diff --git a/esphome/components/wifi/__init__.py b/esphome/components/wifi/__init__.py index 65bd5f775cf..69544f36367 100644 --- a/esphome/components/wifi/__init__.py +++ b/esphome/components/wifi/__init__.py @@ -116,6 +116,7 @@ VALIDATE_WIFI_MIN_AUTH_MODE = cv.enum(WIFI_MIN_AUTH_MODES, upper=True) WiFi8266PhyMode = wifi_ns.enum("WiFi8266PhyMode") WIFI_8266_PHY_MODES = { + "AUTO": WiFi8266PhyMode.WIFI_8266_PHY_MODE_AUTO, "11B": WiFi8266PhyMode.WIFI_8266_PHY_MODE_11B, "11G": WiFi8266PhyMode.WIFI_8266_PHY_MODE_11G, "11N": WiFi8266PhyMode.WIFI_8266_PHY_MODE_11N, diff --git a/esphome/components/wifi/wifi_component.h b/esphome/components/wifi/wifi_component.h index ef301e3d4f2..0437267a1f0 100644 --- a/esphome/components/wifi/wifi_component.h +++ b/esphome/components/wifi/wifi_component.h @@ -346,8 +346,10 @@ enum WifiMinAuthMode : uint8_t { }; #ifdef USE_WIFI_PHY_MODE -// Values match ESP8266 SDK phy_mode_t (PHY_MODE_11B=1, PHY_MODE_11G=2, PHY_MODE_11N=3). +// Values 1-3 match ESP8266 SDK phy_mode_t (PHY_MODE_11B=1, PHY_MODE_11G=2, PHY_MODE_11N=3). +// AUTO leaves the SDK at its default (no wifi_set_phy_mode() call). enum WiFi8266PhyMode : uint8_t { + WIFI_8266_PHY_MODE_AUTO = 0, WIFI_8266_PHY_MODE_11B = 1, WIFI_8266_PHY_MODE_11G = 2, WIFI_8266_PHY_MODE_11N = 3, @@ -827,7 +829,7 @@ class WiFiComponent final : public Component { wifi_band_mode_t band_mode_{WIFI_BAND_MODE_AUTO}; #endif #ifdef USE_WIFI_PHY_MODE - WiFi8266PhyMode phy_mode_{WIFI_8266_PHY_MODE_11N}; + WiFi8266PhyMode phy_mode_{WIFI_8266_PHY_MODE_AUTO}; #endif WifiMinAuthMode min_auth_mode_{WIFI_MIN_AUTH_MODE_WPA2}; WiFiRetryPhase retry_phase_{WiFiRetryPhase::INITIAL_CONNECT}; diff --git a/esphome/components/wifi/wifi_component_esp8266.cpp b/esphome/components/wifi/wifi_component_esp8266.cpp index f2ae69f5965..9d2c1bb1be0 100644 --- a/esphome/components/wifi/wifi_component_esp8266.cpp +++ b/esphome/components/wifi/wifi_component_esp8266.cpp @@ -633,6 +633,8 @@ bool WiFiComponent::wifi_sta_pre_setup_() { #ifdef USE_WIFI_PHY_MODE bool WiFiComponent::wifi_apply_phy_mode_() { + if (this->phy_mode_ == WIFI_8266_PHY_MODE_AUTO) + return true; // Values of WiFi8266PhyMode are aligned with the SDK's phy_mode_t enum. return wifi_set_phy_mode(static_cast(this->phy_mode_)); }