From f84a97b9bf2665dea91f71fb1b0f938eeb725ccf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Tue, 10 Jan 2023 19:03:37 +0100 Subject: bigclown-leds: attempt reconnect when connection refused --- bigclown-leds | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bigclown-leds b/bigclown-leds index d988bdf..fdba7e4 100755 --- a/bigclown-leds +++ b/bigclown-leds @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import configparser import sys +import time import paho.mqtt.client as mqtt @@ -41,7 +42,12 @@ def main(): # client.on_log = on_log client.username_pw_set(cnf_mqtt["username"], cnf_mqtt["password"]) - client.connect("127.0.0.1", 1883, 60) + while True: + try: + client.connect("127.0.0.1", 1883, 60) + break + except ConnectionRefusedError: + time.sleep(1) client.loop_forever() -- cgit v1.2.3