1
0
mirror of https://github.com/thingsboard/thingsboard-gateway synced 2025-10-26 22:31:42 +08:00

Changed device connecting logic when connection to TB is lost

This commit is contained in:
zbeacon
2021-04-26 13:55:01 +03:00
parent 4e1c603718
commit f897c65a9e
2 changed files with 6 additions and 8 deletions

View File

@@ -312,7 +312,8 @@ class MqttConnector(Connector, Thread):
def _on_log(self, *args):
self.__log.debug(args)
def _on_subscribe(self, _, __, mid, granted_qos):
def _on_subscribe(self, _, __, mid, granted_qos, *args):
log.info(args)
try:
if granted_qos[0] == 128:
self.__log.error('"%s" subscription failed to topic %s subscription message id = %i',

View File

@@ -143,7 +143,7 @@ class TBGatewayService:
self.__subscribed_to_rpc_topics = False
if self.tb_client.is_connected() and not self.__subscribed_to_rpc_topics:
for device in self.__saved_devices:
self.add_device(device, {"connector": self.__saved_devices[device]["connector"]}, True, device_type=self.__saved_devices[device]["device_type"])
self.add_device(device, {"connector": self.__saved_devices[device]["connector"]}, device_type=self.__saved_devices[device]["device_type"])
self.subscribe_to_required_topics()
self.__subscribed_to_rpc_topics = True
if self.__sheduled_rpc_calls:
@@ -323,9 +323,9 @@ class TBGatewayService:
if not TBUtility.validate_converted_data(data):
log.error("Data from %s connector is invalid.", connector_name)
return None
if data["deviceName"] not in self.get_devices():
if data["deviceName"] not in self.get_devices() and self.tb_client.is_connected():
self.add_device(data["deviceName"],
{"connector": self.available_connectors[connector_name]}, wait_for_publish=True, device_type=data["deviceType"])
{"connector": self.available_connectors[connector_name]}, device_type=data["deviceType"])
if not self.__connector_incoming_messages.get(connector_name):
self.__connector_incoming_messages[connector_name] = 0
else:
@@ -623,15 +623,12 @@ class TBGatewayService:
summary_messages.update(**telemetry)
return summary_messages
def add_device(self, device_name, content, wait_for_publish=False, device_type=None):
def add_device(self, device_name, content, device_type=None):
if device_name not in self.__saved_devices:
device_type = device_type if device_type is not None else 'default'
self.__connected_devices[device_name] = {**content, "device_type": device_type}
self.__saved_devices[device_name] = {**content, "device_type": device_type}
self.__save_persistent_devices()
if wait_for_publish:
self.tb_client.client.gw_connect_device(device_name, device_type).wait_for_publish()
else:
self.tb_client.client.gw_connect_device(device_name, device_type)
def update_device(self, device_name, event, content):