forked from platypush/platypush
Be more robust in case we receive non-Unicode characters on the serial port
This commit is contained in:
parent
52a13f0511
commit
a9cb834499
1 changed files with 7 additions and 2 deletions
|
@ -36,8 +36,7 @@ class SerialPlugin(SensorPlugin):
|
|||
self.serial_lock = threading.Lock()
|
||||
self.last_measurement = None
|
||||
|
||||
@staticmethod
|
||||
def _read_json(serial_port):
|
||||
def _read_json(self, serial_port):
|
||||
n_brackets = 0
|
||||
is_escaped_ch = False
|
||||
parse_start = False
|
||||
|
@ -48,6 +47,12 @@ class SerialPlugin(SensorPlugin):
|
|||
if not ch:
|
||||
break
|
||||
|
||||
try:
|
||||
ch = ch.decode()
|
||||
except Exception as e:
|
||||
self.logger.warning('Could not decode character: {}'.format(str(e)))
|
||||
output = bytes()
|
||||
|
||||
if ch.decode() == '{' and not is_escaped_ch:
|
||||
parse_start = True
|
||||
n_brackets += 1
|
||||
|
|
Loading…
Reference in a new issue