From e7a5a15a759720e1e0150ada5d44094b13389d1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Fri, 20 Nov 2020 21:59:04 +0000 Subject: [PATCH] Read socket data until null character. --- neohub.py | 6 ++++-- test.py | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/neohub.py b/neohub.py index 91ef061..1e4a8b1 100644 --- a/neohub.py +++ b/neohub.py @@ -23,12 +23,14 @@ class NeoHub: writer.write(encoded_message) await writer.drain() - data = await reader.read(4096) + data = await reader.readuntil(b'\0') + data = data.strip(b'\0') json_string = data.decode('utf-8') self._logger.debug(f"Received message: {json_string}") + writer.close() await writer.wait_closed() - print(json_string) + return json.loads(json_string) diff --git a/test.py b/test.py index ee0e060..aa85c4d 100755 --- a/test.py +++ b/test.py @@ -12,7 +12,8 @@ import logging async def run(): hub = neohub.NeoHub() await hub.connect() - print(await hub.firmware()) + firmware_version = await hub.firmware() + print(firmware_version) result = await hub.get_system() print(result)