Skip to content

Commit d7aee80

Browse files
committed
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 when the sensor disconnects.
1 parent 0c31e0b commit d7aee80

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

micropython/bluetooth/aioble/examples/temp_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ async def main():
5454
print("Timeout discovering services/characteristics")
5555
return
5656

57-
while True:
57+
while connection.is_connected():
5858
temp_deg_c = _decode_temperature(await temp_characteristic.read())
5959
print("Temperature: {:.2f}".format(temp_deg_c))
6060
await asyncio.sleep_ms(1000)

0 commit comments

Comments
 (0)