From 33a12f9a2573a28d3fe4dd6616610c8d0581e846 Mon Sep 17 00:00:00 2001 From: Damian Schneider Date: Sun, 1 Feb 2026 22:02:35 +0100 Subject: [PATCH 1/6] fix bootup output glitch by using NVM stored credentials --- wled00/wled.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/wled00/wled.cpp b/wled00/wled.cpp index 5b7e1f1345..0061c8eb62 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -503,7 +503,7 @@ void WLED::setup() if (strcmp(multiWiFi[0].clientSSID, DEFAULT_CLIENT_SSID) == 0 && !configBackupExists()) showWelcomePage = true; - WiFi.persistent(false); + WiFi.persistent(false); // note: this is only applied if WiFi.mode() is called and only if mode changes, use low level esp_wifi_set_storage() to change storage method immediately WiFi.onEvent(WiFiEvent); WiFi.mode(WIFI_STA); // enable scanning findWiFi(true); // start scanning for available WiFi-s @@ -666,6 +666,23 @@ void WLED::initAP(bool resetAP) void WLED::initConnection() { + static bool firstCall = true; + bool updateWiFiNVM = false; + if (firstCall) { + // check cached WiFi config in flash, esp_wifi_get_config still contains NVM values at this point + // note: connecting to the NVM stored wifi is much faster and prevents boot-up glitches on LEDs + wifi_config_t cachedConfig; + esp_err_t configResult = esp_wifi_get_config( (wifi_interface_t)ESP_IF_WIFI_STA, &cachedConfig ); + if( configResult == ESP_OK ) { + if (strncmp((const char*)cachedConfig.ap.ssid, multiWiFi[0].clientSSID, 32) != 0 || + strncmp((const char*)cachedConfig.ap.password, multiWiFi[0].clientPass, 64) != 0) { + updateWiFiNVM = true; // SSID or pass changed, update NVM at next WiFi.begin() call + DEBUG_PRINTLN(F("WiFi config NVM update triggered")); + } + } + firstCall = false; + } + DEBUG_PRINTF_P(PSTR("initConnection() called @ %lus.\n"), millis()/1000); #ifdef WLED_ENABLE_WEBSOCKETS ws.onEvent(wsEvent); @@ -716,6 +733,10 @@ void WLED::initConnection() char hostname[25]; prepareHostname(hostname); + // NVM only can store one wifi so store credentials of first WiFi even if multiple are configured + if(updateWiFiNVM && selectedWiFi == 0) + esp_wifi_set_storage(WIFI_STORAGE_FLASH); // temporary override WiFi.persistent(false) to store credentials in flash + #ifdef WLED_ENABLE_WPA_ENTERPRISE if (multiWiFi[selectedWiFi].encryptionType == WIFI_ENCRYPTION_TYPE_PSK) { DEBUG_PRINTLN(F("Using PSK")); @@ -758,6 +779,7 @@ void WLED::initConnection() WiFi.hostname(hostname); #endif } + esp_wifi_set_storage(WIFI_STORAGE_RAM); // do not update credentials while running to prevent wear on flash #ifndef WLED_DISABLE_ESPNOW if (enableESPNow) { From 00da21f8f7f762416603f76caa8b6b80c98f4715 Mon Sep 17 00:00:00 2001 From: Damian Schneider Date: Sun, 1 Feb 2026 22:24:56 +0100 Subject: [PATCH 2/6] fix race condition --- wled00/wled.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wled00/wled.cpp b/wled00/wled.cpp index 0061c8eb62..d2963895e6 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -682,6 +682,8 @@ void WLED::initConnection() } firstCall = false; } + else + esp_wifi_set_storage(WIFI_STORAGE_RAM); // do keep update credentials while running to prevent wear on flash DEBUG_PRINTF_P(PSTR("initConnection() called @ %lus.\n"), millis()/1000); #ifdef WLED_ENABLE_WEBSOCKETS @@ -779,8 +781,6 @@ void WLED::initConnection() WiFi.hostname(hostname); #endif } - esp_wifi_set_storage(WIFI_STORAGE_RAM); // do not update credentials while running to prevent wear on flash - #ifndef WLED_DISABLE_ESPNOW if (enableESPNow) { quickEspNow.onDataSent(espNowSentCB); // see udp.cpp From c092c6f559e17f4d01c86d1004515190632bb591 Mon Sep 17 00:00:00 2001 From: Damian Schneider Date: Sun, 1 Feb 2026 22:26:47 +0100 Subject: [PATCH 3/6] fix typo --- wled00/wled.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wled00/wled.cpp b/wled00/wled.cpp index d2963895e6..b275d77868 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -683,7 +683,7 @@ void WLED::initConnection() firstCall = false; } else - esp_wifi_set_storage(WIFI_STORAGE_RAM); // do keep update credentials while running to prevent wear on flash + esp_wifi_set_storage(WIFI_STORAGE_RAM); // do not update NVM credentials while running to prevent wear on flash DEBUG_PRINTF_P(PSTR("initConnection() called @ %lus.\n"), millis()/1000); #ifdef WLED_ENABLE_WEBSOCKETS From cea77f9fda60d96335a72f3383ab5cc24f9e8be7 Mon Sep 17 00:00:00 2001 From: Damian Schneider Date: Mon, 2 Feb 2026 07:47:11 +0100 Subject: [PATCH 4/6] add ifdef guards for ESP8266 --- wled00/wled.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/wled00/wled.cpp b/wled00/wled.cpp index b275d77868..d28cd47ad3 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -503,7 +503,7 @@ void WLED::setup() if (strcmp(multiWiFi[0].clientSSID, DEFAULT_CLIENT_SSID) == 0 && !configBackupExists()) showWelcomePage = true; - WiFi.persistent(false); // note: this is only applied if WiFi.mode() is called and only if mode changes, use low level esp_wifi_set_storage() to change storage method immediately + WiFi.persistent(false); // note: on ESP32 this is only applied if WiFi.mode() is called and only if mode changes, use low level esp_wifi_set_storage() to change storage method immediately WiFi.onEvent(WiFiEvent); WiFi.mode(WIFI_STA); // enable scanning findWiFi(true); // start scanning for available WiFi-s @@ -666,11 +666,12 @@ void WLED::initAP(bool resetAP) void WLED::initConnection() { + #ifdef ARDUINO_ARCH_ESP32 static bool firstCall = true; bool updateWiFiNVM = false; if (firstCall) { // check cached WiFi config in flash, esp_wifi_get_config still contains NVM values at this point - // note: connecting to the NVM stored wifi is much faster and prevents boot-up glitches on LEDs + // note: connecting to the NVM stored wifi is much faster and prevents boot-up glitches on LEDs (there is no benefit on ESP8266) wifi_config_t cachedConfig; esp_err_t configResult = esp_wifi_get_config( (wifi_interface_t)ESP_IF_WIFI_STA, &cachedConfig ); if( configResult == ESP_OK ) { @@ -684,6 +685,7 @@ void WLED::initConnection() } else esp_wifi_set_storage(WIFI_STORAGE_RAM); // do not update NVM credentials while running to prevent wear on flash + #endif DEBUG_PRINTF_P(PSTR("initConnection() called @ %lus.\n"), millis()/1000); #ifdef WLED_ENABLE_WEBSOCKETS @@ -735,9 +737,10 @@ void WLED::initConnection() char hostname[25]; prepareHostname(hostname); - // NVM only can store one wifi so store credentials of first WiFi even if multiple are configured - if(updateWiFiNVM && selectedWiFi == 0) - esp_wifi_set_storage(WIFI_STORAGE_FLASH); // temporary override WiFi.persistent(false) to store credentials in flash + #ifdef ARDUINO_ARCH_ESP32 + if(updateWiFiNVM && selectedWiFi == 0) // NVM only can store one wifi: store credentials of first WiFi even if multiple are configured + esp_wifi_set_storage(WIFI_STORAGE_FLASH); // temporary override WiFi.persistent(false) to store credentials in flash (is reset to RAM on next initConnection() call) + #endif #ifdef WLED_ENABLE_WPA_ENTERPRISE if (multiWiFi[selectedWiFi].encryptionType == WIFI_ENCRYPTION_TYPE_PSK) { From 386b7034f92e091b7765be1442b81438c382578c Mon Sep 17 00:00:00 2001 From: Damian Schneider Date: Mon, 2 Feb 2026 07:54:32 +0100 Subject: [PATCH 5/6] revert whitespace change --- wled00/wled.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/wled00/wled.cpp b/wled00/wled.cpp index d28cd47ad3..e2e1fc86e0 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -784,6 +784,7 @@ void WLED::initConnection() WiFi.hostname(hostname); #endif } + #ifndef WLED_DISABLE_ESPNOW if (enableESPNow) { quickEspNow.onDataSent(espNowSentCB); // see udp.cpp From 2cbc7c692b0207a2ea9633375eb5241265c239b4 Mon Sep 17 00:00:00 2001 From: Damian Schneider Date: Mon, 2 Feb 2026 08:07:05 +0100 Subject: [PATCH 6/6] clear intention on union access --- wled00/wled.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wled00/wled.cpp b/wled00/wled.cpp index e2e1fc86e0..496f9e096a 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -675,8 +675,8 @@ void WLED::initConnection() wifi_config_t cachedConfig; esp_err_t configResult = esp_wifi_get_config( (wifi_interface_t)ESP_IF_WIFI_STA, &cachedConfig ); if( configResult == ESP_OK ) { - if (strncmp((const char*)cachedConfig.ap.ssid, multiWiFi[0].clientSSID, 32) != 0 || - strncmp((const char*)cachedConfig.ap.password, multiWiFi[0].clientPass, 64) != 0) { + if (strncmp((const char*)cachedConfig.sta.ssid, multiWiFi[0].clientSSID, 32) != 0 || + strncmp((const char*)cachedConfig.sta.password, multiWiFi[0].clientPass, 64) != 0) { updateWiFiNVM = true; // SSID or pass changed, update NVM at next WiFi.begin() call DEBUG_PRINTLN(F("WiFi config NVM update triggered")); }