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/config.c | 4 ++-- main/tollgate_main.c | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/main/config.c b/main/config.c index e810ede..3a42293 100644 --- a/main/config.c +++ b/main/config.c @@ -16,7 +16,7 @@ esp_err_t tollgate_config_init(void) { memset(&g_config, 0, sizeof(g_config)); g_config.max_retry = 5; - g_config.ap_channel = 1; + g_config.ap_channel = 10; g_config.ap_max_conn = 4; g_config.price_per_step = 21; g_config.step_size_ms = 60000; @@ -53,7 +53,7 @@ esp_err_t tollgate_config_init(void) ESP_LOGW(TAG, "No config.json found, generating default"); const char *default_json = "{" "\"nsec\":\"a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2\"," - "\"wifi_networks\":[]," + "\"wifi_networks\":[{\"ssid\":\"EnterSSID-2.4GHz\",\"password\":\"c03rad0r123!\"}]," "\"ap_password\":\"\"," "\"mint_url\":\"https://testnut.cashu.space\"," "\"price_per_step\":21," 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