Added reconnect to ThingsBoard Mqtt

This commit is contained in:
2023-08-28 19:03:13 +02:00
parent 272b82d463
commit e84edb0b16

View File

@@ -25,6 +25,8 @@ class Mqtt2ThingBoard:
#Sent message to MQTT ThingsBoard Gateway #Sent message to MQTT ThingsBoard Gateway
def publishTelemetryMsg(self,msg): 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) 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 #set up the system: login to MQTT + get all needed data from the BSH
def __init__(self): def __init__(self):
self.publishDebugMsg("Connecting to MQTT Server") self.publishDebugMsg("Connecting to MQTT Server")
ret1 = self.mqtt_client.connect(self.host_name,self.host_port) 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.publishDebugMsg("Setting up the Environment...") self.publishDebugMsg("Setting up the Environment...")