fix(provisioning): fast-fail wifi on bad PSK / missing SSID

Match the failure path's latency to the happy path. Before: a wrong
password meant the user stared at the yellow Step 1/2 screen for the
full 30 s WIFI_TIMEOUT_MS before the red retry repaint started — total
~50 s to "Connection Failed" visible. After: WL_CONNECT_FAILED and
WL_NO_SSID_AVAIL bail attempt_wifi() immediately, so the red repaint
starts within a few seconds of the radio giving up — total ~25 s,
matching the happy-path-to-Step-2/2 timing.

Also collapse the duplicate boot-time poll loop in main.cpp onto the
shared attempt_wifi() so the same fast-fail covers boot-with-stored-
creds, not just captive-portal submission.

Tests: FW-15a (auth fail) and FW-15b (no SSID) assert millis() never
reaches WIFI_TIMEOUT_MS on those statuses. Existing FW-15 tightened
to use WL_DISCONNECTED so it actually exercises the timeout path.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-09 10:31:41 -04:00
parent 6a924963e5
commit 05e869d190
4 changed files with 41 additions and 15 deletions
+8 -2
View File
@@ -80,11 +80,17 @@ inline bool attempt_wifi(const char* ssid, const char* pass) {
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, pass);
uint32_t start = millis();
while (WiFi.status() != WL_CONNECTED) {
while (true) {
int s = WiFi.status();
if (s == WL_CONNECTED) return true;
// Bail the moment the radio reports a terminal failure — bad PSK
// surfaces as WL_CONNECT_FAILED and missing SSID as WL_NO_SSID_AVAIL
// within a few seconds. Without this the user stares at the yellow
// Step 1/2 for the full WIFI_TIMEOUT_MS before the red retry repaints.
if (s == WL_CONNECT_FAILED || s == WL_NO_SSID_AVAIL) return false;
if (millis() - start > WIFI_TIMEOUT_MS) return false;
delay(200);
}
return true;
}
// ── Reset button hold detection ───────────────────────────────────────────────