1
0
mirror of https://github.com/thingsboard/thingsboard-gateway synced 2025-10-26 22:31:42 +08:00

Fix for mixed function codes (3 and 4), Fix for connection to BLE devices.

This commit is contained in:
zbeacon
2019-12-31 11:04:33 +02:00
parent 6dab6030a6
commit a47ace6b08
4 changed files with 14 additions and 6 deletions

2
.gitignore vendored
View File

@@ -18,3 +18,5 @@ thingsboard_gateway/storage/data/
/thingsboard_gateway.egg-info/
/docker/python3-thingsboard-gateway.deb
/data/
/logs/
__pycache__

View File

@@ -92,10 +92,10 @@ class BLEConnector(Connector, Thread):
if content['data'].get(requests['attributeOnThingsBoard']) is not None:
try:
self.__check_and_reconnect(device)
characteristic.write(content['data'][requests['attributeOnThingsBoard']].encode('UTF-8'))
resp = characteristic.write(content['data'][requests['attributeOnThingsBoard']].encode('UTF-8'), True)
except BTLEDisconnectError:
self.__check_and_reconnect(device)
characteristic.write(content['data'][requests['attributeOnThingsBoard']].encode('UTF-8'))
resp = characteristic.write(content['data'][requests['attributeOnThingsBoard']].encode('UTF-8'), True)
except Exception as e:
log.exception(e)
else:
@@ -187,7 +187,10 @@ class BLEConnector(Connector, Thread):
self.__devices_around[device]['peripheral'] = peripheral
else:
peripheral = self.__devices_around[device]['peripheral']
peripheral.connect(self.__devices_around[device]['scanned_device'])
try:
peripheral.connect(self.__devices_around[device]['scanned_device'])
except Exception as e:
log.exception(e)
services = peripheral.getServices()
for service in services:
if self.__devices_around[device].get('services') is None:

View File

@@ -49,6 +49,8 @@ class BytesBLEUplinkConverter(BLEUplinkConverter):
byte_from = config['section_config'].get('byteFrom')
byte_to = config['section_config'].get('byteTo')
try:
if data is None:
return {}
byte_to = byte_to if byte_to != -1 else len(data)
converted_data = data[byte_from: byte_to]
try:

View File

@@ -20,6 +20,7 @@ from thingsboard_gateway.tb_utility.tb_utility import TBUtility
from pymodbus.client.sync import ModbusTcpClient, ModbusUdpClient, ModbusSerialClient, ModbusRtuFramer, ModbusSocketFramer
from pymodbus.bit_write_message import WriteSingleCoilResponse, WriteMultipleCoilsResponse
from pymodbus.register_write_message import WriteMultipleRegistersResponse, WriteSingleRegisterResponse
from pymodbus.register_read_message import ReadRegistersResponseBase
from pymodbus.exceptions import ConnectionException
from thingsboard_gateway.connectors.connector import Connector, log
from thingsboard_gateway.connectors.modbus.bytes_modbus_uplink_converter import BytesModbusUplinkConverter
@@ -113,7 +114,7 @@ class ModbusConnector(Connector, threading.Thread):
current_data = self.__devices[device]["config"][config_data][interested_data]
current_data["deviceName"] = device
input_data = self.__function_to_device(current_data, unit_id)
if input_data.isError():
if not isinstance(input_data, ReadRegistersResponseBase) and input_data.isError():
log.exception(input_data)
continue
device_responses[config_data][current_data["tag"]] = {"data_sent": current_data,
@@ -174,8 +175,8 @@ class ModbusConnector(Connector, threading.Thread):
self.__available_functions = {
1: self.__master.read_coils,
2: self.__master.read_discrete_inputs,
3: self.__master.read_input_registers,
4: self.__master.read_holding_registers,
3: self.__master.read_holding_registers,
4: self.__master.read_input_registers,
5: self.__master.write_coils,
6: self.__master.write_registers,
15: self.__master.write_coils,