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:
Diffstat (limited to 'main/tollgate_api.c')
-rw-r--r--main/tollgate_api.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/main/tollgate_api.c b/main/tollgate_api.c
index 45cd02f..af91093 100644
--- a/main/tollgate_api.c
+++ b/main/tollgate_api.c
@@ -3,6 +3,7 @@
3#include "config.h" 3#include "config.h"
4#include "identity.h" 4#include "identity.h"
5#include "session.h" 5#include "session.h"
6#include "captive_portal.h"
6#include "firewall.h" 7#include "firewall.h"
7#include "nucula_wallet.h" 8#include "nucula_wallet.h"
8#include "mint_health.h" 9#include "mint_health.h"
@@ -681,6 +682,32 @@ static esp_err_t api_get_mining_stats(httpd_req_t *req)
681 return ESP_OK; 682 return ESP_OK;
682} 683}
683 684
685extern bool s_start_services_called;
686extern bool s_start_ap_services_called;
687extern bool s_sta_got_ip;
688extern bool s_ap_started;
689
690static esp_err_t api_get_debug(httpd_req_t *req)
691{
692 httpd_handle_t portal = captive_portal_get_server();
693 cJSON *root = cJSON_CreateObject();
694 cJSON_AddBoolToObject(root, "portal_running", portal != NULL);
695 cJSON_AddBoolToObject(root, "portal_start_called", captive_portal_was_start_called());
696 cJSON_AddNumberToObject(root, "portal_start_result", captive_portal_get_start_result());
697 cJSON_AddBoolToObject(root, "start_services_called", s_start_services_called);
698 cJSON_AddBoolToObject(root, "start_ap_services_called", s_start_ap_services_called);
699 cJSON_AddBoolToObject(root, "sta_got_ip", s_sta_got_ip);
700 cJSON_AddBoolToObject(root, "ap_started", s_ap_started);
701 cJSON_AddNumberToObject(root, "free_heap", (double)esp_get_free_heap_size());
702 cJSON_AddNumberToObject(root, "min_free_heap", (double)esp_get_minimum_free_heap_size());
703 char *json = cJSON_PrintUnformatted(root);
704 httpd_resp_set_type(req, "application/json");
705 httpd_resp_sendstr(req, json);
706 cJSON_free(json);
707 cJSON_Delete(root);
708 return ESP_OK;
709}
710
684static const httpd_uri_t uri_discovery = { .uri = "/", .method = HTTP_GET, .handler = api_get_discovery }; 711static const httpd_uri_t uri_discovery = { .uri = "/", .method = HTTP_GET, .handler = api_get_discovery };
685static const httpd_uri_t uri_payment = { .uri = "/", .method = HTTP_POST, .handler = api_post_payment }; 712static const httpd_uri_t uri_payment = { .uri = "/", .method = HTTP_POST, .handler = api_post_payment };
686static const httpd_uri_t uri_mints = { .uri = "/mints", .method = HTTP_GET, .handler = api_get_mints }; 713static const httpd_uri_t uri_mints = { .uri = "/mints", .method = HTTP_GET, .handler = api_get_mints };
@@ -731,6 +758,7 @@ static esp_err_t api_get_market(httpd_req_t *req)
731} 758}
732 759
733static const httpd_uri_t uri_market = { .uri = "/market", .method = HTTP_GET, .handler = api_get_market }; 760static const httpd_uri_t uri_market = { .uri = "/market", .method = HTTP_GET, .handler = api_get_market };
761static const httpd_uri_t uri_debug = { .uri = "/debug", .method = HTTP_GET, .handler = api_get_debug };
734 762
735esp_err_t tollgate_api_start(void) 763esp_err_t tollgate_api_start(void)
736{ 764{
@@ -750,6 +778,7 @@ esp_err_t tollgate_api_start(void)
750 } 778 }
751 779
752 httpd_register_uri_handler(s_api_server, &uri_discovery); 780 httpd_register_uri_handler(s_api_server, &uri_discovery);
781 httpd_register_uri_handler(s_api_server, &uri_debug);
753 httpd_register_uri_handler(s_api_server, &uri_payment); 782 httpd_register_uri_handler(s_api_server, &uri_payment);
754 httpd_register_uri_handler(s_api_server, &uri_mints); 783 httpd_register_uri_handler(s_api_server, &uri_mints);
755 httpd_register_uri_handler(s_api_server, &uri_usage); 784 httpd_register_uri_handler(s_api_server, &uri_usage);