[esp32_ble_tracker] Fix missed BLE advertisements with WiFi on ESP-IDF 5.5.5 - #18356
Conversation
|
To use the changes from this PR as an external component, add the following to your ESPHome configuration YAML file: external_components:
- source: github://pr#18356
components: [ble_device_base, esp32_ble_tracker]
refresh: 1h(Added by the PR bot) |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #18356 +/- ##
=======================================
Coverage 88.59% 88.59%
=======================================
Files 67 67
Lines 15299 15299
Branches 2319 2319
=======================================
Hits 13554 13554
Misses 1434 1434
Partials 311 311 🚀 New features to boost your workflow:
|
Memory Impact AnalysisComponents:
This analysis runs automatically when components change. Memory usage is measured from a representative test configuration. |
|
👋 Hi there! This PR modifies 2 file(s) with codeowners. @Bl00d-B0b - As codeowner(s) of the affected files, your review would be appreciated! 🙏 Note: Automatic review request may have failed, but you're still welcome to review. |
There was a problem hiding this comment.
Pull request overview
This PR adjusts the default BLE scan window behavior for esp32_ble_tracker to prevent missed advertisements when WiFi coexistence is active on ESP-IDF versions where the scan window is now honored strictly (ESP-IDF >= 5.5.5). It fits into ESPHome’s config-validation layer by making the default window conditional while preserving explicit user configuration.
Changes:
- Introduces a conditional scan window default for ESP32 that (when safe) raises the default window to match the interval under WiFi coexistence on ESP-IDF >= 5.5.5.
- Extends the shared BLE scan-parameter schema to support a callable window default (needed for “defaulted vs explicitly set” tracking).
- Adds targeted component tests to cover the new WiFi/IDF-version-dependent defaulting behavior.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/component_tests/esp32_ble_tracker/test_scan_window_default.py | Adds tests validating the conditional scan window default matrix (WiFi on/off, IDF fixed/unfixed, explicit window). |
| tests/component_tests/ble_device_base/test_scan_parameter_validation.py | Updates ESP32 default-validation test docstring to reflect the conditional window behavior and where it’s covered. |
| esphome/components/esp32_ble_tracker/init.py | Implements conditional default tracking and post-schema adjustment of the defaulted scan window based on coexistence + IDF version. |
| esphome/components/ble_device_base/init.py | Allows scan_parameters_schema() to accept a callable window_default and centralizes the historical default window string. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Reviewed the ble_device_base schema change as its owner: the deferred-callable form of window_default is backward compatible (plain strings unchanged), DEFAULT_SCAN_WINDOW extraction matches the previous literal, and the bk72xx/ln882h trackers are unaffected — both pin their own window strings, so the esp32-conditional path never engages for them. The coexistence rationale matches what we see on LibreTiny targets too: full-interval windows there starve WiFi without an arbiter, so keeping 30ms when software_coexistence is off is the right guard.
|
thanks |
What does this implement/fix?
ESP-IDF 5.5.5 fixed a coexistence bug where BLE scans on the ESP32 ran much longer than the configured window (espressif/esp-idf#18931). Our default 30ms window in a 320ms interval relied on that bug to work well; with the fix the scanner only listens 9.4% of the time and misses most advertisements when WiFi is active, which is why trackers and proxies became unreliable starting with 2026.7.1.
When WiFi coexistence is active and the build uses ESP-IDF 5.5.5 or newer, the scan window now defaults to the scan interval, as Espressif recommends; the radio arbiter still shares airtime with WiFi. A window set in the config is never changed. The 30ms default is kept without WiFi, on builds pinned to older IDF versions where the old behavior still applies, and when software_coexistence is disabled, since without the arbiter a full duty scan would starve WiFi.
Types of changes
Related issue or feature (if applicable):
Pull request in esphome.io with documentation (if applicable):
Pull request in developers.esphome.io with developer documentation (if applicable):
Test Environment
Example entry for
config.yaml:Checklist:
tests/folder).If user exposed functionality or configuration variables are added/changed: