Skip to content

Commit 484c5ef

Browse files
committed
aioble/device: Add DeviceConnection.indicate_service_changed().
1 parent 5b496e9 commit 484c5ef

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

micropython/bluetooth/aioble/aioble/device.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,10 @@ async def exchange_mtu(self, mtu=None, timeout_ms=1000):
284284
await self._mtu_event.wait()
285285
return self.mtu
286286

287+
def indicate_service_changed(self, changed: List[Characteristic] = None):
288+
from .server import indicate_service_changed
289+
indicate_service_changed(self._conn_handle, changed)
290+
287291
# Wait for a connection on an L2CAP connection-oriented-channel.
288292
async def l2cap_accept(self, psm, mtu, timeout_ms=None):
289293
from .l2cap import accept

micropython/bluetooth/aioble/aioble/server.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,3 +338,17 @@ def register_services(*services):
338338
for descriptor in characteristic.descriptors:
339339
descriptor._register(service_handles[n])
340340
n += 1
341+
342+
343+
# Send indication on the service changed characteristic.
344+
# Targets specific connection if provided, else sends to all connected and/or bonded devices.
345+
# Flags specific changed characteristics if provided else all will be indicated.
346+
def indicate_service_changed(conn_handle=None, changed: List[Characteristic] = None):
347+
handle_start = 0x0000
348+
handle_end = 0xFFFF
349+
if changed:
350+
print(_registered_characteristics)
351+
handles = sorted([c._value_handle for c in changed])
352+
handle_start = handles[0] - 1 # def handle is one less than value_handle
353+
handle_end = handles[-1]
354+
ble.gap_indicate_service_changed(conn_handle, handle_start, handle_end)

0 commit comments

Comments
 (0)