From f4ec1430777ace7d9ad9cd62ba82c96da4987185 Mon Sep 17 00:00:00 2001 From: samson0v Date: Tue, 17 Dec 2024 15:32:03 +0200 Subject: [PATCH 1/2] Fixed processing SET modbus RPC --- .../connectors/modbus/modbus_connector.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/thingsboard_gateway/connectors/modbus/modbus_connector.py b/thingsboard_gateway/connectors/modbus/modbus_connector.py index ed0898d7..8eb3e9fd 100644 --- a/thingsboard_gateway/connectors/modbus/modbus_connector.py +++ b/thingsboard_gateway/connectors/modbus/modbus_connector.py @@ -470,7 +470,21 @@ def __get_rpc_config(device: Slave, content): rpc_method = content['data']['method'] if rpc_method == 'get' or rpc_method == 'set': params = {} - for param in content['data']['params'].split(';'): + + if rpc_method == 'set': + input_params_and_value_list = content['data']['params'].split(' ') + if len(input_params_and_value_list) < 2: + raise ValueError('Invalid RPC request format. ' + 'Expected RPC request format: ' + 'set param_name1=param_value1;param_name2=param_value2;...; value') + + (input_params, input_value) = input_params_and_value_list + content['data']['params'] = input_value + + if rpc_method == 'get': + input_params = content.get('data', {}).get('params', {}) + + for param in input_params.split(';'): try: (key, value) = param.split('=') except ValueError: From 7c78245ec7559644d3795c7ab86224b0c20eeb8c Mon Sep 17 00:00:00 2001 From: samson0v Date: Wed, 18 Dec 2024 08:46:12 +0200 Subject: [PATCH 2/2] Fixed slave name --- thingsboard_gateway/connectors/modbus/slave.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/thingsboard_gateway/connectors/modbus/slave.py b/thingsboard_gateway/connectors/modbus/slave.py index d7ab231a..ddac21fd 100644 --- a/thingsboard_gateway/connectors/modbus/slave.py +++ b/thingsboard_gateway/connectors/modbus/slave.py @@ -35,15 +35,19 @@ def __init__(self, connector, logger, config): self.stopped = False self._log = logger self.connector = connector - self.name = "Modbus slave processor for unit " + str(config['unitId']) + " on host " + str( - config['host']) + ":" + str(config['port']) + ' ' + config['deviceName'] + self.type = config.get('type', 'tcp').lower() + + if self.type == 'serial': + self.name = "Modbus slave processor for unit " + str(config['unitId']) + " on port " + str(config['port']) + ' ' + config['deviceName'] + else: + self.name = "Modbus slave processor for unit " + str(config['unitId']) + " on host " + str( + config.get('host')) + ":" + str(config['port']) + ' ' + config['deviceName'] self.callback = connector.callback self.unit_id = config['unitId'] self.host = config.get('host') self.port = config['port'] - self.type = config.get('type', 'tcp').lower() self.method = config['method'] self.tls = config.get('tls', {}) self.timeout = config.get('timeout')