From 7c36029ec20d23690222a27fc45d4707148a426c Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Wed, 3 Apr 2024 14:36:52 +0200 Subject: [PATCH] Add command ``Wifi 5`` to enable 11ax on ESP32 Core3 --- CHANGELOG.md | 1 + RELEASENOTES.md | 1 + .../ESP32-to-ESP8266-compat/src/ESP32Wifi.cpp | 9 ++++++--- .../ESP32-to-ESP8266-compat/src/ESP8266WiFi.h | 3 +++ tasmota/tasmota_support/support_command.ino | 18 ++++++++++++++---- tasmota/tasmota_support/support_wifi.ino | 2 +- 6 files changed, 26 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 220093420..018e3233b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file. ## [13.4.0.4] ### Added - Command ``PowerLock`` to disable power control of selected outputs (#21081) +- Command ``Wifi 5`` to enable 11ax on ESP32 Core3 ### Breaking Changed diff --git a/RELEASENOTES.md b/RELEASENOTES.md index d37e6936d..e86e13264 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -118,6 +118,7 @@ The latter links can be used for OTA upgrades too like ``OtaUrl https://ota.tasm ## Changelog v13.4.0.4 ### Added +- Command ``Wifi 5`` to enable 11ax on ESP32 Core3 - Command ``PowerLock`` to disable power control of selected outputs [#21081](https://github.com/arendst/Tasmota/issues/21081) - Support for calculated heat index if temperature and humidity is available with ``#define USE_HEAT_INDEX`` [#4771](https://github.com/arendst/Tasmota/issues/4771) - Support for LoRa and single channel EU863-870 LoRaWanBridge [#17790](https://github.com/arendst/Tasmota/issues/17790) diff --git a/lib/libesp32/ESP32-to-ESP8266-compat/src/ESP32Wifi.cpp b/lib/libesp32/ESP32-to-ESP8266-compat/src/ESP32Wifi.cpp index 40b85d692..6bdfc4587 100644 --- a/lib/libesp32/ESP32-to-ESP8266-compat/src/ESP32Wifi.cpp +++ b/lib/libesp32/ESP32-to-ESP8266-compat/src/ESP32Wifi.cpp @@ -147,10 +147,13 @@ int WiFiClass32::getPhyMode() { } bool WiFiClass32::setPhyMode(WiFiPhyMode_t mode) { - uint8_t protocol_bitmap = WIFI_PROTOCOL_11B; // 1 + uint8_t protocol_bitmap = WIFI_PROTOCOL_11B; // 1 switch (mode) { - case 3: protocol_bitmap |= WIFI_PROTOCOL_11N; // 4 - case 2: protocol_bitmap |= WIFI_PROTOCOL_11G; // 2 +#if ESP_IDF_VERSION_MAJOR >= 5 + case 4: protocol_bitmap |= WIFI_PROTOCOL_11AX; // 16 +#endif + case 3: protocol_bitmap |= WIFI_PROTOCOL_11N; // 4 + case 2: protocol_bitmap |= WIFI_PROTOCOL_11G; // 2 } return (ESP_OK == esp_wifi_set_protocol(WIFI_IF_STA, protocol_bitmap)); } diff --git a/lib/libesp32/ESP32-to-ESP8266-compat/src/ESP8266WiFi.h b/lib/libesp32/ESP32-to-ESP8266-compat/src/ESP8266WiFi.h index 94cf3d6c1..881caff0c 100644 --- a/lib/libesp32/ESP32-to-ESP8266-compat/src/ESP8266WiFi.h +++ b/lib/libesp32/ESP32-to-ESP8266-compat/src/ESP8266WiFi.h @@ -33,6 +33,9 @@ typedef enum WiFiPhyMode { TAS_WIFI_PHY_MODE_LR = 0, TAS_WIFI_PHY_MODE_11B = 1, TAS_WIFI_PHY_MODE_11G = 2, TAS_WIFI_PHY_MODE_11N = 3 +#if ESP_IDF_VERSION_MAJOR >= 5 + , TAS_WIFI_PHY_MODE_11AX = 4 +#endif } WiFiPhyMode_t; /* diff --git a/tasmota/tasmota_support/support_command.ino b/tasmota/tasmota_support/support_command.ino index ec483b167..3b4e65422 100644 --- a/tasmota/tasmota_support/support_command.ino +++ b/tasmota/tasmota_support/support_command.ino @@ -2686,8 +2686,7 @@ void CmndWifiPower(void) { ResponseCmndFloat(WifiGetOutputPower(), 1); } -void CmndWifi(void) -{ +void CmndWifi(void) { if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1)) { Settings->flag4.network_wifi = XdrvMailbox.payload; if (Settings->flag4.network_wifi) { @@ -2697,14 +2696,25 @@ void CmndWifi(void) WifiEnable(); #endif } - } else if ((XdrvMailbox.payload >= 2) && (XdrvMailbox.payload <= 4)) { + } else if ((XdrvMailbox.payload >= 2) && +#ifdef ESP32 +#if ESP_IDF_VERSION_MAJOR >= 5 + (XdrvMailbox.payload <= 5) +#else // ESP_IDF_VERSION_MAJOR < 5 + (XdrvMailbox.payload <= 4) +#endif // ESP_IDF_VERSION_MAJOR +#else // ESP8266 + (XdrvMailbox.payload <= 4) +#endif // ESP32/ESP8266 + ) { // Wifi 2 = B // Wifi 3 = BG // Wifi 4 = BGN + // Wifi 5 = BGNAX #ifdef ESP32 Wifi.phy_mode = XdrvMailbox.payload - 1; #endif - WiFi.setPhyMode(WiFiPhyMode_t(XdrvMailbox.payload - 1)); // 1-B/2-BG/3-BGN + WiFi.setPhyMode(WiFiPhyMode_t(XdrvMailbox.payload - 1)); // 1-B/2-BG/3-BGN/4-BGNAX } Response_P(PSTR("{\"" D_JSON_WIFI "\":\"%s\",\"" D_JSON_WIFI_MODE "\":\"%s\"}"), GetStateText(Settings->flag4.network_wifi), WifiGetPhyMode().c_str()); diff --git a/tasmota/tasmota_support/support_wifi.ino b/tasmota/tasmota_support/support_wifi.ino index 881ac81f2..546986653 100644 --- a/tasmota/tasmota_support/support_wifi.ino +++ b/tasmota/tasmota_support/support_wifi.ino @@ -228,7 +228,7 @@ void WifiBegin(uint8_t flag, uint8_t channel) { // if (WiFi.getPhyMode() != WIFI_PHY_MODE_11G) { WiFi.setPhyMode(WIFI_PHY_MODE_11G); } // B/G #ifdef ESP32 if (Wifi.phy_mode) { - WiFi.setPhyMode(WiFiPhyMode_t(Wifi.phy_mode)); // 1-B/2-BG/3-BGN + WiFi.setPhyMode(WiFiPhyMode_t(Wifi.phy_mode)); // 1-B/2-BG/3-BGN/4-BGNAX } #endif if (!WiFi.getAutoConnect()) { WiFi.setAutoConnect(true); }