From 997afa8b86ffc985494db794442293181d086228 Mon Sep 17 00:00:00 2001 From: imbeacon Date: Thu, 16 Nov 2023 10:23:55 +0200 Subject: [PATCH] Minor fixes for socket connector and remote configurator --- .../socket/bytes_socket_uplink_converter.py | 16 +++++++--------- .../connectors/socket/socket_connector.py | 1 + .../tb_utility/tb_gateway_remote_configurator.py | 7 ++++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/thingsboard_gateway/connectors/socket/bytes_socket_uplink_converter.py b/thingsboard_gateway/connectors/socket/bytes_socket_uplink_converter.py index 8ce6921d6..194668842 100644 --- a/thingsboard_gateway/connectors/socket/bytes_socket_uplink_converter.py +++ b/thingsboard_gateway/connectors/socket/bytes_socket_uplink_converter.py @@ -20,10 +20,6 @@ class BytesSocketUplinkConverter(SocketUplinkConverter): def __init__(self, config, logger): self._log = logger self.__config = config - dict_result = { - "deviceName": config['deviceName'], - "deviceType": config['deviceType'] - } @StatisticsService.CollectStatistics(start_stat_type='receivedBytesFromDevices', end_stat_type='convertedBytesFromDevice') @@ -48,11 +44,13 @@ def convert(self, config, data): byte_to = byte_to if byte_to != -1 else len(data) converted_data = data[byte_from:byte_to] - - try: - converted_data = converted_data.replace(b"\x00", b'').decode(config['encoding']) - except UnicodeDecodeError: - converted_data = str(converted_data) + if config['encoding'] == 'hex': + converted_data = converted_data.hex() + else: + try: + converted_data = converted_data.replace(b"\x00", b'').decode(config['encoding']) + except UnicodeDecodeError: + converted_data = str(converted_data) if item.get('key') is not None: dict_result[section].append( diff --git a/thingsboard_gateway/connectors/socket/socket_connector.py b/thingsboard_gateway/connectors/socket/socket_connector.py index c063533de..37b839afe 100644 --- a/thingsboard_gateway/connectors/socket/socket_connector.py +++ b/thingsboard_gateway/connectors/socket/socket_connector.py @@ -294,6 +294,7 @@ def close(self): self.__stopped = True self._connected = False self.__connections = {} + self.__socket.close() self.__log.reset() def get_name(self): diff --git a/thingsboard_gateway/tb_utility/tb_gateway_remote_configurator.py b/thingsboard_gateway/tb_utility/tb_gateway_remote_configurator.py index 186662818..14015b6c6 100644 --- a/thingsboard_gateway/tb_utility/tb_gateway_remote_configurator.py +++ b/thingsboard_gateway/tb_utility/tb_gateway_remote_configurator.py @@ -207,7 +207,8 @@ def send_current_configuration(self): already_sent_connectors = [] for connector in self.connectors_configuration: self._gateway.tb_client.client.send_attributes( - {connector['name']: {**connector, 'logLevel': connector['configurationJson'].get('logLevel', 'INFO'), + {connector['name']: {**connector, + 'logLevel': connector.get('configurationJson', {}).get('logLevel', 'INFO'), 'ts': int(time() * 1000)}}) already_sent_connectors.append(connector['configuration']) @@ -283,7 +284,7 @@ def _handle_general_configuration_update(self, config): if config['host'] != self.general_configuration['host'] or config['port'] != self.general_configuration[ 'port'] or config['security'] != self.general_configuration['security'] or config.get('provisioning', {}) != self.general_configuration.get( - 'provisioning', {}) or config['qos'] != self.general_configuration['qos']: + 'provisioning', {}) or config['qos'] != self.general_configuration['qos']: LOG.info('---- Connection configuration changed. Processing...') success = self._apply_connection_config(config) if not success: @@ -482,7 +483,7 @@ def _handle_connector_configuration_update(self, config): if found_connector.get('name') != config['name'] or found_connector.get('type') != config[ 'type'] or found_connector.get('class') != config.get('class') or found_connector.get( 'key') != config.get('key') or found_connector.get('configurationJson', {}).get( - 'logLevel') != config.get('logLevel'): + 'logLevel') != config.get('logLevel'): changed = True connector_configuration = {'name': config['name'], 'type': config['type'], 'configuration': config_file_name}