8000
Skip to content

[esp32_ble_tracker] Fix missed BLE advertisements with WiFi on ESP-IDF 5.5.5 - #18356

Merged
bdraco merged 3 commits into
devfrom
esp32_ble_tracker_coex_window_default
Aug 13, 2026
Merged

[esp32_ble_tracker] Fix missed BLE advertisements with WiFi on ESP-IDF 5.5.5#18356
bdraco merged 3 commits into
devfrom
esp32_ble_tracker_coex_window_default

Conversation

@bdraco
@bdraco bdraco commented Aug 13, 2026
Copy link
Copy Markdown
Member

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

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • New developer-facing feature (adds functionality for component developers; no end-user configuration change)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected) — policy
  • Developer breaking change (an API change that could break external components) — policy
  • Undocumented C++ API change (removal or change of undocumented public methods that lambda users may depend on) — policy
  • Code quality improvements to existing code or addition of tests
  • Other

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):

  • esphome/developers.esphome.io#<developers.esphome.io PR number goes here>

Test Environment

  • ESP32
  • ESP32 IDF
  • ESP8266
  • RP2040/RP2350
  • BK72xx
  • RTL87xx
  • LN882x
  • nRF52840

Example entry for config.yaml:

# Example config.yaml
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

esp32_ble_tracker:

Checklist:

  • The code change is tested and works locally.
  • Tests have been added to verify that the new code works (under tests/ folder).

If user exposed functionality or configuration variables are added/changed:

@bdraco bdraco added this to the 2026.8.0 milestone Aug 13, 2026
@esphome
esphome Bot commented Aug 13, 2026
Copy link
Copy Markdown
Contributor

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
codecov Bot commented Aug 13, 2026
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.59%. Comparing base (f1c4086) to head (519e334).
⚠️ Report is 1 commits behind head on dev.

Additional details and impacted files

Impacted file tree graph

@@           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:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Copy Markdown
Contributor

Memory Impact Analysis

Components: esp32_ble_tracker
Platform: esp32-idf

Metric Target Branch This PR Change
RAM 66,356 bytes 66,356 bytes ➡️ +0 bytes (0.00%)
Flash 1,072,807 bytes 1,072,807 bytes ➡️ +0 bytes (0.00%)

Note: This analysis measures static RAM and Flash usage only (compile-time allocation).
Dynamic memory (heap) cannot be measured automatically.
⚠️ You must test this PR on a real device to measure free heap and ensure no runtime memory issues.

This analysis runs automatically when components change. Memory usage is measured from a representative test configuration.

@bdraco
bdraco marked this pull request as ready for review August 13, 2026 16:13
Copilot AI lite review requested due to automatic review settings August 13, 2026 16:13
@esphome
esphome Bot commented Aug 13, 2026
Copy link
Copy Markdown
Contributor

👋 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.

Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Bl00d-B0b Bl00d-B0b left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@bdraco
bdraco commented Aug 13, 2026
Copy link
Copy Markdown
Member Author

thanks

@bdraco
bdraco merged commit db51736 into dev Aug 13, 2026
42 checks passed
@bdraco
bdraco deleted the esp32_ble_tracker_coex_window_default branch August 13, 2026 18:22
@jesserockz jesserockz mentioned this pull request Aug 14, 2026
p1ngb4ck pushed a commit to p1ngb4ck/esphome that referenced this pull request Aug 14, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 15, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

esp32_ble_tracker is unreliable after updating to >= 2026.7.1

5 participants

0