From 78df0e4163af6868f759ff059d8df9c0c551c336 Mon Sep 17 00:00:00 2001 From: Juli Date: Thu, 17 Sep 2026 19:50:57 +0200 Subject: [PATCH] Keep the Wi-Fi setup portal open when opened on purpose Choosing Wi-Fi setup (or holding BOOT) while already connected used to fall straight through: run_portal waited for a connection, which the existing Wi-Fi satisfied at once. A forced portal now stays open until new credentials are saved (which restarts the device); the no-connection fallback still proceeds on auto-reconnect. --- main/main.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/main/main.c b/main/main.c index 6dd4eb8..182c1d5 100644 --- a/main/main.c +++ b/main/main.c @@ -17,13 +17,20 @@ static const char *TAG = "main"; -static void run_portal(void) +static void run_portal(bool forced) { net_start_portal(); leds_set_mode(LED_BREATHE, 0x8030ff); ui_status("Wi-Fi setup", "Join the Wi-Fi network\n\"" CONFIG_WIDGET_AP_SSID "\" with your phone.\n" "The setup page opens by itself\n(or browse to http://192.168.4.1)"); + // When the user asked for setup we stay here until they save new credentials + // (which restarts the device). Otherwise the existing Wi-Fi would satisfy the + // wait immediately and we'd fall through to the streams. On a plain fallback + // (no/failed connection) we let an auto-reconnect carry us onward. + if (forced) { + while (1) vTaskDelay(pdMS_TO_TICKS(1000)); + } net_wait_connected(-1); } @@ -55,10 +62,10 @@ void app_main(void) input_init(); if (force_setup || !net_has_credentials()) { - run_portal(); + run_portal(force_setup); } else { ui_status("insecam widget", "connecting to Wi-Fi"); - if (!net_wait_connected(20000)) run_portal(); + if (!net_wait_connected(20000)) run_portal(false); } ESP_LOGI(TAG, "online at %s", net_ip_str()); ui_status("insecam widget", "online - finding cameras\n\nturn: next / previous\nclick: pause\nhold: menu");