Repository navigation
_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
Open
_bleio: send extended advertisement data on 2M so iPhones see it; fix two extended-advertising bugs#12055dhalbert wants to merge 3 commits into
dhalbert wants to merge 3 commits into
Conversation
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>
Collaborator
Author
|
@Lotram if you would like to test that would be welcome. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_phyargument tostart_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 withBluetoothError: Unknown BLE error: 0x0212if 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 advertisersProblem
_bleio.Adapter.connect()to a device sending connectable extended advertisements failed, either after the timeout or withConnectionError: Not connected. Connecting to legacy advertisers worked. The scan parameters thatconnect()passes to the SoftDevice didn't enable extended advertisements.Fix
Set
extendedin those scan parameters.Testing
Boards: Metro ESP32-S3, QT Py ESP32-S3, Feather ESP32-C6, Feather nRF52840 Express, Feather nRF52840 Sense.
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.