From e2798f1193a3241f0931bd56562ab4bf6e2398a2 Mon Sep 17 00:00:00 2001 From: samuelbles07 Date: Sat, 7 Dec 2024 04:59:25 +0700 Subject: [PATCH] Dashboard page --- examples/OneOpenAir/LocalServer.cpp | 103 +++++++++++++++++++++++++--- examples/OneOpenAir/LocalServer.h | 7 +- 2 files changed, 100 insertions(+), 10 deletions(-) diff --git a/examples/OneOpenAir/LocalServer.cpp b/examples/OneOpenAir/LocalServer.cpp index ed7dcfa..5bdda7c 100644 --- a/examples/OneOpenAir/LocalServer.cpp +++ b/examples/OneOpenAir/LocalServer.cpp @@ -13,12 +13,10 @@ bool LocalServer::begin(void) { server.on(openMetrics.getApi(), HTTP_GET, [this]() { _GET_metrics(); }); server.on("/config", HTTP_GET, [this]() { _GET_config(); }); server.on("/config", HTTP_PUT, [this]() { _PUT_config(); }); - server.on("/storage", HTTP_GET, [this]() { - Serial.println(server.arg("time")); - _GET_storage(); - }); - server.on("/storage/reset", HTTP_PUT, [this]() { _PUT_storage(); }); - server.on("/timestamp", HTTP_PUT, [this]() { _PUT_time(); }); + server.on("/dashboard", HTTP_GET, [this]() { _GET_dashboard(); }); + server.on("/storage/download", HTTP_GET, [this]() { _GET_storage(); }); + server.on("/storage/reset", HTTP_POST, [this]() { _POST_storage(); }); + server.on("/timestamp", HTTP_POST, [this]() { _POST_time(); }); server.begin(); @@ -75,6 +73,11 @@ void LocalServer::_GET_measure(void) { server.send(200, "application/json", toSend); } +void LocalServer::_GET_dashboard(void) { + String timestamp = ag->getCurrentTime(); + server.send(200, "text/html", htmlDashboard(timestamp)); +} + void LocalServer::_GET_storage(void) { char *data = measure.getLocalStorage(); if (data != nullptr) { @@ -86,7 +89,7 @@ void LocalServer::_GET_storage(void) { } } -void LocalServer::_PUT_storage(void) { +void LocalServer::_POST_storage(void) { if (!measure.resetLocalStorage()) { server.send(500, "text/plain", "Failed reset local storage, unknown error"); return; @@ -95,7 +98,7 @@ void LocalServer::_PUT_storage(void) { server.send(200, "text/plain", "Success reset storage"); } -void LocalServer::_PUT_time(void) { +void LocalServer::_POST_time(void) { String epochTime = server.arg(0); Serial.printf("Received epoch: %s \n", epochTime.c_str()); if (epochTime.isEmpty()) { @@ -115,3 +118,87 @@ void LocalServer::_PUT_time(void) { } void LocalServer::setFwMode(AgFirmwareMode fwMode) { this->fwMode = fwMode; } + +String LocalServer::htmlDashboard(String timestamp) { + // TODO: Set timestamp + String page = ""; + page += ""; + page += ""; + page += ""; + page += " "; + page += " "; + page += " Button Layout with Datetime Picker"; + page += " "; + page += ""; + page += ""; + page += "
"; + page += " "; + page += "
"; + page += "
"; + page += " "; + page += " "; + page += " "; + page += "
"; + page += "
"; + page += "
"; + page += " "; + page += "
"; + page += ""; + page += ""; + page += ""; + + return page; +} \ No newline at end of file diff --git a/examples/OneOpenAir/LocalServer.h b/examples/OneOpenAir/LocalServer.h index 64d423b..3af34ff 100644 --- a/examples/OneOpenAir/LocalServer.h +++ b/examples/OneOpenAir/LocalServer.h @@ -19,6 +19,8 @@ class LocalServer : public PrintLog { WebServer server; AgFirmwareMode fwMode; + String htmlDashboard(String timestamp); + public: LocalServer(Stream &log, OpenMetrics &openMetrics, Measurements &measure, Configuration &config, WifiConnector& wifiConnector); @@ -33,9 +35,10 @@ class LocalServer : public PrintLog { void _PUT_config(void); void _GET_metrics(void); void _GET_measure(void); + void _GET_dashboard(void); void _GET_storage(void); - void _PUT_storage(void); - void _PUT_time(void); + void _POST_storage(void); + void _POST_time(void); }; #endif /** _LOCAL_SERVER_H_ */