Skip to content

Commit 8318be7

Browse files
author
Ravi Singh
committed
fix(netmgr): mirror sta_configured in memory when credentials change
s_net.sta_configured was computed once at boot from NVS, then never updated when netmgr_set_credentials() persisted new creds. The result: on first-time onboarding (fresh-NVS device), the in-memory flag stayed false even after the user saved creds + STA successfully connected. ap_should_be_on() checks sta_configured first and unconditionally returns true if false — which meant the IP_EVENT_STA_GOT_IP handler saw "AP should still be on" even after STA was up, never armed the AP teardown timer, and the AP stayed broadcasting forever. Symptom (from bench): user onboards via captive portal, success modal shows the IP, device is reachable on home Wi-Fi, but AmbiSense-XXXX remains visible in the phone's Wi-Fi list indefinitely. Reboots after the first onboarding worked correctly because the init path re-reads NVS and computes sta_configured = true. Fix: set s_net.sta_configured = true alongside settings_set_wifi_ssid() in the success path, and = false alongside the clear path. Reproduced on a freshly-erased ESP32-C3 (MAC d8:3b:da:35:06:f0) running v6.1.0-alpha.2; verified fixed on the same hardware.
1 parent 3c4b336 commit 8318be7

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

firmware/components/netmgr/netmgr.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,13 +476,23 @@ esp_err_t netmgr_set_credentials(const char *ssid, const char *pass) {
476476
if (!ssid || !ssid[0]) {
477477
settings_set_wifi_ssid("");
478478
settings_set_wifi_pass("");
479+
/* CRITICAL: clear in-memory flag too, otherwise ap_should_be_on()
480+
* still thinks we're configured and keeps the AP up incorrectly. */
481+
s_net.sta_configured = false;
479482
esp_wifi_disconnect();
480483
notify_state(NETMGR_STATE_AP_FALLBACK);
481484
ESP_LOGI(TAG, "Cleared STA creds; AP remains up");
482485
return ESP_OK;
483486
}
484487
settings_set_wifi_ssid(ssid);
485488
settings_set_wifi_pass(pass ? pass : "");
489+
/* CRITICAL: mark STA configured BEFORE the connection attempt. The
490+
* IP_EVENT_STA_GOT_IP handler reads ap_should_be_on() which depends
491+
* on this flag — without setting it here, fresh-NVS onboarding
492+
* leaves the AP up forever even after STA succeeds, because
493+
* ap_should_be_on() returns true unconditionally when no STA is
494+
* configured. (Reproduced 2026-05-07 on a freshly-erased C3.) */
495+
s_net.sta_configured = true;
486496

487497
/* AP keeps running throughout. Just retarget STA. */
488498
esp_wifi_disconnect();

0 commit comments

Comments
 (0)