Add ESP32 setPhyMode in WiFi Init and force HT20

This commit is contained in:
Theo Arends 2026-01-07 14:47:54 +01:00
parent 5bffce9297
commit 5680069768
2 changed files with 25 additions and 10 deletions

View File

@ -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

View File

@ -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