The Blinking Light - Javascript Edition
This is an update to my post [“Hypriot, wiringPI and a Blinking Light”]({% post_url 2015-12-06-hypriot-wiringpi-and-a-blinking-light %}).
There are two major changes to the whole thing.
-
The GPIO service is now a webservice implmented with NodeJS and Express. For interfacing with the GPIO pins of the Raspberry Pi am using a library called “onoff”.
-
The shell script that is responsible for all the blinking has been replaced with a piece of Javascript using “unirest” for calling the GPIO service via HTTP.
Both, the GPIO service and the Javascript that sends the HTTP requests to it are running each in their own docker container and are setup with docker-compose as ususal.
Setting it all up was not that difficult, but not being that firm with Javascript, the biggest issue I had was letting the LED blink in a steady interval. Not being used to Javascripts asynchronous nature it took me a while and a very helpful answer on StackOverflow to make it work: “How to create a sleep/delay in nodejs that is Blocking?”.
Get it all from Github with
git clone https://github.com/twissmueller/docker-pi.git
cd docker-pi
git checkout tags/2016-01-13
Start the whole thing with
docker-compose --x-networking up -d
Done for today!