From 56800697685b87c760bb0408260d2eb1453f0cfa Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Wed, 7 Jan 2026 14:47:54 +0100 Subject: [PATCH] Add ESP32 setPhyMode in WiFi Init and force HT20 --- .../WiFiHelper/src/WiFiHelper_ESP32.cpp | 27 ++++++++++++++++--- tasmota/tasmota_support/support_wifi.ino | 8 ++---- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/lib/default/WiFiHelper/src/WiFiHelper_ESP32.cpp b/lib/default/WiFiHelper/src/WiFiHelper_ESP32.cpp index 384f1f0aa..de0a24619 100644 --- a/lib/default/WiFiHelper/src/WiFiHelper_ESP32.cpp +++ b/lib/default/WiFiHelper/src/WiFiHelper_ESP32.cpp @@ -190,10 +190,29 @@ int WiFiHelper::getPhyMode() { } bool WiFiHelper::setPhyMode(WiFiPhyMode_t mode) { - // 1 = B - // 2 = BG - // 3 = BGN - // 4 = BGNAX + /* + mode 1 = B + mode 2 = BG + mode 3 = BGN + mode 4 = BGNAX + */ + /* + ESPEasy: + HT20 = 20 MHz channel width. + HT40 = 40 MHz channel width. + In theory, HT40 can offer upto 150 Mbps connection speed. + However since HT40 is using nearly all channels on 2.4 GHz WiFi, + Thus you are more likely to experience disturbances. + The response speed and stability is better at HT20 for ESP units. + */ + esp_wifi_set_bandwidth(WIFI_IF_STA, WIFI_BW_HT20); + /* + ESPEasy: + Set to use "Long GI" making it more resilliant to reflections + See: https://www.tp-link.com/us/configuration-guides/q_a_basic_wireless_concepts/?configurationId=2958#_idTextAnchor038 + */ + esp_wifi_config_80211_tx_rate(WIFI_IF_STA, WIFI_PHY_RATE_MCS3_LGI); + uint8_t protocol_bitmap = WIFI_PROTOCOL_11B; // 1 switch (mode) { case 4: protocol_bitmap |= WIFI_PROTOCOL_11AX; // 16 diff --git a/tasmota/tasmota_support/support_wifi.ino b/tasmota/tasmota_support/support_wifi.ino index cb1755b79..fbdde65b3 100644 --- a/tasmota/tasmota_support/support_wifi.ino +++ b/tasmota/tasmota_support/support_wifi.ino @@ -329,13 +329,9 @@ void WifiBegin(uint8_t flag, uint8_t channel) { WiFiSetSleepMode(); WifiSetOutputPower(); -// if (WiFiHelper::getPhyMode() != WIFI_PHY_MODE_11N) { WiFiHelper::setPhyMode(WIFI_PHY_MODE_11N); } // B/G/N -// if (WiFiHelper::getPhyMode() != WIFI_PHY_MODE_11G) { WiFiHelper::setPhyMode(WIFI_PHY_MODE_11G); } // B/G #ifdef ESP32 - if (Wifi.phy_mode) { - WiFiHelper::setPhyMode(WiFiPhyMode_t(Wifi.phy_mode)); // 1-B/2-BG/3-BGN/4-BGNAX - } -#endif + WiFiHelper::setPhyMode(WiFiPhyMode_t((Wifi.phy_mode > 0) ? Wifi.phy_mode : 4)); // 1-B/2-BG/3-BGN/4-BGNAX +#endif // ESP32 WiFi.setAutoReconnect(true); switch (flag) { case 0: // AP1