It's now time to run the Tree MQTT service program and publish MQTT messages that will control our IoTree. Here are the steps to run and test our Tree MQTT service:
- We must have the Mosquitto MQTT broker service installed and running on our Raspberry Pi, plus the Mosquitto MQTT clients tools. Please refer to Chapter 4, Networking with MQTT, Python, and the Mosquitto MQTT Broker, if you need to check your installation.
- Change into the chapter14/tree_mqtt_service folder and start the main.py script, as shown:
# Terminal 1
(venv) $ cd tree_mqtt_service
(venv) $ python main.py
INFO:root:Connecting to MQTT Broker localhost:1883
INFO:MQTTListener:Connected to MQTT Broker
- Next, open a second terminal and send an MQTT message using the following command:
# Terminal 2
$ mosquitto_pub -h "localhost" -t "tree/lights/pattern" -m "red blue black"
The LED strip will light up with the repeating color pattern...