mirror of
https://github.com/esphome/esphome.git
synced 2026-05-23 11:16:52 +08:00
[wifi] Filter fast_connect by band_mode and use background scan for roaming (#15152)
This commit is contained in:
committed by
Jesse Hills
parent
f5f99071fb
commit
92642df419
@@ -2229,6 +2229,14 @@ bool WiFiComponent::load_fast_connect_settings_(WiFiAP ¶ms) {
|
||||
params.set_hidden(false);
|
||||
|
||||
ESP_LOGD(TAG, "Loaded fast_connect settings");
|
||||
#if defined(USE_ESP32) && defined(SOC_WIFI_SUPPORT_5G)
|
||||
if ((this->band_mode_ == WIFI_BAND_MODE_5G_ONLY && fast_connect_save.channel < FIRST_5GHZ_CHANNEL) ||
|
||||
(this->band_mode_ == WIFI_BAND_MODE_2G_ONLY && fast_connect_save.channel >= FIRST_5GHZ_CHANNEL)) {
|
||||
ESP_LOGW(TAG, "Saved channel %u not allowed by band mode, ignoring fast_connect", fast_connect_save.channel);
|
||||
this->selected_sta_index_ = -1;
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -774,6 +774,8 @@ class WiFiComponent : public Component {
|
||||
SemaphoreHandle_t high_performance_semaphore_{nullptr};
|
||||
#endif
|
||||
|
||||
static constexpr uint8_t FIRST_5GHZ_CHANNEL = 36;
|
||||
|
||||
// Post-connect roaming constants
|
||||
static constexpr uint32_t ROAMING_CHECK_INTERVAL = 5 * 60 * 1000; // 5 minutes
|
||||
static constexpr int8_t ROAMING_MIN_IMPROVEMENT = 10; // dB
|
||||
|
||||
@@ -961,6 +961,11 @@ bool WiFiComponent::wifi_scan_start_(bool passive) {
|
||||
config.scan_time.active.min = 100;
|
||||
config.scan_time.active.max = 300;
|
||||
}
|
||||
// When scanning while connected (roaming), return to home channel between
|
||||
// each scanned channel to maintain the connection (helps with BLE/WiFi coexistence)
|
||||
if (this->roaming_state_ == RoamingState::SCANNING) {
|
||||
config.coex_background_scan = true;
|
||||
}
|
||||
|
||||
esp_err_t err = esp_wifi_scan_start(&config, false);
|
||||
if (err != ESP_OK) {
|
||||
|
||||
Reference in New Issue
Block a user