Se ha denunciado esta presentación.
Se está descargando tu SlideShare. ×

Spacebrew: The Overview

Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Cargando en…3
×

Eche un vistazo a continuación

1 de 53 Anuncio

Spacebrew: The Overview

Descargar para leer sin conexión

An overview of Spacebrew, introducing the basic inner-workings, libraries involved, and its capabilities.

Usually accompanied by me, hence some of the "let's try..." language!

An overview of Spacebrew, introducing the basic inner-workings, libraries involved, and its capabilities.

Usually accompanied by me, hence some of the "let's try..." language!

Anuncio
Anuncio

Más Contenido Relacionado

Presentaciones para usted (20)

Similares a Spacebrew: The Overview (20)

Anuncio

Más reciente (20)

Spacebrew: The Overview

  1. 1. Spacebrew Workshop - NYU ITP - Brett Renfer Spacebrew
  2. 2. Spacebrew Workshop - NYU ITP - Brett Renfer Spacebrew Basics
  3. 3. Spacebrew Workshop - NYU ITP - Brett Renfer Obligatory hype video!
  4. 4. 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
  5. 5. Spacebrew at SFPC - Brett Renfer Spacebrew is supported by a group of amazing people.
  6. 6. Arduino Day - NYU ITP - Brett Renfer & Julio Terra Remote 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
  7. 7. Spacebrew Workshop - NYU ITP - Brett Renfer “Landing Page”, Mountain View, CA, 2010
 with LAB at Rockwell Group
  8. 8. Spacebrew Workshop - NYU ITP - Brett Renfer JS Libraries Spacebrew aims to be implementation agnostic.
 We want to use the right tools at the right time!
  9. 9. 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.
  10. 10. Spacebrew Workshop - NYU ITP - Brett Renfer client app client app client app client app Client-Server Model Each 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).
  11. 11. Spacebrew Workshop - NYU ITP - Brett Renfer client app client app client app client app Client-Server Model Clients communicate with the server via WebSockets. All data is formatted as JSON
  12. 12. Spacebrew Workshop - NYU ITP - Brett Renfer Client-Server Model The server routes all publishers and subscribers. Routes can be edited via a switchboard-like interface
  13. 13. Spacebrew Workshop - NYU ITP - Brett Renfer Data Types Three standard types allow for quick and easy routing. Custom types are also supported = true or false = 0-1023 = “some text”
  14. 14. Spacebrew Workshop - NYU ITP - Brett Renfer Publishers + Subscribers Each client announces its publishers and subscribers to the server when it launches client app Publishers: ... Subscribers: ...
  15. 15. Spacebrew Workshop - NYU ITP - Brett Renfer Publishers + Subscribers This 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
  16. 16. Spacebrew Workshop - NYU ITP - Brett Renfer Publishers + Subscribers Names 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”
  17. 17. Spacebrew Workshop - NYU ITP - Brett Renfer Messages Apps 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
  18. 18. Spacebrew Workshop - NYU ITP - Brett Renfer Messages Apps 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 app Name: “TEXT” Value: “Hey!”
  19. 19. 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”
  20. 20. Spacebrew Workshop - NYU ITP - Brett Renfer Messages, Illustrated client app A Name: “MOVING” Value: FALSE Name: “BG ON” Value: FALSE client app B
  21. 21. Spacebrew Workshop - NYU ITP - Brett Renfer Using Spacebrew
  22. 22. Spacebrew Workshop - NYU ITP - Brett Renfer Spacebrew Libraries Each 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
  23. 23. Spacebrew Workshop - NYU ITP - Brett Renfer Spacebrew Libraries Connecting 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
  24. 24. Spacebrew Workshop - NYU ITP - Brett Renfer Spacebrew + Processing • spacebrewP5 is a Spacebrew-supported library
 • install the library from
 spacebrewP5/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!
  25. 25. 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!
  26. 26. 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
  27. 27. 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!
  28. 28. 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
  29. 29. Spacebrew Workshop - NYU ITP - Brett Renfer Spacebrew + Arduino • Two routes:
 • the easy road: use Processing + Serial or Firmata
 • the road less travelled: Spacebrew Arduino lib
 
 http://github.com/labatrockwell/spacebrew-arduino-library
 • requires Arduino Ethernet shield • notoriously difficult to debug!
  30. 30. Spacebrew Workshop - NYU ITP - Brett Renfer Questions?
  31. 31. Spacebrew Workshop - NYU ITP - Brett Renfer Lunch O’Clock
  32. 32. Spacebrew Workshop - NYU ITP - Brett Renfer Custom Types
  33. 33. Spacebrew Collab - Parsons D + T - Brett Renfer & Julio Terra Spacebrew 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”
  34. 34. Spacebrew Workshop - NYU ITP - Brett Renfer
  35. 35. Spacebrew Collab - Parsons D + T - Brett Renfer & Julio Terra Spacebrew 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
  36. 36. Spacebrew Collab - Parsons D + T - Brett Renfer & Julio Terra Spacebrew Workshop - NYU ITP - Brett Renfer Custom Type Demo 1 • Break free of the tyranny of the int: 
 let’s send some floats!
  37. 37. Spacebrew Collab - Parsons D + T - Brett Renfer & Julio Terra Spacebrew 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
  38. 38. Spacebrew Collab - Parsons D + T - Brett Renfer & Julio Terra Spacebrew 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)
  39. 39. Spacebrew Collab - Parsons D + T - Brett Renfer & Julio Terra Spacebrew 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
  40. 40. Spacebrew Collab - Parsons D + T - Brett Renfer & Julio Terra Spacebrew 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
 }
  41. 41. Spacebrew Collab - Parsons D + T - Brett Renfer & Julio Terra Spacebrew Workshop - NYU ITP - Brett Renfer Quick JSON primer { "name":"cool object", "position":{ "x":0, "y":0 }, "candy I like":[ "twizzlers", "ginger snaps" ] }
  42. 42. Spacebrew Workshop - NYU ITP - Brett Renfer You Got Served
  43. 43. 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!
  44. 44. 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
  45. 45. 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
  46. 46. 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
  47. 47. 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”
  48. 48. 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
  49. 49. 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
  50. 50. Spacebrew Workshop - NYU ITP - Brett Renfer Admin
  51. 51. 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
  52. 52. 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
  53. 53. Spacebrew Workshop - NYU ITP - Brett Renfer The End @robotconscience brett@robotconscience.com

×