Skip to content

Commit 0c31e0b

Browse files
pi-mstdpgeorge
authored andcommitted
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.
1 parent 760bfef commit 0c31e0b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

micropython/bluetooth/aioble/aioble/peripheral.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,8 @@ async def advertise(
126126
struct.pack("B", (0x01 if limited_disc else 0x02) + (0x18 if br_edr else 0x04)),
127127
)
128128

129-
if name:
130-
resp_data = _append(adv_data, resp_data, _ADV_TYPE_NAME, name)
131-
129+
# Services are prioritised to go in the advertising data because iOS supports
130+
# filtering scan results by service only, so services must come first.
132131
if services:
133132
for uuid in services:
134133
b = bytes(uuid)
@@ -139,6 +138,9 @@ async def advertise(
139138
elif len(b) == 16:
140139
resp_data = _append(adv_data, resp_data, _ADV_TYPE_UUID128_COMPLETE, b)
141140

141+
if name:
142+
resp_data = _append(adv_data, resp_data, _ADV_TYPE_NAME, name)
143+
142144
if appearance:
143145
# See org.bluetooth.characteristic.gap.appearance.xml
144146
resp_data = _append(

0 commit comments

Comments
 (0)