Skip to content

Commit

Permalink
Added force master creation on reconnecting
Browse files Browse the repository at this point in the history
  • Loading branch information
imbeacon committed Sep 10, 2024
1 parent 67221ed commit c8b5ad8
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions thingsboard_gateway/connectors/modbus/modbus_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit c8b5ad8

Please sign in to comment.