Skip to content

Commit

Permalink
Fix SDS011 interfacer compatibility for python3
Browse files Browse the repository at this point in the history
  • Loading branch information
Trystan Lea committed Sep 22, 2020
1 parent 7071c8c commit ca13484
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/emonhub_interfacer.py
Expand Up @@ -426,7 +426,7 @@ def _process_rx(self, cargo):
if not rxc:
return False
self._log.debug("%d Timestamp : %f", rxc.uri, rxc.timestamp)
self._log.debug("%d From Node : %d", rxc.uri, rxc.nodeid)
self._log.debug("%d From Node : %s", rxc.uri, str(rxc.nodeid))
if rxc.target:
self._log.debug("%d To Target : %d", rxc.uri, rxc.target)
self._log.debug("%d Values : %s", rxc.uri, rxc.realdata)
Expand Down
8 changes: 5 additions & 3 deletions src/interfacers/EmonHubSDS011Interfacer.py
Expand Up @@ -59,14 +59,16 @@ def read(self):

self.lastbyte = self.byte
self.byte = self._ser.read(size=1)

# Valid packet header
if self.lastbyte == "\xAA" and self.byte == "\xC0":
if self.lastbyte == b"\xaa" and self.byte == b"\xc0":

sentence = self._ser.read(size=8) # Read 8 more bytes
readings = struct.unpack('<hhxxcc',sentence) # Decode the packet - big endian, 2 shorts for pm2.5 and pm10, 2 reserved bytes, checksum, message tail

pm_25 = readings[0]/10.0
pm_10 = readings[1]/10.0

# self._log.debug("PM 2.5:"+str(pm_25)+"μg/m^3 PM 10:"+str(pm_10)+"μg/m^3")

self.pm_25_sum += pm_25
Expand Down Expand Up @@ -99,7 +101,7 @@ def set(self, **kwargs):
"""

for key, setting in self._template_settings.iteritems():
for key, setting in self._template_settings.items():
# Decide which setting value to use
if key in kwargs.keys():
setting = kwargs[key]
Expand Down

0 comments on commit ca13484

Please sign in to comment.