From 9fcf1b76b54c33db414ab79b39d81ec39691957a Mon Sep 17 00:00:00 2001 From: caleb Date: Fri, 13 Oct 2023 05:15:26 +0100 Subject: [PATCH] reset the connection every hour to be more stable --- relay.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/relay.py b/relay.py index 7f087d1..2548199 100644 --- a/relay.py +++ b/relay.py @@ -99,6 +99,7 @@ def end(): RUN=0 def main(): + reset_count=0 print("Start Relay Contorl") sys.stdout.flush() client=mqtt_setup() @@ -119,6 +120,17 @@ def main(): except: print("Failed to reconnect") sys.stdout.flush() + elif reset_count>=720: + try: + client.loop_stop() + client.reconnect() + client.subscribe(topic_control) + client.loop_start() + reset_count=0 + except: + print("Couldn't reconnect"); + sys.stdout.flush() + gpio.cleanup() exit()