Skip to content

Commit

Permalink
Fix for modbus
Browse files Browse the repository at this point in the history
  • Loading branch information
imbeacon committed Jan 3, 2020
1 parent 72524f3 commit 1b1cd58
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions thingsboard_gateway/connectors/modbus/modbus_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]:
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion thingsboard_gateway/tb_utility/tb_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1b1cd58

Please sign in to comment.