Skip to content

A web controlled traffic light for Raspberry PI, powered by Elixir and Nerves

Notifications You must be signed in to change notification settings

fabrik42/traffic-light-client-elixir

Repository files navigation

Traffic Light Client for the Raspberry PI

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.

Deployment

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.

Initial Deployment (or Offline Deployment)

mix deps.get
mix firmware
mix firmware.burn

Follow up deployments

mix firmware
./upload.sh

Debugging and introspection

SSH into running client

Note that the client has to be in the same network ;)

ssh nerves.local

Check outside connections from iex

tping 'google.com'

Get network information

Nerves.Network.status("wlan0")

Looking into the GenServer that updates the traffic light

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)

A little bit of Traffic Light history

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.

More Information

🚥 ❤ 🚥

About

A web controlled traffic light for Raspberry PI, powered by Elixir and Nerves

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published