MQTT Basics
MQTT Basics
Mosquitto MQTT broker provides a fairly robust environment that is suitable for testing and to a great extent for production as well
Follow these instructinos to install mosquitto on macOS
https://formulae.brew.sh/formula/mosquitto
Here is a quick setup to test
Subscribe to a topic and watch for messages
mosquitto_sub -v -t "myiottopic/test" -h test.mosquitto.org | ts
Publish to this topic
mosquitto_sub -t "myiottopic/test" -h test.mosquitto.org -m '{"key":"msg", "value":"hello world"}'
import paho.mqtt.client as mqtt
.
.
client = mqtt.Client()
.
.
client.connect(broker_address, broker_port, 60)
client.publish(topic, message, qos=1)