It seems we ‘re getting into a series. It started with using a Raspberry Pi as a Docker host and then became more interactive with a blinking light connected to the RPi’s GPIO pins. Here is the whole series so far:

  1. Docker for Your Pocket
  2. Docker for Your Pocket - Streamlined
  3. Hypriot, wiringPI and a Blinking Light
  4. The Blinking Light - Javascript Edition

Now I had some new objectives:

  1. Be able to start and stop the blinking light with a physical button.
  2. Have a web frontend that shows whether blinking mode is enabled or disabled.
  3. Be able to start and stop the blinking light with a button in the web frontend.

The “onoff” library that I was already using made it quite easy to add the physical button; an example is already on their project page.

The cool thing about using the “onoff” library is that you do not need a while loop to poll the pin state. Incoming GPIO changes trigger a callback— that’s all.

This is my wiring diagram:

You can download the Fritzing file from here.

I divided development into two stages and tagged my code accordingly.

Release “2016-03-18” scope:

  • Physical button can activate and deactivate the blinking.
  • Blinker should run continuously and ignore exceptions and timeouts from the GPIO service.
  • Better prototyping with Docker volumes mapped to the host.
  • Refactored how Docker uses package.json.

Release “2016-04-12” scope:

  • Extended frontend with a button.
  • Frontend connects to backend via WebSockets.
  • Activate and deactivate the blinking with the frontend button.
  • Backend sends its status to the frontend via socket.io.

There ‘s a nice Stack Overflow question with a minimal socket.io example. If you ‘re not familiar with socket.io, check it out— it helped me get up to speed.

So far the project accumulates more technologies. For now we have:

  • Raspberry Pi
  • Docker
  • Node.js, Express
  • socket.io

There are some open items I may cover later:

  • Backend address is hardcoded; other code optimizations.
  • Do I really need a separate port for socket.io?
  • Store data in MongoDB.

Done for today!