From c8b5ad8a0ee1ad9510ef863ca386e53a0ed1d004 Mon Sep 17 00:00:00 2001 From: imbeacon Date: Tue, 10 Sep 2024 14:40:24 +0300 Subject: [PATCH] Added force master creation on reconnecting --- .../connectors/modbus/modbus_connector.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/thingsboard_gateway/connectors/modbus/modbus_connector.py b/thingsboard_gateway/connectors/modbus/modbus_connector.py index 174c19dfb..4efb5f84a 100644 --- a/thingsboard_gateway/connectors/modbus/modbus_connector.py +++ b/thingsboard_gateway/connectors/modbus/modbus_connector.py @@ -446,13 +446,14 @@ def __process_slaves(self): sleep(.001) - def __connect_to_current_master(self, device=None): + def __connect_to_current_master(self, device: Slave=None): connect_attempt_count = 5 connect_attempt_time_ms = 100 wait_after_failed_attempts_ms = 300000 - if device.config.get('master') is None: - device.config['master'], device.config['available_functions'] = self.__get_or_create_connection(device.config) + force_update_master = device.config['connection_attempt'] > 0 + if device.config.get('master') is None or force_update_master: + device.config['master'], device.config['available_functions'] = self.__get_or_create_connection(device.config, force_update_master) if connect_attempt_count < 1: connect_attempt_count = 1 @@ -492,6 +493,8 @@ def __connect_to_current_master(self, device=None): device.config['connection_attempt'] = 0 device.config['last_connection_attempt_time'] = current_time return True + else: + return False @staticmethod def __configure_master(config):