From 95af5c233e1468de8b6bc9e6c48dc2eb9b63085c Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 23 Mar 2026 13:17:50 -1000 Subject: [PATCH] [wifi] Distinguish failed roam vs scan-induced disconnect in log Split the RECONNECTING log message into two cases: - "Reconnected after failed roam" when a specific roam target was set but we ended up on a different AP - "Reconnected after roam scan" when no roam target was set (the disconnect was caused by going off-channel during the scan itself) --- esphome/components/wifi/wifi_component.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/esphome/components/wifi/wifi_component.cpp b/esphome/components/wifi/wifi_component.cpp index d495efc82c0..2da95bf7ebe 100644 --- a/esphome/components/wifi/wifi_component.cpp +++ b/esphome/components/wifi/wifi_component.cpp @@ -1593,11 +1593,15 @@ void WiFiComponent::check_connecting_finished(uint32_t now) { if (this->roaming_target_bssid_ != bssid_t{} && current_bssid == this->roaming_target_bssid_) { char bssid_buf[MAC_ADDRESS_PRETTY_BUFFER_SIZE]; format_mac_addr_upper(current_bssid.data(), bssid_buf); - ESP_LOGD(TAG, "Roam successful (via retry) to %s", bssid_buf); + ESP_LOGD(TAG, "Roam successful (via retry, attempt %u/%u) to %s", this->roaming_attempts_, ROAMING_MAX_ATTEMPTS, + bssid_buf); this->roaming_attempts_ = 0; - } else { - // Failed roam, reconnected to different AP - keep attempts to prevent ping-pong + } else if (this->roaming_target_bssid_ != bssid_t{}) { + // Failed roam to specific target, reconnected to different AP - keep attempts to prevent ping-pong ESP_LOGD(TAG, "Reconnected after failed roam (attempt %u/%u)", this->roaming_attempts_, ROAMING_MAX_ATTEMPTS); + } else { + // Reconnected after scan-induced disconnect (no roam target) - keep attempts + ESP_LOGD(TAG, "Reconnected after roam scan (attempt %u/%u)", this->roaming_attempts_, ROAMING_MAX_ATTEMPTS); } } else { // Normal connection (boot, credentials changed, etc.)