firmware wip - changed webhandlers - working now with redirects instead setting handlers

This commit is contained in:
Marcus 2024-04-17 02:03:45 +02:00
parent af9847ceb7
commit b3c0959521

View file

@ -945,16 +945,27 @@ void WebHandler() {
* *
* WebHandler_unconfigured() and WebHandler_configured() * WebHandler_unconfigured() and WebHandler_configured()
*/ */
// generic handler // style.css
webserver.on("/style.css", HTTP_GET, WEBstyleCSS);
// Web root
webserver.on("/", HTTP_GET, WEBroot);
// WiFi Stuff // WiFi Stuff
webserver.on("/wifiSettings", HTTP_GET, WEBwifiSettings); webserver.on("/wifiSettings", HTTP_GET, WEBwifiSettings);
webserver.on("/wifiSettings/save", HTTP_POST, POSTwifiSettings); webserver.on("/wifiSettings/save", HTTP_POST, POSTwifiSettings);
webserver.on("/style.css", HTTP_GET, WEBstyleCSS);
// System stuff
webserver.on("/systemSettings", HTTP_GET, WEBsystemSettings);
webserver.on("/systemSettings/save", HTTP_POST, POSTsystemSettings);
// Grow stuff
webserver.on("/growSettings", HTTP_GET, WEBgrowSettings);
webserver.on("/growSettings/save", HTTP_POST, POSTgrowSettings);
// help // help
webserver.on("/help", HTTP_GET, WEBhelp); webserver.on("/help", HTTP_GET, WEBhelp);
// does not work atm TODO // does not work atm TODO
webserver.on("/logout", [](){ webserver.send(401, "text/html", "logged out!"); }); //webserver.on("/logout", [](){ webserver.send(401, "text/html", "logged out!"); });
// 404 handling // 404 handling
// favicon.ico is a special one, because its requested everytime and i dont wont to deliver the // favicon.ico is a special one, because its requested everytime and i dont wont to deliver the
@ -962,39 +973,6 @@ void WebHandler() {
webserver.on("/favicon.ico", [](){ webserver.send(404, "text/html", "404 - not found"); }); webserver.on("/favicon.ico", [](){ webserver.send(404, "text/html", "404 - not found"); });
webserver.onNotFound(WEB404); webserver.onNotFound(WEB404);
// when wifi is unconfigured (WIFIssid <1) then root are Wifi settings
if(strlen(WIFIssid) < 1) {
webserver.on("/", HTTP_GET, WEBwifiSettings);
webserver.on("/systemSettings", HTTP_GET, WEBwifiSettings);
webserver.on("/growSettings", HTTP_GET, WEBwifiSettings);
} else {
// now we need to receive systemSettings
webserver.on("/systemSettings/save", HTTP_POST, POSTsystemSettings);
// when system settings are unconfigured , then system settings are root
if(configured == false) {
webserver.on("/", HTTP_GET, WEBsystemSettings);
webserver.on("/systemSettings", HTTP_GET, WEBsystemSettings);
webserver.on("/growSettings", HTTP_GET, WEBsystemSettings);
} else {
webserver.on("/systemSettings", HTTP_GET, WEBsystemSettings);
}
webserver.on("/growSettings", HTTP_GET, WEBgrowSettings);
// now we need to receive growSettings
webserver.on("/growSettings/save", HTTP_POST, POSTgrowSettings);
// when grow is unconfigured (GrowStart <1) then Grow settings are root
if(GrowStart < 1) {
webserver.on("/", HTTP_GET, WEBgrowSettings);
} else {
webserver.on("/", HTTP_GET, WEBroot);
}
}
} }
@ -1101,7 +1079,18 @@ void WEBhelp() {
*/ */
void WEBroot() { void WEBroot() {
if(strlen(WIFIssid) < 1) {
webserver.sendHeader("Location", String("/wifiSettings"), true);
webserver.send(302, "text/plain", "please configure wifiSettings first");
} else if(configured == false){
webserver.sendHeader("Location", String("/systemSettings"), true);
webserver.send(302, "text/plain", "please configure systemSettings first");
} else if(strlen(GrowName) < 1){
webserver.sendHeader("Location", String("/growSettings"), true);
webserver.send(302, "text/plain", "please configure growSettings first");
} else {
String body = FPSTR(HTMLheader); String body = FPSTR(HTMLheader);
body += "<h1>configured!</h1>"; body += "<h1>configured!</h1>";
body += "<p>"; body += "<p>";
body += timeClient.getFormattedTime(); body += timeClient.getFormattedTime();
@ -1110,6 +1099,7 @@ void WEBroot() {
webserver.send(200, "text/html", body); webserver.send(200, "text/html", body);
} }
}
/* /*
* Config pages * Config pages
@ -1163,6 +1153,12 @@ void WEBwifiSettings() {
} }
void WEBsystemSettings() { void WEBsystemSettings() {
// if wifi settings are unconfigured, we cannot proceed with systemSettings
if(strlen(WIFIssid) < 1) {
webserver.sendHeader("Location", String("/wifiSettings"), true);
webserver.send(302, "text/plain", "please configure wifiSettings first");
} else {
String body = FPSTR(HTMLheader); String body = FPSTR(HTMLheader);
if(configured == false) { if(configured == false) {
@ -1234,11 +1230,18 @@ void WEBsystemSettings() {
webserver.send(200, "text/html", body); webserver.send(200, "text/html", body);
} }
}
/* /*
* Grow pages * Grow pages
*/ */
void WEBgrowSettings() { void WEBgrowSettings() {
// if system settings are unconfigured, we cannot proceed with growSettings
if(configured == false) {
webserver.sendHeader("Location", String("/systemSettings"), true);
webserver.send(302, "text/plain", "please configure systemSettings first");
} else {
String body = FPSTR(HTMLheader); String body = FPSTR(HTMLheader);
if(strlen(GrowName) < 1) { if(strlen(GrowName) < 1) {
@ -1301,6 +1304,7 @@ void WEBgrowSettings() {
webserver.send(200, "text/html", body); webserver.send(200, "text/html", body);
} }
}
/* /*