The Electric Impspacebrewnoduino

by Thomas Brady in , ,


I've been dying, ever since a couple of the core contributors visited frog Austin a little over a year ago, to play with Spacebrew, and in yet another skunkworks bit of hacking at work recently, I finally got to.

We, the secret snooping society, want to fill the Austin studio with sensors of varying type and scope, and we wanted it to be very easy for people, once they've found us out, to play along. This is a perfect fit for Spacebrew, which aims to make interactive spaces, exposing data via a simple API. One rig can be set up to be a data "publisher," and, without permission or help of any kind, anybody that can reach that server via a network/Internet connection can write a "subscriber" that can do whatever it likes with that data (usually, visualizing it).

As I was building this out (our project used a simple proximity sensor to track motion near the elevator, as a proxy to counting elevator trips), I realized that we also wanted historical data. Spacebrew is a super convenient way to provide real-time data, but it doesn't have any affordances for persisting data. So, I built a Node.js server that both acted as the Spacebrew publisher, via the javascript API, and write data to a mongoDB.

I also finally got to play with the Electric Imp, a nifty little WiFi-enabler.

You can read all about it, and get all the source code, on github, but here's a short walkthrough of how it works (from the "What does it do?" section of the project's README):

  1. Use an Arduino to power a proximity sensor as a motion detector, and, when it sees motion, send a command over serial to an
  2. Electric Imp, which throws an event over the Internet to
  3. Electric Imp's cloud service, which we've configured to exposes an API that rolls up and reports these events upon HTTP GET, which
  4. Our Node.js server polls, and upon finding new events, acts by both
  5. Writing a record to a mongoDB and
  6. Forwarding the event to
  7. Spacebrew

Up to this point we have built a Spacebrew publisher, that happens to also persist data (something not typically included in Spacebrew).

We have also included an example Spacebrew subscriber, in the form of a web app that uses the Spacebrew javascript API in order to increment a count of movements observed. Our web app first polls our Node app to get a historical count for the day, and the timestamp of that last movement. The real-time Spacebrew updates then increment this historical count, and reset the last-movement-seen clock.

IMG_2473.jpg
Source: https://github.com/thomasqbrady/TheElectri...