Skip to content

Commit

Permalink
Wait for MQTT broker to come online on start
Browse files Browse the repository at this point in the history
  • Loading branch information
argilo committed Mar 10, 2024
1 parent b80f60d commit 5a71989
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,13 @@ def on_message(client, serial_queue, message):
mqttc.will_set(TOPIC_AVAILABILITY, "offline", retain=True)
mqttc.on_connect = on_connect
mqttc.on_message = on_message
mqttc.connect(args.H)
while True:
try:
mqttc.connect(args.H)
break
except OSError as e:
print(f"Error connecting to MQTT broker. Will retry in 5 seconds. {e}")
time.sleep(5)
mqttc.loop_start()

finished = threading.Event()
Expand Down

0 comments on commit 5a71989

Please sign in to comment.