diff --git a/Arduino/CanGrow/CanGrow.ino b/Arduino/CanGrow/CanGrow.ino index 4d8212b..42cd920 100644 --- a/Arduino/CanGrow/CanGrow.ino +++ b/Arduino/CanGrow/CanGrow.ino @@ -945,56 +945,34 @@ void WebHandler() { * * 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 webserver.on("/wifiSettings", HTTP_GET, WEBwifiSettings); 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 webserver.on("/help", HTTP_GET, WEBhelp); // 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 // favicon.ico is a special one, because its requested everytime and i dont wont to deliver the // failed whole page every call. we can save up this 0,5kb traffic :o) webserver.on("/favicon.ico", [](){ webserver.send(404, "text/html", "404 - not found"); }); 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,14 +1079,26 @@ void WEBhelp() { */ void WEBroot() { - String body = FPSTR(HTMLheader); - body += "
"; - body += timeClient.getFormattedTime(); - body += "
"; - body += returnHTMLfooter(); - - webserver.send(200, "text/html", body); + 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); + + body += ""; + body += timeClient.getFormattedTime(); + body += "
"; + body += returnHTMLfooter(); + + webserver.send(200, "text/html", body); + } } /* @@ -1163,143 +1153,157 @@ void WEBwifiSettings() { } void WEBsystemSettings() { - String body = FPSTR(HTMLheader); - - if(configured == false) { - body += "Please configure all settings
";
- body += "
here you can set which features and sensors you use
";
- body += "
Please configure all settings
";
+ String body = FPSTR(HTMLheader);
+
+ if(strlen(GrowName) < 1) {
+ body += "
Please configure all settings
";
+ body += "
Here you can set everything grow related, like light hours, how much water, LED brightness
";
body += "
Here you can set everything grow related, like light hours, how much water, LED brightness
";
- body += "