huge improvement on WebUI with caching
This commit is contained in:
		| @@ -17,7 +17,7 @@ void initWebUI() | |||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   webServer.serveStatic("/static/", LittleFS, "/static/"); |   webServer.serveStatic("/static/", LittleFS, "/static/").setCacheControl("max-age=360000");; | ||||||
|   webServer.on("/", HTTP_GET, [](AsyncWebServerRequest *request) |   webServer.on("/", HTTP_GET, [](AsyncWebServerRequest *request) | ||||||
|                { request->redirect("/index.htm"); }); |                { request->redirect("/index.htm"); }); | ||||||
|   webServer.onNotFound(WebserverNotFound_Callback); |   webServer.onNotFound(WebserverNotFound_Callback); | ||||||
| @@ -27,10 +27,6 @@ void initWebUI() | |||||||
|   webServer.begin(); |   webServer.begin(); | ||||||
| } | } | ||||||
|  |  | ||||||
| void UpdateWebUI() |  | ||||||
| { |  | ||||||
| } |  | ||||||
|  |  | ||||||
| String processor(const String &var) | String processor(const String &var) | ||||||
| { | { | ||||||
|   if (var == "TANK_REMAIN_CAPACITY") |   if (var == "TANK_REMAIN_CAPACITY") | ||||||
| @@ -133,11 +129,13 @@ String processor(const String &var) | |||||||
|  |  | ||||||
| void Webserver_Callback(AsyncWebServerRequest *request) | 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) | void WebserverPOST_Callback(AsyncWebServerRequest *request) | ||||||
| { | { | ||||||
|  |   request->send(LittleFS, "/post.htm", "text/html", false, processor); | ||||||
|  |  | ||||||
|   Serial.print("POST:\n"); |   Serial.print("POST:\n"); | ||||||
|   int paramsNr = request->params(); |   int paramsNr = request->params(); | ||||||
|   for (int i = 0; i < paramsNr; i++) |   for (int i = 0; i < paramsNr; i++) | ||||||
| @@ -182,11 +180,39 @@ void WebserverPOST_Callback(AsyncWebServerRequest *request) | |||||||
|     if (p->name() == "cansave") |     if (p->name() == "cansave") | ||||||
|       globals.requestEEAction = EE_CFG_SAVE; |       globals.requestEEAction = EE_CFG_SAVE; | ||||||
|     // end: POST Form Source CAN Settings |     // 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) | void WebserverNotFound_Callback(AsyncWebServerRequest *request) | ||||||
| { | { | ||||||
|   request->send(404, "text/plain", "Not found"); |   request->send(404, "text/html", "Not found"); | ||||||
| } | } | ||||||
| @@ -10,6 +10,5 @@ | |||||||
| #include "globals.h" | #include "globals.h" | ||||||
|  |  | ||||||
| void initWebUI(); | void initWebUI(); | ||||||
| void UpdateWebUI(); |  | ||||||
|  |  | ||||||
| #endif | #endif | ||||||
		Reference in New Issue
	
	Block a user