From f0b683218efafae904db060eff48d58eaf59c142 Mon Sep 17 00:00:00 2001 From: Rob Knegjens Date: Tue, 5 Apr 2022 12:05:06 -0700 Subject: [PATCH] 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. --- micropython/bluetooth/aioble/examples/temp_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/micropython/bluetooth/aioble/examples/temp_client.py b/micropython/bluetooth/aioble/examples/temp_client.py index 56715838c..42752d8c9 100644 --- a/micropython/bluetooth/aioble/examples/temp_client.py +++ b/micropython/bluetooth/aioble/examples/temp_client.py @@ -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)