Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed FTP RPCs processing #1260

Merged
merged 2 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions thingsboard_gateway/connectors/ftp/ftp_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -276,7 +270,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
Expand Down
3 changes: 2 additions & 1 deletion thingsboard_gateway/gateway/statistics_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ def inner(*args, **kwargs):
except ValueError:
pass

func(*args, **kwargs)
result = func(*args, **kwargs)
return result

return inner

Expand Down
Loading