mirror of
https://github.com/thingsboard/thingsboard-gateway
synced 2025-10-26 22:31:42 +08:00
Fixed FTP RPCs processing
This commit is contained in:
@@ -28,16 +28,8 @@ from thingsboard_gateway.connectors.ftp.file import File
|
|||||||
from thingsboard_gateway.connectors.ftp.ftp_uplink_converter import FTPUplinkConverter
|
from thingsboard_gateway.connectors.ftp.ftp_uplink_converter import FTPUplinkConverter
|
||||||
from thingsboard_gateway.connectors.ftp.path import Path
|
from thingsboard_gateway.connectors.ftp.path import Path
|
||||||
from thingsboard_gateway.gateway.statistics_service import StatisticsService
|
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
|
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
|
from thingsboard_gateway.connectors.connector import Connector
|
||||||
|
|
||||||
|
|
||||||
@@ -83,6 +75,7 @@ class FTPConnector(Connector, Thread):
|
|||||||
)
|
)
|
||||||
for obj in self.__config['paths']
|
for obj in self.__config['paths']
|
||||||
]
|
]
|
||||||
|
self.__log.info('FTP Connector started.')
|
||||||
|
|
||||||
def open(self):
|
def open(self):
|
||||||
self.__stopped = False
|
self.__stopped = False
|
||||||
@@ -193,6 +186,7 @@ class FTPConnector(Connector, Thread):
|
|||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.__stopped = True
|
self.__stopped = True
|
||||||
|
self.__log.info('FTP Connector stopped.')
|
||||||
self.__log.reset()
|
self.__log.reset()
|
||||||
|
|
||||||
def get_name(self):
|
def get_name(self):
|
||||||
@@ -263,7 +257,8 @@ class FTPConnector(Connector, Thread):
|
|||||||
|
|
||||||
@StatisticsService.CollectAllReceivedBytesStatistics('allBytesSentToDevices')
|
@StatisticsService.CollectAllReceivedBytesStatistics('allBytesSentToDevices')
|
||||||
def _get_io_stream(self, data_expression):
|
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):
|
def __fill_rpc_requests(self):
|
||||||
for rpc_request in self.__config.get("serverSideRpc", []):
|
for rpc_request in self.__config.get("serverSideRpc", []):
|
||||||
@@ -276,7 +271,7 @@ class FTPConnector(Connector, Thread):
|
|||||||
if fullmatch(rpc_request['deviceNameFilter'], content['device']) and fullmatch(
|
if fullmatch(rpc_request['deviceNameFilter'], content['device']) and fullmatch(
|
||||||
rpc_request['methodFilter'], content['data']['method']):
|
rpc_request['methodFilter'], content['data']['method']):
|
||||||
with self.__ftp() as ftp:
|
with self.__ftp() as ftp:
|
||||||
if not self._connected:
|
if not self._connected or not ftp.sock:
|
||||||
self.__connect(ftp)
|
self.__connect(ftp)
|
||||||
|
|
||||||
converted_data = None
|
converted_data = None
|
||||||
|
|||||||
@@ -125,7 +125,8 @@ class StatisticsService(Thread):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func(*args, **kwargs)
|
result = func(*args, **kwargs)
|
||||||
|
return result
|
||||||
|
|
||||||
return inner
|
return inner
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user