diff options
| author | Your Name <you@example.com> | 2026-05-19 02:01:58 +0530 |
|---|---|---|
| committer | Your Name <you@example.com> | 2026-05-19 02:01:58 +0530 |
| commit | 49f3b4aebff089991a04da370b8e343f8bcfe7ca (patch) | |
| tree | 085508e8f04f516204bace19fd1736d0e6adda82 | |
| parent | 56f30ca866613c94e6a83bc1c21bee0eb38c5b39 (diff) | |
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
| -rw-r--r-- | main/config.c | 4 | ||||
| -rw-r--r-- | 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) | |||
| 16 | { | 16 | { |
| 17 | memset(&g_config, 0, sizeof(g_config)); | 17 | memset(&g_config, 0, sizeof(g_config)); |
| 18 | g_config.max_retry = 5; | 18 | g_config.max_retry = 5; |
| 19 | g_config.ap_channel = 1; | 19 | g_config.ap_channel = 10; |
| 20 | g_config.ap_max_conn = 4; | 20 | g_config.ap_max_conn = 4; |
| 21 | g_config.price_per_step = 21; | 21 | g_config.price_per_step = 21; |
| 22 | g_config.step_size_ms = 60000; | 22 | g_config.step_size_ms = 60000; |
| @@ -53,7 +53,7 @@ esp_err_t tollgate_config_init(void) | |||
| 53 | ESP_LOGW(TAG, "No config.json found, generating default"); | 53 | ESP_LOGW(TAG, "No config.json found, generating default"); |
| 54 | const char *default_json = "{" | 54 | const char *default_json = "{" |
| 55 | "\"nsec\":\"a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2\"," | 55 | "\"nsec\":\"a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2\"," |
| 56 | "\"wifi_networks\":[]," | 56 | "\"wifi_networks\":[{\"ssid\":\"EnterSSID-2.4GHz\",\"password\":\"c03rad0r123!\"}]," |
| 57 | "\"ap_password\":\"\"," | 57 | "\"ap_password\":\"\"," |
| 58 | "\"mint_url\":\"https://testnut.cashu.space\"," | 58 | "\"mint_url\":\"https://testnut.cashu.space\"," |
| 59 | "\"price_per_step\":21," | 59 | "\"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, | |||
| 47 | } | 47 | } |
| 48 | esp_wifi_connect(); | 48 | esp_wifi_connect(); |
| 49 | } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) { | 49 | } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) { |
| 50 | wifi_event_sta_disconnected_t *disconn = (wifi_event_sta_disconnected_t *)event_data; | ||
| 50 | s_retry_count++; | 51 | s_retry_count++; |
| 51 | ESP_LOGW(TAG, "WiFi disconnected, retry %d/%d", s_retry_count, MAX_STA_RETRY); | 52 | ESP_LOGW(TAG, "WiFi disconnected, reason=%d, retry %d/%d", disconn->reason, s_retry_count, MAX_STA_RETRY); |
| 52 | tollgate_client_on_sta_disconnected(); | 53 | tollgate_client_on_sta_disconnected(); |
| 53 | if (s_retry_count < MAX_STA_RETRY) { | 54 | if (s_retry_count < MAX_STA_RETRY) { |
| 54 | esp_wifi_connect(); | 55 | esp_wifi_connect(); |
| @@ -285,6 +286,15 @@ void app_main(void) | |||
| 285 | if (tollgate_config_get_wifi(&(wifi_config_t){0}) != ESP_OK) { | 286 | if (tollgate_config_get_wifi(&(wifi_config_t){0}) != ESP_OK) { |
| 286 | ESP_LOGI(TAG, "No STA network configured, starting services immediately"); | 287 | ESP_LOGI(TAG, "No STA network configured, starting services immediately"); |
| 287 | xTaskCreate(services_start_task, "svc_start", 32768, NULL, 5, NULL); | 288 | xTaskCreate(services_start_task, "svc_start", 32768, NULL, 5, NULL); |
| 289 | } else { | ||
| 290 | ESP_LOGI(TAG, "STA configured, waiting up to 30s for connection..."); | ||
| 291 | for (int i = 0; i < 30 && !s_services_running; i++) { | ||
| 292 | vTaskDelay(pdMS_TO_TICKS(1000)); | ||
| 293 | } | ||
| 294 | if (!s_services_running) { | ||
| 295 | ESP_LOGW(TAG, "STA not connected after 30s, starting services anyway"); | ||
| 296 | xTaskCreate(services_start_task, "svc_start", 32768, NULL, 5, NULL); | ||
| 297 | } | ||
| 288 | } | 298 | } |
| 289 | 299 | ||
| 290 | while (1) { | 300 | while (1) { |