fix(wifi): skip SDK-cached credentials when SSID is already configured (closes #3)
WiFi.begin() without params connects to any SDK-cached network, including open public hotspots, and then overwrites config.ssid with the wrong SSID. Now Try 1 (SDK credentials) is only attempted on first boot when no SSID is configured. Once the user has saved credentials, we go straight to Try 2 (EEPROM config), so the correct network is always used. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
이 커밋은 다음에 포함됨:
co-authored by
Claude Sonnet 4.6
부모
c606bcc589
커밋
09b8680408
@@ -67,8 +67,12 @@ void ICACHE_FLASH_ATTR setupWiFi() {
|
||||
WiFi.hostname(config.hostname);
|
||||
WiFi.mode(WIFI_STA);
|
||||
|
||||
// Try 1: Use WiFi.begin() without params - uses SDK stored credentials
|
||||
Serial.println("Trying SDK-stored credentials...");
|
||||
// Try 1: Use WiFi.begin() without params - only when no SSID is configured.
|
||||
// Skipped if user has a saved SSID: SDK-cached credentials may include open
|
||||
// networks (e.g. public hotspots) that would be preferred over the user's
|
||||
// network, and a successful connect would overwrite config.ssid (issue #3).
|
||||
if (strlen(config.ssid) == 0) {
|
||||
Serial.println("No SSID configured, trying SDK-stored credentials...");
|
||||
WiFi.begin();
|
||||
|
||||
// SYNCHRONOUS wait for connection (max 10 seconds)
|
||||
@@ -99,13 +103,14 @@ void ICACHE_FLASH_ATTR setupWiFi() {
|
||||
wifiConnState = WIFI_CONN_CONNECTED;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Try 2: If we have EEPROM credentials, try those
|
||||
if (strlen(config.ssid) > 0 && strlen(config.password) > 0) {
|
||||
Serial.println("\nTrying EEPROM credentials...");
|
||||
WiFi.begin(config.ssid, config.password);
|
||||
|
||||
attempts = 0;
|
||||
int attempts = 0;
|
||||
while (WiFi.status() != WL_CONNECTED && attempts < 20) {
|
||||
showWiFiConnecting(attempts);
|
||||
delay(500);
|
||||
|
||||
+10
-9
@@ -761,9 +761,13 @@ void ICACHE_FLASH_ATTR setupWiFi() {
|
||||
// STRATEGY: First try SDK-stored credentials (from WiFiManager), then EEPROM config
|
||||
// WiFiManager stores credentials in ESP flash separately from our EEPROM
|
||||
|
||||
// Try 1: Use WiFi.begin() without params - uses SDK stored credentials
|
||||
Serial.println("Trying SDK-stored credentials...");
|
||||
WiFi.begin(); // Uses credentials stored by WiFiManager/SDK
|
||||
// Try 1: Use WiFi.begin() without params - only when no SSID is configured.
|
||||
// Skipped if user has a saved SSID: SDK-cached credentials may include open
|
||||
// networks (e.g. public hotspots) that would be preferred over the user's
|
||||
// network, and a successful connect would overwrite config.ssid (issue #3).
|
||||
if (strlen(config.ssid) == 0) {
|
||||
Serial.println("No SSID configured, trying SDK-stored credentials...");
|
||||
WiFi.begin();
|
||||
|
||||
// SYNCHRONOUS wait for connection (max 10 seconds)
|
||||
Serial.print("Connecting to WiFi");
|
||||
@@ -786,16 +790,13 @@ void ICACHE_FLASH_ATTR setupWiFi() {
|
||||
Serial.print("DNS: ");
|
||||
Serial.println(WiFi.dnsIP());
|
||||
|
||||
// Sync connected SSID to our config
|
||||
safeStringCopy(WiFi.SSID(), config.ssid, sizeof(config.ssid));
|
||||
// Note: password stays in SDK storage, we don't have access to it
|
||||
saveConfig();
|
||||
|
||||
// Show IP on display
|
||||
showIP();
|
||||
|
||||
wifiConnState = WIFI_CONN_CONNECTED;
|
||||
return; // Success!
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Try 2: If we have EEPROM credentials, try those
|
||||
@@ -803,7 +804,7 @@ void ICACHE_FLASH_ATTR setupWiFi() {
|
||||
Serial.println("\nTrying EEPROM credentials...");
|
||||
WiFi.begin(config.ssid, config.password);
|
||||
|
||||
attempts = 0;
|
||||
int attempts = 0;
|
||||
while (WiFi.status() != WL_CONNECTED && attempts < 20) {
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
|
||||
새 이슈에서 참조
사용자 차단