Scott8586 / TrafficLight

Raspberry Pi Traffic Light control via MQTT

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status Code Climate

MQTT Traffic Light

Python code for controlling a Rasperry Pi Traffic Light LED stack from low voltage labs, using paho MQTT. The main script connects to a MQTT broker, listens for commands on a designated topic, and operates the LEDs of the Traffic Light accordingly.

Requirements

paho.mqtt
RPi.GPIO

These can be installed like so:

sudo pip install paho-mqtt
sudo pip install RPi.GPIO

Example

Use the example configuration file to test the operation. The IP address is associated witha free MQTT broker, so don't publish anything sensitive. The code needs to be run as root in order for the GPIO code to access /dev/mem under normal circumstances.

sudo python traffic_light.py -c mqtt.ini.example

Then communicate with a mosquitto_client:

mosquitto_pub -h 85.119.83.194 -t pi/demo/led -m green
mosquitto_pub -h 85.119.83.194 -t pi/demo/led -m off

You should see your green traffic light LED turn on, then off with the different messages.

About

Raspberry Pi Traffic Light control via MQTT


Languages

Language:Python 100.0%