prueker / METARMap

Raspberry Pi project to visualize flight conditions on a map using WS8211 LEDs addressed via NeoPixel
MIT License
118 stars 72 forks source link

MQTT Client Support #22

Closed peaster closed 3 years ago

peaster commented 3 years ago

The time-based approach of controlling the map is great, but I wanted to add a little more flexibility in how I turn on and off my map. I'm a Home Assistant user and wanted to integrate the map into my existing home automation, as well as expose it to my voice assistants. MQTT enables the map to report its state and be controlled by a MQTT broker.

The sole dependency is paho-mqtt which I installed with pip.

Configuration is managed through a private mqtt_config.py file that looks like

broker_url = <broker_url>
broker_port = <broker_port>
set_topic = "home/metarmap/set"
state_topic = "home/metarmap/state"
broker_username = "admin"
broker_password = "notrealpass"

To run the client permanently, I set up a service sudo vim /etc/systemd/system/mqtt-client.service

[Unit]
Description=mqtt client service

[Service]
ExecStart=python3 mqtt-client.py
WorkingDirectory=/home/pi/
Restart=always
RestartSec=10
User=pi

[Install]
WantedBy=multi-user.target 

And then enabled it

sudo systemctl enable mqtt-client.service
sudo systemctl start mqtt-client.service
prueker commented 3 years ago

That's neat for your usecase. By the way one small change I'd make is to use the ./refresh.sh script to kick things off (as it ensures only one version of metar.py is running at any given time).

As for the Pull Request itself, I'd like to keep the repo simple with just the core functionality that caters to the large majority of people that just want to build a simple METARMap and run it with crontab.