Select Git revision
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
Consumer.py 854 B
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()