Skip to content

Commit e5389eb

Browse files
xyzzy42dpgeorge
authored andcommitted
aioble/peripheral.py: Place multiple UUIDs in single advertisement LTV.
When multiple UUIDs of the same size are advertised, they should all be listed in a single LTV. Supplement to the Bluetooth Core Specification, Part A, §1.1.1: "A packet or data block shall not contain more than one instance for each Service UUID data size." When aioble construct the advertisement data, it is creating a new data block for each UUID that contains only that single UUID. Rather than, e.g., a single 16-bit UUID block with a list of multiple UUIDs. Not only is this against the specification, it wastes two bytes of limited advertisement space per UUID beyond the first for the repeated data block length and type fields. Fix this by grouping each UUID size together. Signed-off-by: Trent Piepho <tpiepho@gmail.com>
1 parent db7f9a1 commit e5389eb

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

micropython/bluetooth/aioble-peripheral/manifest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
metadata(version="0.2.0")
1+
metadata(version="0.2.1")
22

33
require("aioble-core")
44

micropython/bluetooth/aioble/aioble/peripheral.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,13 @@ async def advertise(
129129
# Services are prioritised to go in the advertising data because iOS supports
130130
# filtering scan results by service only, so services must come first.
131131
if services:
132-
for uuid in services:
133-
b = bytes(uuid)
134-
if len(b) == 2:
135-
resp_data = _append(adv_data, resp_data, _ADV_TYPE_UUID16_COMPLETE, b)
136-
elif len(b) == 4:
137-
resp_data = _append(adv_data, resp_data, _ADV_TYPE_UUID32_COMPLETE, b)
138-
elif len(b) == 16:
139-
resp_data = _append(adv_data, resp_data, _ADV_TYPE_UUID128_COMPLETE, b)
132+
for uuid_len, code in (
133+
(2, _ADV_TYPE_UUID16_COMPLETE),
134+
(4, _ADV_TYPE_UUID32_COMPLETE),
135+
(16, _ADV_TYPE_UUID128_COMPLETE),
136+
):
137+
if uuids := [bytes(uuid) for uuid in services if len(bytes(uuid)) == uuid_len]:
138+
resp_data = _append(adv_data, resp_data, code, b"".join(uuids))
140139

141140
if name:
142141
resp_data = _append(adv_data, resp_data, _ADV_TYPE_NAME, name)

micropython/bluetooth/aioble/manifest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# code. This allows (for development purposes) all the files to live in the
44
# one directory.
55

6-
metadata(version="0.5.0")
6+
metadata(version="0.5.1")
77

88
# Default installation gives you everything. Install the individual
99
# components (or a combination of them) if you want a more minimal install.

0 commit comments

Comments
 (0)