spacebrew @ sfpc
DESCRIPTION
Introduction to Spacebrew Workshop from 10/28/14 lecture at the School for Poetic Computation.TRANSCRIPT
![Page 1: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/1.jpg)
Spacebrew at SFPC - Brett Renfer
Spacebrew @ SFPC10/28/2014
![Page 2: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/2.jpg)
Spacebrew at SFPC - Brett Renfer
Spacebrew Basics
![Page 3: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/3.jpg)
Spacebrew at SFPC - Brett RenferObligatory hype video!
![Page 4: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/4.jpg)
Spacebrew at SFPC - Brett Renfer
Spacebrew…• is a service and toolkit for choreographing interactive spaces
• makes it easy to connect interactive things to one another over networks
• was developed to support prototyping-driven design efforts
![Page 5: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/5.jpg)
Spacebrew at SFPC - Brett Renfer
Spacebrew is supported by a group of amazing people.
![Page 6: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/6.jpg)
Arduino Day - NYU ITP - Brett Renfer & Julio TerraRemote Presence Experiments Havas Madsci Lab
Whispering Stairs, Shu Yang Lin
Next Round Gustavo Faria, Bernardo Schorr and Stephanie Burgess
Forget Me Not Remote Flower Watering, Lucy Matchett, Joselyn McDonald, Nicole Messier
![Page 7: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/7.jpg)
Spacebrew at SFPC - Brett Renfer
client app
client app
client app
client app
Client-Server ModelEach client can feature one or more publishers and subscribers. The server can be hosted online or run on a local network.
![Page 8: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/8.jpg)
Spacebrew at SFPC - Brett Renfer
client app
client app
client app
client app
Client-Server ModelClients communicate with the server via WebSockets. All data is formatted as JSON
![Page 9: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/9.jpg)
Spacebrew at SFPC - Brett Renfer
Client-Server ModelThe server routes all publishers and subscribers. Routes can be edited in real time via a switchboard-like interface
![Page 10: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/10.jpg)
Spacebrew at SFPC - Brett Renfer
Data TypesThree standard types allow for quick and easy routing. Custom types are also supported
= true or false
= 0-1023
= “some text”
![Page 11: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/11.jpg)
Spacebrew at SFPC - Brett Renfer
Data TypesEach publisher and subscriber announces its type, allowing for automatic routing between different apps
= true or false
= 0-1023
= “some text”
![Page 12: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/12.jpg)
Spacebrew at SFPC - Brett Renfer
LibrariesSpacebrew aims to be implementation agnostic.We want to use the right tools at the right time!
JS
![Page 13: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/13.jpg)
Spacebrew at SFPC - Brett Renfer
Why?• Create a glue between our favorite toolkits and languages
• Focus on real-time communication
• Wanted to build a toolkit with a low floor and a high ceiling
![Page 14: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/14.jpg)
Spacebrew at SFPC - Brett Renfer
Using Spacebrew
![Page 15: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/15.jpg)
Spacebrew at SFPC - Brett Renfer
Thinking About Apps• We try to silo apps whenever possible • Create specialized apps that are easy to re-use • Allows for multiple languages for each need • Quickly and easily move between machines/networks when necessary
• Allows for easy prototypes in the future!
![Page 16: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/16.jpg)
Spacebrew at SFPC - Brett Renfer
Thinking About Prototypes• What’s the quickest path to a prototype?
• Can you use one of the existing examples?Or multiple examples? • Phone can become a “jump sensor”,string example can stand-in for Twitter or text messaging
![Page 17: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/17.jpg)
Spacebrew at SFPC - Brett Renfer
Spacebrew LibrariesEach Spacebrew library: • Connects to a Spacebrew server (via WebSockets)
• Has an API to declare its publisher(s) and subscriber(s)
• Can send + receive messages to/from Spacebrew
![Page 18: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/18.jpg)
Spacebrew at SFPC - Brett Renfer
Spacebrew LibrariesConnecting to Spacebrew
1. Create a Spacebrew Object
2. Tell your object where Spacebrew server is
3. Declare any publishers and subscribers
4. Connect!
![Page 19: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/19.jpg)
Spacebrew at SFPC - Brett Renfer
Spacebrew + Processing• install the library at ~/Documents/Processing/libraries (make the folder if it doesn’t exist!)
• restart Processing if it was open
• open the spacebrew_base example to get started!
![Page 20: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/20.jpg)
Spacebrew at SFPC - Brett Renfer
Spacebrew + Arduino• Two routes:
• the easy road: use Processing + Serial
• the road less travelled: Spacebrew Arduino libhttp://github.com/labatrockwell/spacebrew-arduino-library
• requires Arduino Ethernet shield • notoriously difficult to debug!
![Page 21: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/21.jpg)
Spacebrew at SFPC - Brett Renfer
Spacebrew + Javascript• spacebrew.js is a stand-alone script that can run in any browser that supports WebSockets
• this includes: Chrome (OS X, Windows, Android, iOS), Safari (OS X, iOS), Firefox, Opera, IE 10
• open the spacebrew slider example in your text editor
• open http://bit.ly/sbslide on your smartphone
• also try http://bit.ly/sbaccel
![Page 22: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/22.jpg)
Spacebrew at SFPC - Brett Renfer
Spacebrew + openFrameworks• ofxSpacebrew connects to Spacebrew via ofxLibwebsockets
• once you have both installed, you can create ofxSpacebrew projects via the OF project generator
• let’s look at example_button
![Page 23: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/23.jpg)
Spacebrew at SFPC - Brett Renfer
Custom Types
![Page 24: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/24.jpg)
Spacebrew at SFPC - Brett Renfer
Custom Types• Spacebrew supports arbitrary type names and data (anything that reads as valid JSON will work)
• Similar to built-in types, you can only route to matching names (e.g. we might know that “float” could probably route to “int”, but to Spacebrew they’re wholly different)
![Page 25: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/25.jpg)
Spacebrew at SFPC - Brett Renfer
![Page 26: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/26.jpg)
Spacebrew at SFPC - Brett Renfer
Example: Ultrabook Tree• Each input station sent a custom “bloom” object:
• Which image (id) • Number of laptops • Radius • Relative position (x,y) • Velocity • Rotation
![Page 27: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/27.jpg)
Spacebrew at SFPC - Brett Renfer
Custom Type Demo• https://github.com/robotconscience/spacebrew-JSON-examples
• JSON in spacebrew.js, ofxSpacebrew, and spacebrewP5
• Why JSON? • It’s a simple way to send arbitrary objects • Spacebrew uses it, so all libs have some sort of JSON library included (if there isn’t one built in)
![Page 28: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/28.jpg)
Spacebrew at SFPC - Brett Renfer
You Got Served
![Page 29: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/29.jpg)
Spacebrew at SFPC - Brett Renfer
Running Your Own Server• Why?
• sandbox.spacebrew.cc is on the slowest AWS tier
• Running over the internet introduces some level of latency
• Running a local server OR a remote server allows a level of control: only people you choose can route/reroute, break your routes, etc
• Allows you to customize the server code if you choose!
![Page 30: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/30.jpg)
Spacebrew at SFPC - Brett Renfer
Running Your Own Server• How?
• Setup! Only needs to be done once
• Download and install nodejs: www.nodejs.org
• Install node dependencies:
• npm install ws • npm install forever-monitor
![Page 31: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/31.jpg)
Spacebrew at SFPC - Brett Renfer
Running Your Own Server• How?
• Run! What you’ll do every time:
• In terminal, cd to the spacebrew directory
• Run: node node_server_forever.js
![Page 32: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/32.jpg)
Spacebrew at SFPC - Brett Renfer
Keep in touch!@robotconscience [email protected]
@spacebrewcc spacebrew.cc
![Page 33: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/33.jpg)
Spacebrew at SFPC - Brett Renfer
Bonus stuff
![Page 34: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/34.jpg)
Spacebrew at SFPC - Brett Renfer
More on WebSockets• What? • Full-duplex (simultaneous input + output) TCP protocol • Fast, simple to use, (relatively) simple to implement • Allows both simple messages (strings, JSON, etc) and binary data steams
• http://tools.ietf.org/html/rfc6455
• Why? • Works in many languages across many platforms • Works over the internet and on local networks • Super easy to debug!
![Page 35: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/35.jpg)
Spacebrew at SFPC - Brett Renfer
Persistent Admin
![Page 36: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/36.jpg)
Spacebrew at SFPC - Brett Renfer
Persistence• Another advantage of running your own server is you can use the persistent admin
• The persistent admin is a separate service that lets you edit, save, load, and persist routes
• It allows you to specify specific app routings:coolApp -> coolPub to lameApp -> lameSub
• It also allows for powerful wild card routings: .* -> coolPub to .* -> lameSub
• This routes any app that publishes “coolPub” to any other app that subscribes to “lameSub”
![Page 37: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/37.jpg)
Spacebrew at SFPC - Brett Renfer
Persistence• You can run the persistent admin from the spacebrew directory:node node_persistent_admin.js
• Run it in parallel with your server!
• From the command line, you can list, add, remove, load, and save routes:
• list: ls
• add: add client1Name,pub,client2Name,sub • use .* to create a wildcard
• remove: remove [index] • you can find an index after add or by listing
• save / load (just that!) • load is called on start automatically
![Page 38: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/38.jpg)
Spacebrew at SFPC - Brett Renfer
Admin API
![Page 39: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/39.jpg)
Spacebrew at SFPC - Brett Renfer
The Admin API• You don’t just have to use our web interface!
• Javascript, openFrameworks and Cinder (Processing soon) support the Admin API
• The Admin API subscribes to Spacebrew similar to a client, firing events each time a client connects/disconnects or changes its pub/sub map
• It allows you to view, edit, and add any and all routes in real time!
• This allows for apps like the Admin Randomizer from the Zip! Zap! Zow! exercise
![Page 40: Spacebrew @ SFPC](https://reader033.vdocument.in/reader033/viewer/2022052622/559417c21a28ab86468b47fe/html5/thumbnails/40.jpg)
Spacebrew at SFPC - Brett Renfer
The Admin API• Try it out: http://bit.ly/sbslider-admin
• Let’s look at the Admin API in Javascript