From 1b1cd58d681844dea3c5cdcc43e38ca57fe87e1f Mon Sep 17 00:00:00 2001 From: zbeacon Date: Fri, 3 Jan 2020 14:26:28 +0200 Subject: [PATCH] Fix for modbus --- .../connectors/modbus/modbus_connector.py | 12 ++++++------ thingsboard_gateway/tb_utility/tb_utility.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/thingsboard_gateway/connectors/modbus/modbus_connector.py b/thingsboard_gateway/connectors/modbus/modbus_connector.py index abf40fd62..f71992137 100644 --- a/thingsboard_gateway/connectors/modbus/modbus_connector.py +++ b/thingsboard_gateway/connectors/modbus/modbus_connector.py @@ -125,7 +125,9 @@ def __process_devices(self): log.debug(device_responses) converted_data = self.__devices[device]["converter"].convert(config=None, data=device_responses) - if (converted_data["telemetry"] != self.__devices[device]["telemetry"] or converted_data["attributes"] != self.__devices[device]["attributes"]) and self.__config.get("sendDataOnlyOnChange") == True: + if (converted_data["telemetry"] != self.__devices[device]["telemetry"] \ + or converted_data["attributes"] != self.__devices[device]["attributes"]) \ + and self.__devices[device]["config"].get("sendDataOnlyOnChange") == True: self.statistics['MessagesReceived'] += 1 to_send = {"deviceName": converted_data["deviceName"], "deviceType": converted_data["deviceType"]} if converted_data["telemetry"] != self.__devices[device]["telemetry"]: @@ -136,19 +138,17 @@ def __process_devices(self): to_send["attributes"] = converted_data["attributes"] self.__gateway.send_to_storage(self.get_name(), to_send) self.statistics['MessagesSent'] += 1 - elif self.__config.get("sendDataOnlyOnChange") == False: + elif self.__devices[device]["config"].get("sendDataOnlyOnChange") is None or self.__devices[device]["config"].get("sendDataOnlyOnChange") == False: self.statistics['MessagesReceived'] += 1 to_send = {"deviceName": converted_data["deviceName"], "deviceType": converted_data["deviceType"]} if converted_data["telemetry"] != self.__devices[device]["telemetry"]: self.__devices[device]["last_telemetry"] = converted_data["telemetry"] to_send["telemetry"] = converted_data["telemetry"] - self.__gateway.send_to_storage(self.get_name(), to_send) - self.statistics['MessagesSent'] += 1 if converted_data["attributes"] != self.__devices[device]["attributes"]: self.__devices[device]["last_telemetry"] = converted_data["attributes"] to_send["attributes"] = converted_data["attributes"] - self.__gateway.send_to_storage(self.get_name(), to_send) - self.statistics['MessagesSent'] += 1 + self.__gateway.send_to_storage(self.get_name(), to_send) + self.statistics['MessagesSent'] += 1 except ConnectionException: log.error("Connection lost! Trying to reconnect") except Exception as e: diff --git a/thingsboard_gateway/tb_utility/tb_utility.py b/thingsboard_gateway/tb_utility/tb_utility.py index 5f326caaf..7b2c21ad0 100644 --- a/thingsboard_gateway/tb_utility/tb_utility.py +++ b/thingsboard_gateway/tb_utility/tb_utility.py @@ -34,7 +34,7 @@ def validate_converted_data(data): if not data.get("deviceType") or data.get("deviceType") is None: log.error('deviceType is empty in data: %s', json_data) return False - if not data["attributes"] and not data["telemetry"]: + if (data.get("attributes") is None and data.get("telemetry") is None) or (not data.get("attributes") and not data.get("telemetry")): log.error('No telemetry and attributes in data: %s', json_data) return False return True