Spacebrew
2/1/14 + 2/2/14

Spacebrew Workshop - NYU ITP - Brett Renfer
Schedule
Today
• Now-10:30: - Quick Introductions
• 10:30-12:00 - Introduction to Spacebrew
• 12-12:30 - Lunch break
• 12:30-2:00 - Spacebrew exercise
• 2:00-3:00 - Advanced Spacebrew
• 3:00-5:00 - Assignment: Brainstorm, jam session
!

Tomorrow
• 12:00-12:45 - Demos
• 12:45-1:45 - Documentation
Spacebrew Workshop - NYU ITP - Brett Renfer
Spacebrew Basics

Spacebrew Workshop - NYU ITP - Brett Renfer
Setup Time
Software Basics
• Processing
• Arduino
• a Text Editor
• openFrameworks

Spacebrew

https://github.com/Spacebrew/

•
•
•
•

Spacebrew Workshop - NYU ITP - Brett Renfer

spacebrew
spacebrewP5
ofxSpacebrew
• ofxLibwebsockets
spacebrew.js
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 prototypingdriven design efforts

Spacebrew Workshop - NYU ITP - Brett Renfer
Client-Server Model
client
app

client
app
client
app

Spacebrew Workshop - NYU ITP - Brett Renfer

client
app

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).
Client-Server Model
client
app

client
app
client
app

Spacebrew Workshop - NYU ITP - Brett Renfer

client
app

Clients communicate with the
server via WebSockets. All data
is formatted as JSON
Client-Server Model
The server routes all publishers
and subscribers. Routes can be
edited via a switchboard-like
interface

Spacebrew Workshop - NYU ITP - Brett Renfer
= true or false
= 0-1023
= “some text”

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”

Spacebrew Workshop - NYU ITP - Brett Renfer

Data Types
Each publishers and subscribers
announces its type, allowing for
automatic routing between
different apps
Libraries

JS
Spacebrew Workshop - NYU ITP - Brett Renfer

Spacebrew aims to be
implementation agnostic.

We want to use the right tools
at the right time!
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
Using Spacebrew

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

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

Spacebrew Workshop - NYU ITP - Brett Renfer
Spacebrew + Processing
•

spacebrewP5 is a Spacebrew-supported library


•

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!

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 + 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


•

the road less travelled: Spacebrew Arduino lib




http://github.com/labatrockwell/spacebrew-arduino-library

•
•

Spacebrew Workshop - NYU ITP - Brett Renfer

requires Arduino Ethernet shield
notoriously difficult to debug!
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
Questions?

Spacebrew Workshop - NYU ITP - Brett Renfer
Lunch O’Clock

Spacebrew Workshop - NYU ITP - Brett Renfer
Zip! Zap! Zow!
Everybody stand up!

Spacebrew Workshop - NYU ITP - Brett Renfer
Exercise
Zip! Zap! Zow! 2.0

Spacebrew Workshop - NYU ITP - Brett Renfer
ZZZ2.0
•

use any library you wish
!

•

create an app that has one publisher and one
subscriber, both of which are range type


•

Your app must change states when it receives a
range. 


•

Your app must have a trigger to send out its value!
(e.g. mouse click, key press, sensor read)

Spacebrew Workshop - NYU ITP - Brett Renfer
Custom Types

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 names (e.g. we might know that “float”
could probably route to “int”, but to Spacebrew
they’re wholly different)

Spacebrew Workshop - NYU ITP - Brett Renfer
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

Spacebrew Workshop - NYU ITP - Brett Renfer
Quick Brainstorm
•

What are some scenarios you might use
custom types for?

Spacebrew Workshop - NYU ITP - Brett Renfer
Custom Type Demo
•

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)

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:
!

•
•

Spacebrew Workshop - NYU ITP - Brett Renfer

npm install ws
npm install forever-monitor
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
•

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
!

•

Spacebrew Workshop - NYU ITP - Brett Renfer

This routes any app that publishes “coolPub” to
any other app that subscribes to “lameSub”
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
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
Jam Session

Spacebrew Workshop - NYU ITP - Brett Renfer
Assignment
•

For tomorrow:

•

option A:
• brainstorm an interaction scenario that would
require (at least) 3 separate input/output
stations
• create a prototype using spacebrew!


•

option B:
• build a prototype that physicalizes spacebrew
routes (and uses the admin API)
• demonstrate it routing/re-routing with the built
in examples

Spacebrew Workshop - NYU ITP - Brett Renfer

