From 9e84d28ee99475595dc9393be03174d1b8293eaa Mon Sep 17 00:00:00 2001 From: SybexX Date: Mon, 2 Dec 2024 00:26:54 +0100 Subject: [PATCH] overview_add_date_and_time (#3398) * overview_add_date_and_time * Update overview.html --------- Co-authored-by: CaCO3 --- .../jomjol_flowcontroll/MainFlowControl.cpp | 27 +++++++++++++++++++ code/main/server_main.cpp | 2 +- sd-card/html/overview.html | 16 +++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/code/components/jomjol_flowcontroll/MainFlowControl.cpp b/code/components/jomjol_flowcontroll/MainFlowControl.cpp index e80f69eb3..b378e2622 100644 --- a/code/components/jomjol_flowcontroll/MainFlowControl.cpp +++ b/code/components/jomjol_flowcontroll/MainFlowControl.cpp @@ -1487,6 +1487,28 @@ esp_err_t handler_rssi(httpd_req_t *req) return ESP_OK; } +esp_err_t handler_current_date(httpd_req_t *req) +{ +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_uptime - Start"); +#endif + + std::string formatedDateAndTime = getCurrentTimeString("%Y-%m-%d %H:%M:%S"); + // std::string formatedDate = getCurrentTimeString("%Y-%m-%d"); + + httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); + httpd_resp_send(req, formatedDateAndTime.c_str(), formatedDateAndTime.length()); + + /* Respond with an empty chunk to signal HTTP response completion */ + httpd_resp_sendstr_chunk(req, NULL); + +#ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_uptime - End"); +#endif + + return ESP_OK; +} + esp_err_t handler_uptime(httpd_req_t *req) { #ifdef DEBUG_DETAIL_ON @@ -1798,6 +1820,11 @@ void register_server_main_flow_task_uri(httpd_handle_t server) camuri.user_ctx = (void *)"Light Off"; httpd_register_uri_handler(server, &camuri); + camuri.uri = "/date"; + camuri.handler = handler_current_date; + camuri.user_ctx = (void *)"Light Off"; + httpd_register_uri_handler(server, &camuri); + camuri.uri = "/uptime"; camuri.handler = handler_uptime; camuri.user_ctx = (void *)"Light Off"; diff --git a/code/main/server_main.cpp b/code/main/server_main.cpp index 5d9d16f70..58b55e900 100644 --- a/code/main/server_main.cpp +++ b/code/main/server_main.cpp @@ -459,7 +459,7 @@ httpd_handle_t start_webserver(void) config.server_port = 80; config.ctrl_port = 32768; config.max_open_sockets = 5; //20210921 --> previously 7 - config.max_uri_handlers = 40; // Make sure this fits all URI handlers. Memory usage in bytes: 6*max_uri_handlers + config.max_uri_handlers = 41; // Make sure this fits all URI handlers. Memory usage in bytes: 6*max_uri_handlers config.max_resp_headers = 8; config.backlog_conn = 5; config.lru_purge_enable = true; // this cuts old connections if new ones are needed. diff --git a/sd-card/html/overview.html b/sd-card/html/overview.html index 9333a5336..546f492c1 100644 --- a/sd-card/html/overview.html +++ b/sd-card/html/overview.html @@ -118,6 +118,7 @@ +
@@ -153,6 +154,7 @@ loadValue("prevalue", "prevalue", "border-collapse: collapse; width: 100%"); loadValue("error", "error", "border-collapse: collapse; width: 100%"); loadStatus(); + loadSntpDate(); loadCPUTemp(); loadRSSI(); loadUptime(); @@ -234,6 +236,20 @@ xhttp.send(); } + function loadSntpDate() { + url = domainname + '/date'; + var xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function () { + if (this.readyState == 4 && this.status == 200) { + var _rsp = xhttp.responseText; + $('#sntp_date').html("Date/Time on device: " + _rsp); + } + } + + xhttp.open("GET", url, true); + xhttp.send(); + } + function loadUptime() { url = domainname + '/uptime'; var xhttp = new XMLHttpRequest();