Reader small image

You're reading from  Practical Python Programming for IoT

Product typeBook
Published inNov 2020
Reading LevelIntermediate
PublisherPackt
ISBN-139781838982461
Edition1st Edition
Languages
Right arrow

Running the Tree MQTT service program

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:

  1. 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.
  2. 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
  1. 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...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Practical Python Programming for IoT
Published in: Nov 2020Publisher: PacktISBN-13: 9781838982461