ITP Spacebrew Workshop - Spring 2014

  • 1.
    Spacebrew 2/1/14 + 2/2/14 SpacebrewWorkshop - NYU ITP - Brett Renfer
  • 2.
    Schedule Today • Now-10:30: -Quick Introductions • 10:30-12:00 - Introduction to Spacebrew • 12-12:30 - Lunch break • 12:30-2:00 - Spacebrew exercise • 2:00-3:00 - Advanced Spacebrew • 3:00-5:00 - Assignment: Brainstorm, jam session ! Tomorrow • 12:00-12:45 - Demos • 12:45-1:45 - Documentation Spacebrew Workshop - NYU ITP - Brett Renfer
  • 3.
    Spacebrew Basics Spacebrew Workshop- NYU ITP - Brett Renfer
  • 4.
    Setup Time Software Basics •Processing • Arduino • a Text Editor • openFrameworks Spacebrew
 https://github.com/Spacebrew/
 • • • • Spacebrew Workshop - NYU ITP - Brett Renfer spacebrew spacebrewP5 ofxSpacebrew • ofxLibwebsockets spacebrew.js
  • 5.
    Obligatory hype video! SpacebrewWorkshop - NYU ITP - Brett Renfer
  • 6.
    Spacebrew… • is a serviceand toolkit for choreographing interactive spaces ! • makes it easy to connect interactive things to one another ! • was developed to support prototypingdriven design efforts Spacebrew Workshop - NYU ITP - Brett Renfer
  • 7.
    Client-Server Model client app client app client app Spacebrew Workshop- NYU ITP - Brett Renfer client app 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).
  • 8.
    Client-Server Model client app client app client app Spacebrew Workshop- NYU ITP - Brett Renfer client app Clients communicate with the server via WebSockets. All data is formatted as JSON
  • 9.
    Client-Server Model The serverroutes all publishers and subscribers. Routes can be edited via a switchboard-like interface Spacebrew Workshop - NYU ITP - Brett Renfer
  • 10.
    = true orfalse = 0-1023 = “some text” Spacebrew Workshop - NYU ITP - Brett Renfer Data Types Three standard types allow for quick and easy routing. Custom types are also supported
  • 11.
    = true orfalse = 0-1023 = “some text” Spacebrew Workshop - NYU ITP - Brett Renfer Data Types Each publishers and subscribers announces its type, allowing for automatic routing between different apps
  • 12.
    Libraries JS Spacebrew Workshop -NYU ITP - Brett Renfer Spacebrew aims to be implementation agnostic.
 We want to use the right tools at the right time!
  • 13.
    Why? • We’ve used alot 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
  • 14.
    Using Spacebrew Spacebrew Workshop- NYU ITP - Brett Renfer
  • 15.
    Spacebrew Libraries Each Spacebrewlibrary: • 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
  • 16.
    Spacebrew Libraries Connecting toSpacebrew 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
  • 17.
    Spacebrew + Processing • spacebrewP5is a Spacebrew-supported library
 • 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! Spacebrew Workshop - NYU ITP - Brett Renfer
  • 18.
    Spacebrew + Javascript • spacebrew.jsis 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
  • 19.
    Spacebrew + openFrameworks • ofxSpacebrewconnects 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
  • 20.
    Spacebrew + Arduino • Tworoutes:
 • the easy road: use Processing + Serial
 • the road less travelled: Spacebrew Arduino lib
 
 http://github.com/labatrockwell/spacebrew-arduino-library
 • • Spacebrew Workshop - NYU ITP - Brett Renfer requires Arduino Ethernet shield notoriously difficult to debug!
  • 21.
    Thinking About Apps • Wetry 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
  • 22.
    Questions? Spacebrew Workshop -NYU ITP - Brett Renfer
  • 23.
    Lunch O’Clock Spacebrew Workshop- NYU ITP - Brett Renfer
  • 24.
    Zip! Zap! Zow! Everybodystand up! Spacebrew Workshop - NYU ITP - Brett Renfer
  • 25.
    Exercise Zip! Zap! Zow!2.0 Spacebrew Workshop - NYU ITP - Brett Renfer
  • 26.
    ZZZ2.0 • use any libraryyou wish ! • create an app that has one publisher and one subscriber, both of which are range type
 • Your app must change states when it receives a range. 
 • Your app must have a trigger to send out its value! (e.g. mouse click, key press, sensor read) Spacebrew Workshop - NYU ITP - Brett Renfer
  • 27.
    Custom Types Spacebrew Workshop- NYU ITP - Brett Renfer
  • 28.
    Custom Types • Spacebrew supportsarbitrary 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) Spacebrew Workshop - NYU ITP - Brett Renfer
  • 29.
    Spacebrew Workshop -NYU ITP - Brett Renfer
  • 30.
    Example: Ultrabook Tree • Eachinput station sent a custom “bloom” object: • Which image (id) • Number of laptops • Radius • Relative position (x,y) • Velocity • Rotation Spacebrew Workshop - NYU ITP - Brett Renfer
  • 31.
    Quick Brainstorm • What aresome scenarios you might use custom types for? Spacebrew Workshop - NYU ITP - Brett Renfer
  • 32.
    Custom Type Demo • JSONin 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) Spacebrew Workshop - NYU ITP - Brett Renfer
  • 33.
    You Got Served SpacebrewWorkshop - NYU ITP - Brett Renfer
  • 34.
    Running Your OwnServer • 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
  • 35.
    Running Your OwnServer • How? ! • Setup! Only needs to be done once
 • Download and install nodejs: www.nodejs.org ! • Install node dependencies: ! • • Spacebrew Workshop - NYU ITP - Brett Renfer npm install ws npm install forever-monitor
  • 36.
    Running Your OwnServer • 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
  • 37.
    Running Your OwnServer • 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
  • 38.
    Persistence • Another advantage ofrunning 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 ! • Spacebrew Workshop - NYU ITP - Brett Renfer This routes any app that publishes “coolPub” to any other app that subscribes to “lameSub”
  • 39.
    Persistence • You can runthe 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
  • 40.
    Admin Spacebrew Workshop -NYU ITP - Brett Renfer
  • 41.
    The Admin API • Youdon’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
  • 42.
    The Admin API • Tryit out: http://bit.ly/sbslider-admin
 • Let’s look at the Admin API in Javascript Spacebrew Workshop - NYU ITP - Brett Renfer
  • 43.
    Jam Session Spacebrew Workshop- NYU ITP - Brett Renfer
  • 44.
    Assignment • For tomorrow:
 • option A: •brainstorm an interaction scenario that would require (at least) 3 separate input/output stations • create a prototype using spacebrew!
 • option B: • build a prototype that physicalizes spacebrew routes (and uses the admin API) • demonstrate it routing/re-routing with the built in examples Spacebrew Workshop - NYU ITP - Brett Renfer