Upload
brett-renfer
View
56
Download
3
Tags:
Embed Size (px)
Citation preview
Spacebrew Workshop - NYU ITP - Brett Renfer
Spacebrew
Spacebrew Workshop - NYU ITP - Brett Renfer
Spacebrew Basics
Spacebrew Workshop - NYU ITP - Brett Renfer
Obligatory hype video!
Spacebrew Workshop - NYU ITP - Brett Renfer
Spacebrew…• is a service and toolkit for choreographing interactive spaces
• makes it easy to connect interactive things to one another
• was developed to support prototyping-driven design efforts
Spacebrew at SFPC - Brett Renfer
Spacebrew is supported by a group of amazing people.
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
Spacebrew Workshop - NYU ITP - Brett Renfer
“Landing Page”, Mountain View, CA, 2010with LAB at Rockwell Group
Spacebrew Workshop - NYU ITP - Brett Renfer
JS
LibrariesSpacebrew aims to be implementation agnostic.We want to use the right tools at the right time!
Spacebrew Workshop - NYU ITP - Brett Renfer
Why?• We’ve used a lot of “glue” languages/toolkits in the past, but there wasn’t one that was truly cross-platform/cross-toolkit.
• Wanted to build a toolkit with a low floor and a high ceiling: easy for speed prototypes, advanced enough to handle commercial applications.
Spacebrew Workshop - NYU ITP - 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 (more on that later).
Spacebrew Workshop - NYU ITP - 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
Spacebrew Workshop - NYU ITP - Brett Renfer
Client-Server ModelThe server routes all publishers and subscribers. Routes can be edited via a switchboard-like interface
Spacebrew Workshop - NYU ITP - Brett Renfer
Data TypesThree standard types allow for quick and easy routing. Custom types are also supported
= true or false
= 0-1023
= “some text”
Spacebrew Workshop - NYU ITP - Brett Renfer
Publishers + SubscribersEach client announces its publishers and subscribers to the server when it launches
client app
Publishers: ...Subscribers: ...
Spacebrew Workshop - NYU ITP - Brett Renfer
Publishers + SubscribersThis announcement includes the name and type of each, allowing for semantic relationships and automatic routing between different apps (respectively!)
client app
Publishers
Subscribers
CUSTOM
BOOLEAN
RANGE
RANGE
STRING
Spacebrew Workshop - NYU ITP - Brett Renfer
Publishers + SubscribersNames of publishers and subscribers can be anything.We try to make them make some sort of sense…
client app
Publishers
Subscribers
“TEXT”
“MOVING”
“COLOR”
“TONE”
“POINT”
Spacebrew Workshop - NYU ITP - Brett Renfer
MessagesApps send Messages out on a publisher route. Each Message contains the name and value.
Messages of a custom type also include their type.
client app Name: “MOVING” Value: FALSE
Spacebrew Workshop - NYU ITP - Brett Renfer
MessagesApps receive Messages from the Spacebrew server on a subscribers route. Each Message contains the name and value matching a route in the app.
Messages of a custom type also include their type.
client appName: “TEXT” Value: “Hey!”
Spacebrew Workshop - NYU ITP - Brett Renfer
Messages, Illustrated
client app A
client app B
App with boolean publisher “MOVING”
Route between A:”MOVING” and B:”BG ON”
App with boolean subscriber “BG ON”
Spacebrew Workshop - NYU ITP - Brett Renfer
Messages, Illustrated
client app A
Name: “MOVING” Value: FALSE
Name: “BG ON” Value: FALSE
client app B
Spacebrew Workshop - NYU ITP - Brett Renfer
Using Spacebrew
Spacebrew Workshop - NYU ITP - Brett Renfer
Spacebrew LibrariesEach Spacebrew library: • Connects to a Spacebrew server via WebSockets • Has an API to declare its publisher(s) and subscriber(s)
• Receives messages from Spacebrew and dispatches events accordingly
Spacebrew Workshop - NYU ITP - Brett Renfer
Spacebrew LibrariesConnecting to Spacebrew in each Library • Create a Spacebrew Object • Tell your object the IP or hostname of the Spacebrew server
• Declare any publishers and subscribers • Connect
Spacebrew Workshop - NYU ITP - Brett Renfer
Spacebrew + Processing• spacebrewP5 is a Spacebrew-supported library
• install the library fromspacebrewP5/dist/spacebrew to ~/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!
Spacebrew Workshop - NYU ITP - 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!
Spacebrew Workshop - NYU ITP - 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
Spacebrew Workshop - NYU ITP - Brett Renfer
Spacebrew + Javascript• spacebrew.js uses query strings to dynamically pass in the name, server, and description:http://YOUR_APP.com/index.html?name=NAME&server=SERVER
• The first query string always starts with “?” and the rest with “&”. They follow the format &NAME=VALUE
• Any app that uses spacebrew.js can do this!
Spacebrew Workshop - NYU ITP - 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
Spacebrew Workshop - NYU ITP - Brett Renfer
Spacebrew + Arduino• Two routes:
• the easy road: use Processing + Serial or Firmata
• the road less travelled: Spacebrew Arduino libhttp://github.com/labatrockwell/spacebrew-arduino-library
• requires Arduino Ethernet shield • notoriously difficult to debug!
Spacebrew Workshop - NYU ITP - Brett Renfer
Questions?
Spacebrew Workshop - NYU ITP - Brett Renfer
Lunch O’Clock
Spacebrew Workshop - NYU ITP - Brett Renfer
Custom Types
Spacebrew Collab - Parsons D + T - Brett Renfer & Julio TerraSpacebrew Workshop - NYU ITP - 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 types
• Example: “float” cannot route to “number”
Spacebrew Workshop - NYU ITP - Brett Renfer
Spacebrew Collab - Parsons D + T - Brett Renfer & Julio TerraSpacebrew Workshop - NYU ITP - 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
Spacebrew Collab - Parsons D + T - Brett Renfer & Julio TerraSpacebrew Workshop - NYU ITP - Brett Renfer
Custom Type Demo 1• Break free of the tyranny of the int: let’s send some floats!
Spacebrew Collab - Parsons D + T - Brett Renfer & Julio TerraSpacebrew Workshop - NYU ITP - Brett Renfer
Custom Types: Basics• Set up Spacebrew pub + sub as usual,but use any name (e.g. float)
• Add the onCustomMessage function to listen
• When you send, do two things: 1. Make sure you use your custom type! 2. Cast your custom data to a string
Spacebrew Collab - Parsons D + T - Brett Renfer & Julio TerraSpacebrew Workshop - NYU ITP - Brett Renfer
Custom Type Demo 2• JSON in Processing
• 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)
Spacebrew Collab - Parsons D + T - Brett Renfer & Julio TerraSpacebrew Workshop - NYU ITP - Brett Renfer
Quick JSON primer• JSON is a simple way to write out objects • JSON is made up of name-value pairs • Names are strings (in quotes!) • Values can be numbers, strings, booleans, arrays, null (empty), or objects
Spacebrew Collab - Parsons D + T - Brett Renfer & Julio TerraSpacebrew Workshop - NYU ITP - Brett Renfer
Quick JSON primer• { = start an object • } = end an object • : = between all names and their value • , = between all name-value pairs{ “x”:0, “y”:0 }
Spacebrew Collab - Parsons D + T - Brett Renfer & Julio TerraSpacebrew Workshop - NYU ITP - Brett Renfer
Quick JSON primer{ "name":"cool object", "position":{ "x":0, "y":0 }, "candy I like":[ "twizzlers", "ginger snaps" ] }
Spacebrew Workshop - NYU ITP - Brett Renfer
You Got Served
Spacebrew Workshop - NYU ITP - 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!
Spacebrew Workshop - NYU ITP - 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
Spacebrew Workshop - NYU ITP - 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
Spacebrew Workshop - NYU ITP - Brett Renfer
Running Your Own Server Online• How?
• If you want to set up your own remote server, we recommend this tutorial (by fellow ITPers!):https://vimeo.com/60001410
Spacebrew Workshop - NYU ITP - 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”
Spacebrew Workshop - NYU ITP - Brett Renfer
Persistence• You can run the persistent admin from the spacebrew directory: node node_persistent_admin.js
• 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
Spacebrew Workshop - NYU ITP - Brett Renfer
Binary• A bleeding-edge feature of Spacebrew is sending binary data
• The sandbox server does not allow you to send binary data, but your own server does!
• Let’s check out the javascript and openFrameworks image examples
Spacebrew Workshop - NYU ITP - Brett Renfer
Admin
Spacebrew Workshop - NYU ITP - 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
Spacebrew Workshop - NYU ITP - Brett Renfer
The Admin API• Try it out: http://bit.ly/sbslider-admin
• Let’s look at the Admin API in Javascript
Spacebrew Workshop - NYU ITP - Brett Renfer
The End@robotconscience