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...")