From 09f0e47386c283b17e44cfeee0329165b654d6e2 Mon Sep 17 00:00:00 2001 From: Andrew Leech Date: Tue, 17 Aug 2021 11:17:29 +1000 Subject: [PATCH] aioble: Add timeout to device.exchange_mtu. Signed-off-by: Jim Mussared --- micropython/bluetooth/aioble/aioble/device.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/micropython/bluetooth/aioble/aioble/device.py b/micropython/bluetooth/aioble/aioble/device.py index ea87be35..265d6215 100644 --- a/micropython/bluetooth/aioble/aioble/device.py +++ b/micropython/bluetooth/aioble/aioble/device.py @@ -262,7 +262,7 @@ class DeviceConnection: def timeout(self, timeout_ms): return DeviceTimeout(self, timeout_ms) - async def exchange_mtu(self, mtu=None): + async def exchange_mtu(self, mtu=None, timeout_ms=1000): if not self.is_connected(): raise ValueError("Not connected") @@ -271,7 +271,8 @@ class DeviceConnection: self._mtu_event = self._mtu_event or asyncio.ThreadSafeFlag() ble.gattc_exchange_mtu(self._conn_handle) - await self._mtu_event.wait() + with self.timeout(timeout_ms): + await self._mtu_event.wait() return self.mtu # Wait for a connection on an L2CAP connection-oriented-channel.