From a9cb83449927600b149bd32a5efd693051298b37 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Wed, 26 Feb 2020 11:19:59 +0100 Subject: [PATCH] Be more robust in case we receive non-Unicode characters on the serial port --- platypush/plugins/serial/__init__.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/platypush/plugins/serial/__init__.py b/platypush/plugins/serial/__init__.py index 9e3a34e3..99804111 100644 --- a/platypush/plugins/serial/__init__.py +++ b/platypush/plugins/serial/__init__.py @@ -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