upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/main/tollgate_main.c
diff options
context:
space:
mode:
authorYour Name <you@example.com>2026-05-20 01:02:20 +0530
committerYour Name <you@example.com>2026-05-20 01:02:20 +0530
commit59ea2f02c49a3c678ecae19f55d542b7442d6f7e (patch)
tree6c0b016fa2de6240e65f5bd351161baecb1638a9 /main/tollgate_main.c
parent565d6a715427ace0518f367acf3053d667479390 (diff)
test: fix Playwright Layer 2 tests - all 13 passingfeature/display-fix
- Fix SETUP_HTML innerHTML newline syntax error (single-quoted string can't span lines) - Fix route interception: use page.goto with http://tollgate.test/setup instead of page.setContent - Add **/setup route for serving mock HTML - Fix Layer 1 POST tests: handle ECONNRESET gracefully, accept any error message - Add Layer 1.5 redirect test (needs live board) - Add **/setup route to rescan test - Load page with waitUntil: networkidle
Diffstat (limited to 'main/tollgate_main.c')
-rw-r--r--main/tollgate_main.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/main/tollgate_main.c b/main/tollgate_main.c
index 9960ea5..ec6ffc8 100644
--- a/main/tollgate_main.c
+++ b/main/tollgate_main.c
@@ -37,11 +37,13 @@ static esp_netif_t *s_ap_netif = NULL;
37static int s_retry_count = 0; 37static int s_retry_count = 0;
38static int s_total_retries = 0; 38static int s_total_retries = 0;
39static bool s_services_running = false; 39static bool s_services_running = false;
40static bool s_start_in_error_state = false;
40static SemaphoreHandle_t s_services_mutex = NULL; 41static SemaphoreHandle_t s_services_mutex = NULL;
41static char s_ap_ip_str[16] = "10.0.0.1"; 42static char s_ap_ip_str[16] = "10.0.0.1";
42 43
43static void start_services(void); 44static void start_services(void);
44static void stop_services(void); 45static void stop_services(void);
46static void services_start_task(void *pvParameters);
45 47
46static void wifi_event_handler(void *arg, esp_event_base_t event_base, 48static void wifi_event_handler(void *arg, esp_event_base_t event_base,
47 int32_t event_id, void *event_data) 49 int32_t event_id, void *event_data)
@@ -60,11 +62,15 @@ static void wifi_event_handler(void *arg, esp_event_base_t event_base,
60 tollgate_client_on_sta_disconnected(); 62 tollgate_client_on_sta_disconnected();
61 display_notify_wifi_disconnected(); 63 display_notify_wifi_disconnected();
62 if (s_services_running) { 64 if (s_services_running) {
63 stop_services();
64 display_set_state(DISPLAY_ERROR); 65 display_set_state(DISPLAY_ERROR);
65 } 66 }
66 if (s_total_retries >= MAX_TOTAL_RETRIES) { 67 if (s_total_retries >= MAX_TOTAL_RETRIES) {
67 ESP_LOGW(TAG, "All WiFi retries exhausted"); 68 ESP_LOGW(TAG, "All WiFi retries exhausted");
69 if (!s_services_running) {
70 s_start_in_error_state = true;
71 ESP_LOGI(TAG, "Starting services for /setup access (no upstream)");
72 xTaskCreate(services_start_task, "svc_start", 32768, NULL, 5, NULL);
73 }
68 const tollgate_config_t *cfg = tollgate_config_get(); 74 const tollgate_config_t *cfg = tollgate_config_get();
69 char portal_url[128]; 75 char portal_url[128];
70 snprintf(portal_url, sizeof(portal_url), "http://%s/", cfg->ap_ip_str); 76 snprintf(portal_url, sizeof(portal_url), "http://%s/", cfg->ap_ip_str);
@@ -86,6 +92,11 @@ static void wifi_event_handler(void *arg, esp_event_base_t event_base,
86 esp_wifi_connect(); 92 esp_wifi_connect();
87 } else { 93 } else {
88 ESP_LOGW(TAG, "No more WiFi networks to try"); 94 ESP_LOGW(TAG, "No more WiFi networks to try");
95 if (!s_services_running) {
96 s_start_in_error_state = true;
97 ESP_LOGI(TAG, "Starting services for /setup access (no upstream)");
98 xTaskCreate(services_start_task, "svc_start", 32768, NULL, 5, NULL);
99 }
89 const tollgate_config_t *cfg = tollgate_config_get(); 100 const tollgate_config_t *cfg = tollgate_config_get();
90 char portal_url[128]; 101 char portal_url[128];
91 snprintf(portal_url, sizeof(portal_url), "http://%s/", cfg->ap_ip_str); 102 snprintf(portal_url, sizeof(portal_url), "http://%s/", cfg->ap_ip_str);
@@ -143,7 +154,6 @@ static void ip_event_handler(void *arg, esp_event_base_t event_base,
143 } else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_LOST_IP) { 154 } else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_LOST_IP) {
144 ESP_LOGW(TAG, "Lost IP address"); 155 ESP_LOGW(TAG, "Lost IP address");
145 xEventGroupClearBits(s_wifi_event_group, WIFI_CONNECTED_BIT); 156 xEventGroupClearBits(s_wifi_event_group, WIFI_CONNECTED_BIT);
146 stop_services();
147 } 157 }
148} 158}
149 159
@@ -202,6 +212,12 @@ static void start_services(void)
202 if (s_services_mutex) xSemaphoreGive(s_services_mutex); 212 if (s_services_mutex) xSemaphoreGive(s_services_mutex);
203 ESP_LOGI(TAG, "=== TollGate services started ==="); 213 ESP_LOGI(TAG, "=== TollGate services started ===");
204 214
215 if (s_start_in_error_state) {
216 s_start_in_error_state = false;
217 ESP_LOGI(TAG, "Services started in error state (no upstream), keeping DISPLAY_ERROR");
218 return;
219 }
220
205 display_set_state(DISPLAY_READY); 221 display_set_state(DISPLAY_READY);
206 char portal_url[128]; 222 char portal_url[128];
207 snprintf(portal_url, sizeof(portal_url), "http://%s/", cfg->ap_ip_str); 223 snprintf(portal_url, sizeof(portal_url), "http://%s/", cfg->ap_ip_str);