aioble/examples/temp_client.py: Check connection before reading temp.

Only read from the temp characteristic if the connection is still active.
Improves the example by avoiding a TypeError exception if/when the sensor
disconnects.
pull/496/head
Rob Knegjens 2022-04-05 12:05:06 -07:00 zatwierdzone przez Damien George
rodzic da46c4b9f7
commit f0b683218e
1 zmienionych plików z 1 dodań i 1 usunięć

Wyświetl plik

@ -55,7 +55,7 @@ async def main():
print("Timeout discovering services/characteristics")
return
while True:
while connection.is_connected():
temp_deg_c = _decode_temperature(await temp_characteristic.read())
print("Temperature: {:.2f}".format(temp_deg_c))
await asyncio.sleep_ms(1000)