I have my fair share of playing with embedded Linux and Internet of Things projects these days, but the real treat is finding projects occasionally that just blow me away. Through some Hacker News comments I ended up checking out Resin.io, a tool that brings cloud deployment and management to embedded applications. That might simple (boring?), but here’s the workflow in a nutshell:
- Start a new application and download an image file for your chosen single board computer (1 of 5 choices at the moment: Raspberry Pi 1 & 2, Parallella, Intel Edison, and BeagleBone Black)
- Flash the image onto an SD card, connect the board to the network, and boot it up
- The board shows up in the cloud management console, and you get a git repo address
- Make an application (Docker, Node.js, etc.), do a git push: voila, your board’s running your app
- Flash a few more SD cards, connect the devices to the network, all of them will run your application
- Modify the app behaviour through environment variables, either all of them at once, or customize each
- Check status, logs, updates, online, and enjoy that things just work!
I cannot emphasise enough how good any service feels that 1) runs by git pushing code, and 2) just works.
SomaStream
To try it all out, I’ve put together a very simple application: SomaStream – the SomaFM internet radio streaming app.
Grabbed my RaspberryPi that didn’t do much lately, plugged an earphone in it, and started to look for some examples in the docs how to make it play some streaming music.
In the end I’ve used a docker image, installed mplayer, and stated a shell script in the app to start playing the stream defined by the appropropriate environment variable. This makes it very reusable: if I use more than one board, using the same code all of them could play different SomaFM channels. Also added the cache size as a variable to deal with crappy internet connections without pushing new code to the board.
After git pushing the code, it compiles the image in about 7 minutes which is not too quick, but most of the time is spent in Raspbian package install (which is not a quick thing in itself). Then the image is downloaded to the board automatically (just like it’s on the way on the image above), and if everything went well, in a minute or so there’s music to my ears through the Pi’s headphones – and can see in the logs what is it playing at the moment like this:
This is a totally toy project, but still the outcome is useful and very enjoyable. The entire code from my side is about half a dozen lines altogether, here’s the somastream repository. Tried out most of the functionality of the system, and it enables me to think of more complex problems for which it might be a good solution.
Now, with a (little) job well done, hello Secret Agent (set CHANNEL to “secretagent130”) :)
The Future
I feel that this tool will breathe new life into my Raspberry Pi, because all the possible projects just got a lot more playful and interesting suddenly. The same goes for my Kickstarter Parallellas, since Resin.io powers their new Supercomputer.io, which I’m really looking forward to see in action (Computing and science? Sign me up!)
Also, in the Taipei Hackerspace we had a chat recently to set up a small rack for single board computers, so people can try a toy “datacenter”, having their “server” there. Our question at the time was, how deep people will want to go in the abstraction of server management – all the way to the bare metal managing a Linux distro, or stay on the level applications? Now with Resin, the second option is totally realistic. I can’t wait to discuss this with people in the ‘Space, and see what projects they’ll come up with!
According to the Hacker News discussion, the magic of this system is in part powered by Yocto-generated images, and any single board computer that has a Yocto layer and reasonably new kernel will be usable. I’m a Yocto novice, but this smells like the perfect use case for their philosophy: decoupling the hardware support and the actual operating system, so any recombination of the two still works. Talk about floodgates, how many boards I have idle here that someone already made a Yocto layer (and if there’s a board that does not have a layer, now’s the time…)
One reply on “Magic for the Internet of Things: Resin.io”
[…] trying Resin.io briefly with a SomaFM Streaming Application, I was eager to experiment more with their cloud deployment platform. Maybe some new hardware, […]