From a74f02fc615866c9b2496cb0ccadfedd8d1945f4 Mon Sep 17 00:00:00 2001 From: Marcel Peterkau Date: Tue, 8 Mar 2022 22:31:37 +0100 Subject: [PATCH] huge improvement on WebUI with caching --- Software/ChainLube/src/webui.cpp | 42 ++++++++++++++++++++++++++------ Software/ChainLube/src/webui.h | 1 - 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/Software/ChainLube/src/webui.cpp b/Software/ChainLube/src/webui.cpp index 6cf16c2..a088c82 100644 --- a/Software/ChainLube/src/webui.cpp +++ b/Software/ChainLube/src/webui.cpp @@ -17,7 +17,7 @@ void initWebUI() return; } - webServer.serveStatic("/static/", LittleFS, "/static/"); + webServer.serveStatic("/static/", LittleFS, "/static/").setCacheControl("max-age=360000");; webServer.on("/", HTTP_GET, [](AsyncWebServerRequest *request) { request->redirect("/index.htm"); }); webServer.onNotFound(WebserverNotFound_Callback); @@ -27,10 +27,6 @@ void initWebUI() webServer.begin(); } -void UpdateWebUI() -{ -} - String processor(const String &var) { if (var == "TANK_REMAIN_CAPACITY") @@ -133,11 +129,13 @@ String processor(const String &var) void Webserver_Callback(AsyncWebServerRequest *request) { - request->send(LittleFS, "/index.htm", String(), false, processor); + request->send(LittleFS, "/index.htm", "text/html", false, processor); } void WebserverPOST_Callback(AsyncWebServerRequest *request) { + request->send(LittleFS, "/post.htm", "text/html", false, processor); + Serial.print("POST:\n"); int paramsNr = request->params(); for (int i = 0; i < paramsNr; i++) @@ -182,11 +180,39 @@ void WebserverPOST_Callback(AsyncWebServerRequest *request) if (p->name() == "cansave") globals.requestEEAction = EE_CFG_SAVE; // end: POST Form Source CAN Settings + // begin: POST Form Lubrication + if (p->name() == "lubedistancenormal") + LubeConfig.DistancePerLube_Default = p->value().toInt(); + if (p->name() == "lubedistancerain") + LubeConfig.DistancePerLube_Rain = p->value().toInt(); + if (p->name() == "lubesave") + globals.requestEEAction = EE_CFG_SAVE; + // end: POST Form Lubrication + // begin: POST Form Oiltank + if (p->name() == "tankcap") + LubeConfig.tankCapacity_ml = p->value().toInt(); + if (p->name() == "tankwarn") + LubeConfig.TankRemindAtPercentage = p->value().toInt(); + if (p->name() == "pumppulse") + LubeConfig.amountPerDose_µl = p->value().toInt(); + if (p->name() == "oilsave") + globals.requestEEAction = EE_CFG_SAVE; + // end: POST Form Oiltank + // begin: POST Form Maintenance + if (p->name() == "purgepulse") + LubeConfig.BleedingPulses = p->value().toInt(); + if (p->name() == "maintsave") + globals.requestEEAction = EE_CFG_SAVE; + if (p->name() == "resettank") + { + PersistenceData.tankRemain_µl = LubeConfig.tankCapacity_ml * 1000; + globals.requestEEAction = EE_PDS_SAVE; + } + // end: POST Form Maintenance } - request->send(LittleFS, "/post.htm", String(), false, processor); } void WebserverNotFound_Callback(AsyncWebServerRequest *request) { - request->send(404, "text/plain", "Not found"); + request->send(404, "text/html", "Not found"); } \ No newline at end of file diff --git a/Software/ChainLube/src/webui.h b/Software/ChainLube/src/webui.h index f7530b2..f48918d 100644 --- a/Software/ChainLube/src/webui.h +++ b/Software/ChainLube/src/webui.h @@ -10,6 +10,5 @@ #include "globals.h" void initWebUI(); -void UpdateWebUI(); #endif \ No newline at end of file