From e84edb0b16f3df6533adfd7fbd03b72ee429cf9b Mon Sep 17 00:00:00 2001 From: NilsGrunwald Date: Mon, 28 Aug 2023 19:03:13 +0200 Subject: [PATCH] Added reconnect to ThingsBoard Mqtt --- Mqtt2ThingBoardGateWay.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Mqtt2ThingBoardGateWay.py b/Mqtt2ThingBoardGateWay.py index c90185b..aa96944 100644 --- a/Mqtt2ThingBoardGateWay.py +++ b/Mqtt2ThingBoardGateWay.py @@ -25,6 +25,8 @@ class Mqtt2ThingBoard: #Sent message to MQTT ThingsBoard Gateway def publishTelemetryMsg(self,msg): + if self.tb_client.is_connected == False: + self.tb_client.connect(self.host_name,self.tb_port) self.tb_client.publish("v1/gateway/telemetry",msg,0,True) @@ -58,10 +60,7 @@ class Mqtt2ThingBoard: #set up the system: login to MQTT + get all needed data from the BSH def __init__(self): self.publishDebugMsg("Connecting to MQTT Server") - ret1 = self.mqtt_client.connect(self.host_name,self.host_port) - - self.publishDebugMsg("Connecting to ThingsBoard Mqtt Gateway") - ret2 = self.tb_client.connect(self.host_name,self.tb_port) + self.mqtt_client.connect(self.host_name,self.host_port) self.publishDebugMsg("Setting up the Environment...")