Read socket data until null character.

This commit is contained in:
Andrius Štikonas 2020-11-20 21:59:04 +00:00
parent 7827133b89
commit e7a5a15a75
2 changed files with 6 additions and 3 deletions

View File

@ -23,12 +23,14 @@ class NeoHub:
writer.write(encoded_message) writer.write(encoded_message)
await writer.drain() 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') json_string = data.decode('utf-8')
self._logger.debug(f"Received message: {json_string}") self._logger.debug(f"Received message: {json_string}")
writer.close() writer.close()
await writer.wait_closed() await writer.wait_closed()
print(json_string)
return json.loads(json_string) return json.loads(json_string)

View File

@ -12,7 +12,8 @@ import logging
async def run(): async def run():
hub = neohub.NeoHub() hub = neohub.NeoHub()
await hub.connect() await hub.connect()
print(await hub.firmware()) firmware_version = await hub.firmware()
print(firmware_version)
result = await hub.get_system() result = await hub.get_system()
print(result) print(result)