Week 13 - Arduinos, Processing and JSON

The web as glue! Spacebrew to connect Processing to Browsers to Arduinos, etc.


The Web As Glue

Besides Webservers, databases, blogs, file uploads and user authentication the Web is really good at connecting anything to anything.

Websockets are a persistent connections between servers and clients that work over HTTP but have TCP like operation. For example, one server might offer Websocket support so clients can immediately broadcast and receive message without reloading or using AJAX. The clients subscribe to channels and/or events. One client sends a message associated with an event which goes to the server, the server then publishes or broadcasts it to people subscribed.

Publishers & Subscribers

Publishers

Publishers have a name/title something to offer, usually in the form of an event and message.

Subscribers

Subscribers bind to a publishers event.

Spacebrew

Spacebrew is an open sourced websocket event based publisher/subscriber platform that lets you easily connect your projects together. For example,

  • Web page image click to Process sketch.
  • Processing sketch gravity game collision event to OpenFrameworks project.
  • Arduino sensor to Web page background color.
  • iPhone app to Python app & Arduino LED output.
  • OR any combination you can imagine.

Spacebrew Publisher & Subscriber

  • Spacebrew Publisher can send string, number, boolean or a custom data packet.
  • Spacebrew Subscribers can configure themselves to receive strings, numbers, booleans or custom data packets.

Built in NodeJS

Spacebrew is built in Node but can be made to work with any language that can make web requests. So Processing, Arduino, OpenFrameworks, iOS, Android, Python, Ruby, PHP and browser based JavaScript and every other network ready language can be made to publish and subscribe with Spacebrew.

The Spacebrew server

  • Spacebrew is centralized, meaning there is a server that controlls the publish and subscribe events.
  • Publishers and Subscribers both connect to the Spacebrew server.

Spacebrew has a sandbox server for anyone to try out http://spacebrew.github.io/spacebrew/admin/admin.html?server=sandbox.spacebrew.cc

You can run your own Spacebrew server, locally on your own machine and network at home or on a server you set up on Linode, Rackspace or AWS. Spacebrew will not run on Heroku as you expect.

Spacebrew Admin

To connect publishers and subscribers there is a Spacebrew Admin page. See the Sandbox Admin here, http://spacebrew.github.io/spacebrew/admin/admin.html?server=sandbox.spacebrew.cc

You can also have a local admin for your own Spacebrew server which is included in the downloaded Spacebrew code.

Navigate to and double click to open

<spacebrew directory>/admin/admin.html

You can click on a publisher with a String, and connect it to any Subscriber ready to accept a String. Data types must match, that's the only rule.

Getting Started with your own local Spacebrew server

1) Download Spacebrew server

2) Navigate into the code directory with Terminal and start the Spacebrew server.

node node_server.js

3) Open Spacebrew local admin. Open a browser tab and File -> Open /admin/admin.html

The page will load but no publishers/subscribers will be listed.

4) Let's get the Spacebrew Javascript/Web page examples. Download Spacebrew Javascript/Web page examples

5) Open the JS example directory and open the spacebrew_button folder. Click and open the index.html file.

Connect to the local Spacebrew server by adding ?server=localhost to the url

?server=localhost

6) Your Spacebrew Admin will then update with the Button publisher and subscriber. Click on the Publisher and then the Subscriber to connect them.

7) Your Spacebrew button web page will now change background when the button is clicked.




Assignment

comments powered by Disqus