Tuesday, December 23, 2014

CheerLights node-red edition

A couple days ago I found my DigiPixel so I started thinking what quick project I could use it for and remembered CheerLights. I gave away my Ethernet shield to a friend and never got around to buy another one so I decided to have it connected to my laptop and get data using Serial through USB. I quickly wrote a sketch to do just this but since I didn't want the DigiPixel to stay on all the time I started to modify it to turn off after a while and then back on for a few seconds. While messing with the code node-red came to mind and I realized 2 things: first, I don't need to modify the code on the Arduino (and having to do it again and again if I decided to change the behavior, like different ON/OFF timeouts), I can leave the sketch simple as it was and implement the behavior I wanted in the node-red flow; second, I can run the flow on my RasPi which uses wifi to connect to my home network and for which I also have a battery so my project becomes "wireless".

A quick search revealed this @Cheerlights to various RGB devices example flow (thanks dceejay!) which is exactly what I needed it. Started my RasPi, deployed the flow, replaced the blink device with a serial node connected to my Arduino and I was done! After I "deployed" the project in my living room and my son started to ask me why there is no light I realized that if the CheerLights color doesn't change for a long time, the DigiPixel doesn't show anything so I tweaked the flow a little bit to wake up every 2 minutes and show the last known color and if there is no last known color just use some color to start things off; the result is here, not as good and generic as the original flow but exactly what I needed.
My setup is a bit more complex than it needs to be because I am using a Raspberry Pi A which has only one USB: since I need USB for both the wifi dongle and to communicate with the Arduino, I used a hub (it doesn't need power, the Pi power supply is good enough to power both the dongle and the Arduino).

node-red is indeed amazing: the amount of changes that can be made in short time and the ability to swap out nodes for different ones very easily (I could decide to replace my Arduino+DigiPixel with some other device and probably be up and running in a matter of minutes or an hour at the most), make it an awesome tool that will very likely be used more and more in the IoT world. I'm repeating myself but I simply love it and can't be thanking enough to its authors!

Monday, December 15, 2014

resin.io

I recently discovered resin.io and I have to admit it sounded great being able to deploy apps to a running Raspberry Pi so I decided to give it a try. And apart from a few small things I'd like to see changed, it is indeed awesome.

Following the Getting Started guide I loaded the OS on an 8 GB Sandisk micro SD, inserted it in my Raspberry Pi B+, booted it up, waited and... nothing happened (well, the power LED on the RasPi came on but that's about it). I reformatted the card and tried again and this time RasPi's green LED started to blink soon after boot and like it says on the website, in about 6-10 minutes, my RasPi showed in the list of devices. I assume the first try didn't work because of something I did, so this is not in any way a bad mark for resin.io - in fact, the process is really smooth and explained in such detail on the website that setting it up is quite easy - the only reason I mentioned it is if someone else runs into the same issue, don't give up, retry and it will work for sure.

Now the device showed up on the dashboard, I went ahead with the next steps: cloned the text2speech app, added the resin git endpoint, commit the code and waited for the project to build. This step worked great but it took a very long time to install and compile all the packages and their dependencies; it would have taken a lot longer to build all the node.js modules directly on the Pi so this is a definite advantage. The problem though is that every time when I update the code and commit and push again, the install process starts all over again and it takes as long as the first time; for a simpler app, with a lot less dependencies this is not an issue but for the example app I tried this was definitely a nuisance. Normally, if I deployed such an app on a Pi the initial time to setup the node modules and their dependencies would have been much longer; but subsequent updates would find the modules in place and would only take seconds.

Another issue I found and it is probably only an issue for me is the terminal on the web interface didn't start; every time I try I get a message saying terminal works only for recently provisioned devices but my devices was added recently so it should have worked. This combined with the fact that I was not able to ssh into my Pi (maybe because the SSH service is not installed/started [update] because that would be a security risk) made me shutdown the Pi by unplugging it which is not very safe from the SD card point of view, it can become easily corrupted. It is true that if this is the case I can always start over by installing the OS file again; also, I can probably create my own Docker container with SSH installed and started by default so this may not be a real problem but since I am not familiar with Docker, it is a problem for me.

Last small issue is not having the ability to deploy more than one app on a running Pi - maybe this is possible but I haven't seen anywhere the docs talking about multiple apps on the same device; same app on multiple devices is possible but the other way around I am not sure how to do. This reason along with the previous ones I mentioned made me decide to wait until resin.io becomes a bit more mature before trying it again.

I hope these small problems I ran into won't stop you from trying resin.io - the idea is great and it works so it is indeed an awesome app worth checking out. Thank you to resin.io author(s) for such a great idea and app!

[Update] Recently I started to look into Docker which seems to be really awesome; a quick search for Docker on Raspberry Pi turned out this article on resin.io blog. I wanted to bring this up because this was a big task for the resin.io team and a huge success and whoever is going to use Docker on Raspberry Pi will owe the team a big thank you. Thank you, guys!