Skip to content

_bleio: send extended advertisement data on 2M so iPhones see it; fix two extended-advertising bugs - #12055

Open
dhalbert wants to merge 3 commits into
mainfrom
dhalbert-ble-extended-adv-2m
Open

dhalbert wants to merge 3 commits into
mainfrom
dhalbert-ble-extended-adv-2m

Conversation

@dhalbert

@dhalbert dhalbert commented Dec 5, 2026

Copy link
Copy Markdown
Collaborator

Investigation and first testing by @Lotram in #12020 and #12021. Further testing by Claude and @dhalbert. Code by Claude.

Extended advertisements on 2M

Problem

An extended advertisement is one with more than 31 bytes of data. It is sent in two parts: the first part always goes out on the 1M PHY, and the second part, which holds the data, can go out on 1M or 2M. Espressif and nordic sent the second part on 1M. iPhones don't receive extended advertisements whose data is on 1M, so an iPhone never saw them.

Fix

Send the data on 2M. This is what Zephyr's Bluetooth host does by default. #12021 added a secondary_phy argument to start_advertising(), with 1M as the default. This PR uses 2M always instead, with no new argument. Legacy advertisements (31 bytes or less) are unchanged.

We did a lot of testing and research to check that always choosing 2M is safe. We could not find a case where an extended advertisement was useful to a scanner only on 1M.

The start_advertising() docs now say which clients can't see an extended advertisement: those without extended advertising support, and those that can't receive on 2M.


While testing, two additional issues were found:

espressif: legacy advertising after extended advertising

Problem

On an ESP32-C6, start_advertising() with 31 bytes or less of data failed with BluetoothError: Unknown BLE error: 0x0212 if the previous advertisement was an extended one. A soft reload didn't clear it. NimBLE's advertising set kept the previous, longer data, and the C6 controller rejects legacy parameters while the set holds more than 31 bytes.

Fix

Remove the advertising set before configuring it.

nordic: connect() to extended advertisers

Problem

_bleio.Adapter.connect() to a device sending connectable extended advertisements failed, either after the timeout or with ConnectionError: Not connected. Connecting to legacy advertisers worked. The scan parameters that connect() passes to the SoftDevice didn't enable extended advertisements.

Fix

Set extended in those scan parameters.

Testing

Boards: Metro ESP32-S3, QT Py ESP32-S3, Feather ESP32-C6, Feather nRF52840 Express, Feather nRF52840 Sense.

Scanner Sees extended advertisements on 2M Connects
iPhone 13 mini, iOS 27.2.1 yes (never on 1M) yes
Android 17 tablet yes yes
BlueZ on Linux (Intel AX210) yes yes
The boards above, scanning each other yes yes

As a scanner, the C6 misses some non-connectable advertisements, on either PHY and with or without this PR. That is a separate problem.

An Android 11 Galaxy Tab A from 2019 supports 2M but not extended advertising. It sees no extended advertisements on either PHY, as before.

dhalbert and others added 3 commits December 5, 2026 14:20
On a Feather ESP32-C6, `_bleio.Adapter.start_advertising()` failed with
`BluetoothError: Unknown BLE error: 0x0212` when the data fit in a legacy
advertisement (31 bytes or less) and the previous advertisement was an
extended one (more than 31 bytes). A soft reload didn't clear it.

CircuitPython sends every advertisement through NimBLE's advertising set 0.
`ble_gap_ext_adv_configure()` changes the set's parameters but keeps its
data. So the controller was given legacy parameters while the set still held
the longer data from before. The ESP32-C6 controller rejects that with HCI
error 0x12 (Invalid HCI Command Parameters); the ESP32-S3 controller accepts
it.

Remove set 0 before configuring it, so that it starts empty.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On a Feather nRF52840, `_bleio.Adapter.connect()` to a device sending
connectable extended advertisements failed, either after the timeout or with
`ConnectionError: Not connected`. Connecting to legacy advertisers worked.

`connect()` gives the SoftDevice its own scan parameters, and left their
`extended` flag unset. Without it, the SoftDevice ignores the secondary
advertising channels. An extended advertisement sends its data there, and a
central has to answer there to connect.

Set `extended`. Legacy advertisers are still accepted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An iPhone doesn't see an extended advertisement (one with more than 31 bytes
of data) when its data is sent on the 1M PHY. Espressif and nordic sent it on
1M, so an iPhone never saw CircuitPython's extended advertisements.

An extended advertisement has two parts. The first part always goes out on
1M. The second part holds the data and can go out on 1M or 2M. Send it on
2M, as Zephyr's Bluetooth host does by default. Legacy advertisements are
unchanged.

The `start_advertising()` docs now say which clients can't see an extended
advertisement.

Tested with an iPhone 13 mini (iOS 27.2.1), an Android 17 tablet, and BlueZ,
on a Metro ESP32-S3, QT Py ESP32-S3, Feather ESP32-C6, Feather nRF52840
Express and Feather nRF52840 Sense.

Co-authored-by: Laurent Tramoy <laurenttramoy@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dhalbert

dhalbert commented Dec 5, 2026

Copy link
Copy Markdown
Collaborator Author

@Lotram if you would like to test that would be welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_bleio: iPhones can't see BLE extended advertisements; add a secondary_phy option

1 participant