Skip to content

Commit f0b6832

Browse files
rknegjensdpgeorge
authored andcommitted
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.
1 parent da46c4b commit f0b6832

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
@@ -55,7 +55,7 @@ async def main():
5555
print("Timeout discovering services/characteristics")
5656
return
5757

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

0 commit comments

Comments
 (0)