Skip to content
Snippets Groups Projects
Commit cb97c6c6 authored by Simon Flaisch's avatar Simon Flaisch
Browse files

Adding a script for a testing consumer of the mqtt messagebus. Ideal for debugging :)

parent 7a515f82
No related merge requests found
import keyboard
import paho.mqtt.client as mqtt
# The callback for when the client receives a CONNACK response from the server.
def on_connect(client, userdata, flags, reason_code, properties):
print(f"Connected with result code {reason_code}")
client.subscribe("Topic1")
# The callback for when a PUBLISH message is received from the server.
def on_message(client, userdata, msg):
print(msg.topic+" "+str(msg.payload))
mqttc = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2, userdata=None)
mqttc.on_connect = on_connect
mqttc.on_message = on_message
mqttc.username_pw_set(username="standardUser", password="GreatHHZ4Ever!")
mqttc.connect("localhost", 1883)
while True:
mqttc.loop_start()
if keyboard.read_key == "space":
mqttc.disconnect()
mqttc.loop_stop()
print("goodbye!")
break
mqttc.loop_stop()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment