From 1b8a92e5b5f3ee1698d2407121700eaea02d8355 Mon Sep 17 00:00:00 2001 From: samson0v Date: Tue, 12 Dec 2023 12:17:34 +0200 Subject: [PATCH 1/2] Fixed FTP RPCs processing --- .../connectors/ftp/ftp_connector.py | 15 +++++---------- thingsboard_gateway/gateway/statistics_service.py | 3 ++- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/thingsboard_gateway/connectors/ftp/ftp_connector.py b/thingsboard_gateway/connectors/ftp/ftp_connector.py index 6ce859070..7b83158d8 100644 --- a/thingsboard_gateway/connectors/ftp/ftp_connector.py +++ b/thingsboard_gateway/connectors/ftp/ftp_connector.py @@ -28,16 +28,8 @@ from thingsboard_gateway.connectors.ftp.ftp_uplink_converter import FTPUplinkConverter from thingsboard_gateway.connectors.ftp.path import Path from thingsboard_gateway.gateway.statistics_service import StatisticsService -from thingsboard_gateway.tb_utility.tb_utility import TBUtility from thingsboard_gateway.tb_utility.tb_logger import init_logger -try: - from requests import Timeout, request -except ImportError: - print("Requests library not found - installing...") - TBUtility.install_package("requests") - from requests import Timeout, request - from thingsboard_gateway.connectors.connector import Connector @@ -83,6 +75,7 @@ def __init__(self, gateway, config, connector_type): ) for obj in self.__config['paths'] ] + self.__log.info('FTP Connector started.') def open(self): self.__stopped = False @@ -193,6 +186,7 @@ def __send_data(self, converted_data): def close(self): self.__stopped = True + self.__log.info('FTP Connector stopped.') self.__log.reset() def get_name(self): @@ -263,7 +257,8 @@ def on_attributes_update(self, content): @StatisticsService.CollectAllReceivedBytesStatistics('allBytesSentToDevices') def _get_io_stream(self, data_expression): - return io.BytesIO(str.encode(data_expression)) + _io = io.BytesIO(str.encode(data_expression)) + return _io def __fill_rpc_requests(self): for rpc_request in self.__config.get("serverSideRpc", []): @@ -276,7 +271,7 @@ def server_side_rpc_handler(self, content): if fullmatch(rpc_request['deviceNameFilter'], content['device']) and fullmatch( rpc_request['methodFilter'], content['data']['method']): with self.__ftp() as ftp: - if not self._connected: + if not self._connected or not ftp.sock: self.__connect(ftp) converted_data = None diff --git a/thingsboard_gateway/gateway/statistics_service.py b/thingsboard_gateway/gateway/statistics_service.py index f157be77e..299324ed9 100644 --- a/thingsboard_gateway/gateway/statistics_service.py +++ b/thingsboard_gateway/gateway/statistics_service.py @@ -125,7 +125,8 @@ def inner(*args, **kwargs): except ValueError: pass - func(*args, **kwargs) + result = func(*args, **kwargs) + return result return inner From 1db92743405667afc9807192a90e6bdf222f05ac Mon Sep 17 00:00:00 2001 From: samson0v Date: Tue, 12 Dec 2023 12:22:25 +0200 Subject: [PATCH 2/2] Fixed FTP RPCs processing --- thingsboard_gateway/connectors/ftp/ftp_connector.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/thingsboard_gateway/connectors/ftp/ftp_connector.py b/thingsboard_gateway/connectors/ftp/ftp_connector.py index 7b83158d8..ca7e9cc65 100644 --- a/thingsboard_gateway/connectors/ftp/ftp_connector.py +++ b/thingsboard_gateway/connectors/ftp/ftp_connector.py @@ -257,8 +257,7 @@ def on_attributes_update(self, content): @StatisticsService.CollectAllReceivedBytesStatistics('allBytesSentToDevices') def _get_io_stream(self, data_expression): - _io = io.BytesIO(str.encode(data_expression)) - return _io + return io.BytesIO(str.encode(data_expression)) def __fill_rpc_requests(self): for rpc_request in self.__config.get("serverSideRpc", []):