From 191494ede7fb11585b2cba418f5eeee8d3d3aab0 Mon Sep 17 00:00:00 2001 From: Stephen More Date: Mon, 25 Mar 2024 08:49:00 -0400 Subject: [PATCH 1/2] aioble/examples/temp_sensor.py: Properly notify on update. This ensures that the peripheral notifies subscribed clients when the characteristic is written to. Signed-off-by: Stephen More --- micropython/bluetooth/aioble/examples/temp_sensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/micropython/bluetooth/aioble/examples/temp_sensor.py b/micropython/bluetooth/aioble/examples/temp_sensor.py index bdd8c1c5e..8ab3df700 100644 --- a/micropython/bluetooth/aioble/examples/temp_sensor.py +++ b/micropython/bluetooth/aioble/examples/temp_sensor.py @@ -40,7 +40,7 @@ def _encode_temperature(temp_deg_c): async def sensor_task(): t = 24.5 while True: - temp_characteristic.write(_encode_temperature(t)) + temp_characteristic.write(_encode_temperature(t), send_update=True) t += random.uniform(-0.5, 0.5) await asyncio.sleep_ms(1000) From d4362d5cc3a6d90fabc9a684e1e7c5a29cc47f6e Mon Sep 17 00:00:00 2001 From: Stephen More Date: Mon, 25 Mar 2024 16:10:09 -0400 Subject: [PATCH 2/2] aioble/examples/temp_sensor.py: Wait forever for client to disconnect. This sets the disconnected timeout to None, so that the peripheral waits forever for the client to disconnect. Previously the peripheral would abort the connection after 60 seconds (because that's the default timeout). Signed-off-by: Stephen More --- micropython/bluetooth/aioble/examples/temp_sensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/micropython/bluetooth/aioble/examples/temp_sensor.py b/micropython/bluetooth/aioble/examples/temp_sensor.py index 8ab3df700..29f774bee 100644 --- a/micropython/bluetooth/aioble/examples/temp_sensor.py +++ b/micropython/bluetooth/aioble/examples/temp_sensor.py @@ -56,7 +56,7 @@ async def peripheral_task(): appearance=_ADV_APPEARANCE_GENERIC_THERMOMETER, ) as connection: print("Connection from", connection.device) - await connection.disconnected() + await connection.disconnected(timeout_ms=None) # Run both tasks.