micropython/aioble: Prioritise services in advertisement payload.

A number of fields (services, appearance, manufacturer, name) can appear
when a scan is requested.  However there is only so much space in the
header so, if a user has configured multiple fields, some may be 'pushed'
into the active scan response which requires additional communication.

When iOS scans for BLE devices it can filter by services, and so services
must be in the advertising (as opposed to scan response) payload.
pull/419/merge
Matt Trentini 2022-01-04 16:23:58 +11:00 zatwierdzone przez Damien George
rodzic 760bfefd9d
commit 0c31e0b3d7
1 zmienionych plików z 5 dodań i 3 usunięć

Wyświetl plik

@ -126,9 +126,8 @@ async def advertise(
struct.pack("B", (0x01 if limited_disc else 0x02) + (0x18 if br_edr else 0x04)),
)
if name:
resp_data = _append(adv_data, resp_data, _ADV_TYPE_NAME, name)
# Services are prioritised to go in the advertising data because iOS supports
# filtering scan results by service only, so services must come first.
if services:
for uuid in services:
b = bytes(uuid)
@ -139,6 +138,9 @@ async def advertise(
elif len(b) == 16:
resp_data = _append(adv_data, resp_data, _ADV_TYPE_UUID128_COMPLETE, b)
if name:
resp_data = _append(adv_data, resp_data, _ADV_TYPE_NAME, name)
if appearance:
# See org.bluetooth.characteristic.gap.appearance.xml
resp_data = _append(