From fe7c3be2fd9d464dbc837d1913409d2691bd50f5 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 18 May 2026 01:46:49 +0530 Subject: fix: move MAC set after wifi_set_mode, start services without STA - esp_wifi_set_mac requires WIFI_MODE_APSTA set first (fixes Board B crash) - Start services immediately when no STA network is configured (standalone TollGate without upstream WiFi) --- main/tollgate_main.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/main/tollgate_main.c b/main/tollgate_main.c index 41dbbed..1350d70 100644 --- a/main/tollgate_main.c +++ b/main/tollgate_main.c @@ -265,11 +265,6 @@ void app_main(void) wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); ESP_ERROR_CHECK(esp_wifi_init(&cfg)); - const tollgate_config_t *tcfg = tollgate_config_get(); - ESP_ERROR_CHECK(esp_wifi_set_mac(WIFI_IF_STA, tcfg->sta_mac)); - ESP_ERROR_CHECK(esp_wifi_set_mac(WIFI_IF_AP, tcfg->ap_mac)); - ESP_LOGI(TAG, "MACs set from identity"); - ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler, NULL, NULL)); ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT, IP_EVENT_STA_GOT_IP, @@ -279,6 +274,11 @@ void app_main(void) ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_APSTA)); + const tollgate_config_t *tcfg = tollgate_config_get(); + ESP_ERROR_CHECK(esp_wifi_set_mac(WIFI_IF_STA, tcfg->sta_mac)); + ESP_ERROR_CHECK(esp_wifi_set_mac(WIFI_IF_AP, tcfg->ap_mac)); + ESP_LOGI(TAG, "MACs set from identity"); + wifi_configure_ap(); wifi_config_t sta_config; @@ -292,6 +292,11 @@ void app_main(void) ESP_LOGI(TAG, "WiFi AP+STA started, waiting for connection..."); + 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); + } + while (1) { vTaskDelay(pdMS_TO_TICKS(1000)); session_tick(); -- cgit v1.2.3