From 49f3b4aebff089991a04da370b8e343f8bcfe7ca Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 19 May 2026 02:01:58 +0530 Subject: fix: start services without upstream WiFi + channel 10 + disconnect reason - Start services after 30s timeout if STA never connects (reason=211) - Set AP channel to 10 for APSTA overlap with upstream router - Add upstream WiFi credentials in default config - Log WiFi disconnect reason code for debugging - Previously: remove stop_services() on STA disconnect --- main/tollgate_main.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'main/tollgate_main.c') diff --git a/main/tollgate_main.c b/main/tollgate_main.c index dda4142..346e1c0 100644 --- a/main/tollgate_main.c +++ b/main/tollgate_main.c @@ -47,8 +47,9 @@ static void wifi_event_handler(void *arg, esp_event_base_t event_base, } esp_wifi_connect(); } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) { + wifi_event_sta_disconnected_t *disconn = (wifi_event_sta_disconnected_t *)event_data; s_retry_count++; - ESP_LOGW(TAG, "WiFi disconnected, retry %d/%d", s_retry_count, MAX_STA_RETRY); + ESP_LOGW(TAG, "WiFi disconnected, reason=%d, retry %d/%d", disconn->reason, s_retry_count, MAX_STA_RETRY); tollgate_client_on_sta_disconnected(); if (s_retry_count < MAX_STA_RETRY) { esp_wifi_connect(); @@ -285,6 +286,15 @@ void app_main(void) if (tollgate_config_get_wifi(&(wifi_config_t){0}) != ESP_OK) { ESP_LOGI(TAG, "No STA network configured, starting services immediately"); xTaskCreate(services_start_task, "svc_start", 32768, NULL, 5, NULL); + } else { + ESP_LOGI(TAG, "STA configured, waiting up to 30s for connection..."); + for (int i = 0; i < 30 && !s_services_running; i++) { + vTaskDelay(pdMS_TO_TICKS(1000)); + } + if (!s_services_running) { + ESP_LOGW(TAG, "STA not connected after 30s, starting services anyway"); + xTaskCreate(services_start_task, "svc_start", 32768, NULL, 5, NULL); + } } while (1) { -- cgit v1.2.3