This is an Elixir client that corresponds to our Traffic Light Server and controls the lights of a modded traffic light, using three GPIO pins of the Raspberry PI.
In order to make the deployment and service management on the device as easy as possible I decided to try out the Nerves Project.
The real world traffic light consists of the lights itself (in the commonly known casing) that are controlled by a custom made shield for the Raspberry PI.
This project replaces an old Ruby version of the client that was running as a service on a Raspian installation.
Note that there are some environment variables required when building a release.
I set them automatically with direnv and a .env
file. See the .env_example
file for what is needed.
mix deps.get
mix firmware
mix firmware.burn
mix firmware
./upload.sh
Note that the client has to be in the same network ;)
ssh nerves.local
tping 'google.com'
Nerves.Network.status("wlan0")
First, you have to enable debugging of the genserver.
TrafficLightClient.Updater.enable_debug
Then you can use the following statements to introspect the process and look at the state.
:sys.get_status(UpdaterLink)
:sys.statistics(UpdaterLink, :get)
:sys.get_state(UpdaterLink)
This traffic light project exists since 2010. I use this side project as a form of recreational programming and joyful overengineering.
The software/hardware project has seen many stages:
- Connected to a Synology NAS with a self-soldered Velleman K8055 USB experimentation board.
- Connected to a Raspberry PI, running a Ruby script locally, node.js on the server side.
- Wiring mostly replaced by a custom etched circuit board - a Raspberry shield built only for the purpose of changing the traffic light (and debugging it at home without disassembling the whole traffic light).
- Replacement of the Raspbian/Ruby client with Elixir and Nerves.
- Replacement of the node.js server with Elixir and Phoenix.
The physical traffic light has been set up at two companies and four offices, motivating me and many others to keep your CI green and clean.
It also had its own dedicated blog, showing the appearances of the traffic light in different articles and videos as it was a welcome guest in German media.
- Nerves getting started
- Tutorial nerves_init_gadget
- Network wlan setup
- Nerves GPIO example
- Circuits GPIO lib
🚥 ❤ 🚥