upleb.uk

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

summaryrefslogtreecommitdiff
path: root/main/tollgate_api.c
diff options
context:
space:
mode:
authorYour Name <you@example.com>2026-05-18 19:07:08 +0530
committerYour Name <you@example.com>2026-05-18 19:07:08 +0530
commit859f9b14e033de9a0690ccbbb975b4b472b688ce (patch)
tree678b248420886b1a17fbd32fc796cb2029863bf6 /main/tollgate_api.c
parent6e6d24169fe7ac8960236293bd39a4532f08f65b (diff)
Move /mints to API server (port 2121), fix services persistence
- /mints handler moved from captive portal (port 80) to API server (port 2121) where it belongs (JSON endpoint, matches portal JS fetch URL) - Remove stop_services() from STA disconnect and IP loss handlers - Services now persist across WiFi STA reconnections - Reduce MAX_STA_RETRY from 5 to 3
Diffstat (limited to 'main/tollgate_api.c')
-rw-r--r--main/tollgate_api.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/main/tollgate_api.c b/main/tollgate_api.c
index b694729..22b30ee 100644
--- a/main/tollgate_api.c
+++ b/main/tollgate_api.c
@@ -484,8 +484,28 @@ static esp_err_t api_post_wallet_send(httpd_req_t *req)
484 return ESP_OK; 484 return ESP_OK;
485} 485}
486 486
487static esp_err_t api_get_mints(httpd_req_t *req)
488{
489 int mint_count = 0;
490 const mint_status_t *mints = mint_health_get_all(&mint_count);
491 cJSON *arr = cJSON_CreateArray();
492 for (int i = 0; i < mint_count; i++) {
493 cJSON *obj = cJSON_CreateObject();
494 cJSON_AddStringToObject(obj, "url", mints[i].url);
495 cJSON_AddBoolToObject(obj, "reachable", mints[i].reachable);
496 cJSON_AddItemToArray(arr, obj);
497 }
498 char *json = cJSON_PrintUnformatted(arr);
499 httpd_resp_set_type(req, "application/json");
500 httpd_resp_send(req, json, strlen(json));
501 cJSON_free(json);
502 cJSON_Delete(arr);
503 return ESP_OK;
504}
505
487static const httpd_uri_t uri_discovery = { .uri = "/", .method = HTTP_GET, .handler = api_get_discovery }; 506static const httpd_uri_t uri_discovery = { .uri = "/", .method = HTTP_GET, .handler = api_get_discovery };
488static const httpd_uri_t uri_payment = { .uri = "/", .method = HTTP_POST, .handler = api_post_payment }; 507static const httpd_uri_t uri_payment = { .uri = "/", .method = HTTP_POST, .handler = api_post_payment };
508static const httpd_uri_t uri_mints = { .uri = "/mints", .method = HTTP_GET, .handler = api_get_mints };
489static const httpd_uri_t uri_usage = { .uri = "/usage", .method = HTTP_GET, .handler = api_get_usage }; 509static const httpd_uri_t uri_usage = { .uri = "/usage", .method = HTTP_GET, .handler = api_get_usage };
490static const httpd_uri_t uri_whoami = { .uri = "/whoami", .method = HTTP_GET, .handler = api_get_whoami }; 510static const httpd_uri_t uri_whoami = { .uri = "/whoami", .method = HTTP_GET, .handler = api_get_whoami };
491static const httpd_uri_t uri_wallet = { .uri = "/wallet", .method = HTTP_GET, .handler = api_get_wallet }; 511static const httpd_uri_t uri_wallet = { .uri = "/wallet", .method = HTTP_GET, .handler = api_get_wallet };
@@ -499,7 +519,7 @@ esp_err_t tollgate_api_start(void)
499 httpd_config_t config = HTTPD_DEFAULT_CONFIG(); 519 httpd_config_t config = HTTPD_DEFAULT_CONFIG();
500 config.server_port = 2121; 520 config.server_port = 2121;
501 config.ctrl_port = 32769; 521 config.ctrl_port = 32769;
502 config.max_uri_handlers = 10; 522 config.max_uri_handlers = 12;
503 config.stack_size = 16384; 523 config.stack_size = 16384;
504 524
505 esp_err_t ret = httpd_start(&s_api_server, &config); 525 esp_err_t ret = httpd_start(&s_api_server, &config);
@@ -510,6 +530,7 @@ esp_err_t tollgate_api_start(void)
510 530
511 httpd_register_uri_handler(s_api_server, &uri_discovery); 531 httpd_register_uri_handler(s_api_server, &uri_discovery);
512 httpd_register_uri_handler(s_api_server, &uri_payment); 532 httpd_register_uri_handler(s_api_server, &uri_payment);
533 httpd_register_uri_handler(s_api_server, &uri_mints);
513 httpd_register_uri_handler(s_api_server, &uri_usage); 534 httpd_register_uri_handler(s_api_server, &uri_usage);
514 httpd_register_uri_handler(s_api_server, &uri_whoami); 535 httpd_register_uri_handler(s_api_server, &uri_whoami);
515 httpd_register_uri_handler(s_api_server, &uri_wallet); 536 httpd_register_uri_handler(s_api_server, &uri_wallet);