This commit is contained in:
Robert Borzutzki 2022-10-18 23:02:28 +02:00
parent 514679a801
commit db57939ad4

View File

@ -19,16 +19,14 @@ logging.basicConfig(level=logging.DEBUG)
Connected = False Connected = False
def on_connect(client, userdata, flags, rc):
if rc == 0:
print("Connected to MQTT Broker!")
def connect_mqtt() -> mqtt_client: global Connected #Use global variable
def on_connect(client, userdata, flags, rc): Connected = True #Signal connection
if rc == 0: else:
print("Connected to MQTT Broker!") print("Failed to connect, return code %d\n", rc)
global Connected #Use global variable
Connected = True #Signal connection
else:
print("Failed to connect, return code %d\n", rc)
def on_message(client, userdata, msg): def on_message(client, userdata, msg):
print(f"Received `{msg.payload.decode()}` from `{msg.topic}` topic") print(f"Received `{msg.payload.decode()}` from `{msg.topic}` topic")