fix(wifi): persist password alongside SSID after SDK/WiFiManager connect (v1.9.10)

After a successful connect via SDK-cached credentials (Try 1) or the
WiFiManager captive portal, only the SSID was saved to EEPROM. On the next
boot config.password was empty, so setupWiFi() and the reconnect loop called
WiFi.begin(ssid) as if the network were open and failed with
WL_WRONG_PASSWORD.

v1.9.6 masked this: with an empty password the retry loop fell back to a
bare WiFi.begin(), which reuses the SDK-stored credentials. Commit 02834ba
(v1.9.7) replaced that fallback with WiFi.begin(config.ssid), and v1.9.9
(M2) added the same call to setupWiFi(), so every version after 1.9.6
never reconnects after a reboot when the device was set up through the
portal.

Read the password back with WiFi.psk() and store it next to the SSID in
all three places that sync the SSID. Devices already in this state recover
by entering the password once in the web UI (fallback AP after ~2.5 min).

Verified: builds with PlatformIO (espressif8266 core 3.1.2, esp01_1m).

Fixes #12

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Alex Petrochenko
2026-09-20 15:40:46 +01:00
co-authored by Claude Fable 5.1
parent 75b6a21f3c
commit aee1d3e0ef
4 changed files with 27 additions and 4 deletions
+1 -1
View File
@@ -9,7 +9,7 @@
#include <Arduino.h>
// Firmware version
#define FIRMWARE_VERSION "1.9.9"
#define FIRMWARE_VERSION "1.9.10"
// OLED I2C Configuration
#define I2C_SDA 0 // GPIO0 (I2C Data) - SWAPPED!
+10 -1
View File
@@ -28,9 +28,10 @@ void ICACHE_FLASH_ATTR processWiFiConnection() {
WiFi.mode(WIFI_STA);
}
// Sync connected SSID to config
// Sync connected SSID + password to config
if (strlen(config.ssid) == 0) {
safeStringCopy(WiFi.SSID(), config.ssid, sizeof(config.ssid));
safeStringCopy(WiFi.psk(), config.password, sizeof(config.password));
saveConfig();
}
@@ -96,7 +97,12 @@ void ICACHE_FLASH_ATTR setupWiFi() {
Serial.print("DNS: ");
Serial.println(WiFi.dnsIP());
// Persist the password too, not just the SSID. The SDK keeps the
// password in its own flash area, but every later boot reads
// config.password: an empty one is treated as an open network
// (WiFi.begin(ssid)) and fails with WL_WRONG_PASSWORD (issue #12).
safeStringCopy(WiFi.SSID(), config.ssid, sizeof(config.ssid));
safeStringCopy(WiFi.psk(), config.password, sizeof(config.password));
saveConfig();
showIP();
@@ -166,7 +172,10 @@ void ICACHE_FLASH_ATTR setupWiFi() {
Serial.print("IP: ");
Serial.println(WiFi.localIP());
// Save both SSID and password (issue #12): WiFiManager stores them in the
// SDK flash, but the next boot connects from config.* only.
safeStringCopy(WiFi.SSID(), config.ssid, sizeof(config.ssid));
safeStringCopy(WiFi.psk(), config.password, sizeof(config.password));
saveConfig();
showIP();