Making an IoT gadget with raspberry pi and spacebrew

3rd December, from the backup vaults of David Whale’s email inbox…missing some photos, I’ll get those up soon!

As a very simple project I decided to try and hook up my RGB strip to my pi, to the internet, and then let people mess about with what colour the LEDs are and what LED to turn on and off.

This turns out to be pretty easy using a couple of libraries I found, so I thought I’d share my progress:

Yesterday I went off to maplin, got a wireless adapter for a tenner (I’m still a bit miffed I caved on that one – ebay has them for a fiver but I didn’t want to wait…), and downloaded the first library:

Raspberrypi-experiments by lab @ rockwell

I then had to install a dependency called websockets-client (use pip install websockets-client).

I first ran the example code, which is under Led_Strip_Library/examples, called “simple_example”. This basically makes all the LEDs turn off and turn on again rapidly. After getting excited about doing that, I fiddled around with the colours a bit and then moved on to Spacebrew.

I only know about spacebrew because the other example in there, spacebrew_bar_graph, uses it, and I think because it’s in beta that’s why I hadn’t heard of it before. This is made by the same LAB who did the above code, and it’s again, stupidly simple to use. I modified the code in spacebrew_bar_graph a little to fix a bug, and then ran it, and hey look, my LED strip’s on the internet:

spacebrew

 

The admin page shown there is the sandbox server Spacebrew provides, which has open access to anyone in the world, so you could modify your own LED strip to be connected to someone’s button anywhere in the world, for example.

Annoyingly for my purposes however, each “app” is added to spacebrew server uniquely by it’s IP, not by the name, so when attempting to set up the javascript I have linked to this as my_app and testing it with two devices, they appear on the server independently. This is why I’m thinking of getting my own server set up, probably on another raspberry pi…

The javascript portion I mentioned again is ridiculously simple. I went to this repo of spacebrew, went into spacebrew.js, downloaded it as a zip, and uploaded the bits I needed to here. As I say, unfortunately, if you play with it, it won’t do anything to my LEDs…

Anyway, once you’ve got the javascript open, all you have to do next is connect the dots, so click the appropriate subscriber’s text and then the publisher’s text to link it to (publisher being the slider, subscriber being for example, the colour green on the ranger)

The only thing I don’t like about this is that erm. I’ve not actually written much code…but I have to modify the examples a little in order to change it so that a user can select one of the 36 LEDs and light it up, or a range of LEDs, rather than just a brightness slider (although right now I just tell it to light them all…).

However I will definitely be using this in the future, and now that I have my python spacebrew app on my pi running on boot, that means I don’t even have to SSH to connect a web app to it, so long as both devices have wifi.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s