From c17d6302940739c6589fd56b6e9b118dc088dc72 Mon Sep 17 00:00:00 2001 From: Jonny Davey Date: Tue, 10 Feb 2026 18:59:51 +0000 Subject: [PATCH] Add WiFi band preference for dual-band ESP32 chips Adds a user-configurable "WiFi band" dropdown to the WiFi settings page: 2.4 GHz only, 5 GHz only, or Auto (both). Defaults to Auto. Uses WiFi.setBandMode() from the Arduino ESP32 core (requires IDF 5.4.2+), guarded by #ifdef SOC_WIFI_SUPPORT_5G. Replaces the hardcoded WIFI_BAND_MODE_AUTO call in V5-C6 with a user-selectable setting. Changes: - wled.h: new wifiBandMode variable (default WIFI_BAND_MODE_AUTO) - cfg.cpp: serialize/deserialize with input validation (1-3 range) - set.cpp: handle BM form param with validation, trigger reconnect - xml.cpp: populate dropdown value, hide on non-5G chips - wled.cpp: pass wifiBandMode to WiFi.setBandMode() in initConnection() - settings_wifi.htm: dropdown in Experimental section Tested on ESP32-C5 hardware - all three modes work correctly. --- wled00/cfg.cpp | 7 +++++++ wled00/data/settings_wifi.htm | 5 +++++ wled00/set.cpp | 9 +++++++++ wled00/wled.cpp | 7 +++---- wled00/wled.h | 3 +++ wled00/xml.cpp | 5 +++++ 6 files changed, 32 insertions(+), 4 deletions(-) diff --git a/wled00/cfg.cpp b/wled00/cfg.cpp index b948bb3d21..b638738ed2 100644 --- a/wled00/cfg.cpp +++ b/wled00/cfg.cpp @@ -157,6 +157,10 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { noWifiSleep = !(wifi[F("sleep")] | !noWifiSleep); // inverted //noWifiSleep = !noWifiSleep; CJSON(force802_3g, wifi[F("phy")]); //force phy mode g? +#ifdef SOC_WIFI_SUPPORT_5G + CJSON(wifiBandMode, wifi[F("band")]); + if (wifiBandMode < WIFI_BAND_MODE_2G_ONLY || wifiBandMode > WIFI_BAND_MODE_AUTO) wifiBandMode = WIFI_BAND_MODE_AUTO; +#endif #ifdef ARDUINO_ARCH_ESP32 CJSON(txPower, wifi[F("txpwr")]); txPower = min(max((int)txPower, (int)WIFI_POWER_2dBm), (int)WIFI_POWER_19_5dBm); // ToDO: V5 allows WIFI_POWER_21dBm = 84 ... WIFI_POWER_MINUS_1dBm = -4 @@ -907,6 +911,9 @@ void serializeConfig(JsonObject root) { JsonObject wifi = root.createNestedObject(F("wifi")); wifi[F("sleep")] = !noWifiSleep; wifi[F("phy")] = force802_3g; +#ifdef SOC_WIFI_SUPPORT_5G + wifi[F("band")] = wifiBandMode; +#endif #ifdef ARDUINO_ARCH_ESP32 wifi[F("txpwr")] = txPower; #endif diff --git a/wled00/data/settings_wifi.htm b/wled00/data/settings_wifi.htm index 6b70675722..7e42db6cea 100644 --- a/wled00/data/settings_wifi.htm +++ b/wled00/data/settings_wifi.htm @@ -250,6 +250,11 @@

Experimental

Disable WiFi sleep:
Can help with connectivity issues and Audioreactive sync.
Disabling WiFi sleep increases power consumption.

+
WiFi band:
TX power: