Skip to content

Commit

Permalink
Minor fixes for socket connector and remote configurator
Browse files Browse the repository at this point in the history
  • Loading branch information
imbeacon committed Nov 16, 2023
1 parent 7f16da2 commit 997afa8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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(
Expand Down
1 change: 1 addition & 0 deletions thingsboard_gateway/connectors/socket/socket_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'])

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit 997afa8

Please sign in to comment.