Skip to content

aioble/device: Add DeviceConnection.indicate_service_changed(). #467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions micropython/bluetooth/aioble/aioble/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ async def exchange_mtu(self, mtu=None):
await self._mtu_event.wait()
return self.mtu

def indicate_service_changed(self, changed: List[Characteristic] = None):
from .server import indicate_service_changed
indicate_service_changed(self._conn_handle, changed)

# Wait for a connection on an L2CAP connection-oriented-channel.
async def l2cap_accept(self, psm, mtu, timeout_ms=None):
from .l2cap import accept
Expand Down
14 changes: 14 additions & 0 deletions micropython/bluetooth/aioble/aioble/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,17 @@ def register_services(*services):
for descriptor in characteristic.descriptors:
descriptor._register(service_handles[n])
n += 1


# Send indication on the service changed characteristic.
# Targets specific connection if provided, else sends to all connected and/or bonded devices.
# Flags specific changed characteristics if provided else all will be indicated.
def indicate_service_changed(conn_handle=None, changed: List[Characteristic] = None):
handle_start = 0x0000
handle_end = 0xFFFF
if changed:
print(_registered_characteristics)
handles = sorted([c._value_handle for c in changed])
handle_start = handles[0] - 1 # def handle is one less than value_handle
handle_end = handles[-1]
ble.gap_indicate_service_changed(conn_handle, handle_start, handle_end)