firmware wip - maintenance mode to own webpage

This commit is contained in:
Marcus 2024-05-09 19:48:25 +02:00
parent 330b3e7649
commit 45787b5cdc

View file

@ -1657,6 +1657,8 @@ void WebHandler() {
webserver.on("/system/restart", HTTP_GET, SysRestart);
// wipe eeprom triggered from WebGui
webserver.on("/system/wipe", HTTP_GET, SysWipe);
// Maintenance mode
webserver.on("/system/maintenance", HTTP_GET, SysMaintenance);
// does not work atm TODO
//webserver.on("/logout", [](){ webserver.send(401, "text/html", "logged out!"); });
@ -1750,7 +1752,7 @@ String returnHTMLheader(String MenuEntry = "") {
// status icons and info
if(MaintenanceMode == true) {
// status icons
header += " | 🇲 ";
header += " | ⏸️ ";
header += MaintenanceDuration - ((millis() - MaintenanceStarted) / 1000);
header += "s";
}
@ -1885,6 +1887,28 @@ void Syslogout() {
webserver.send(401, "text/html", body);
}
void SysMaintenance() {
String body = returnHTMLheader();
if( (webserver.hasArg("on")) ) {
MaintenanceMode = true;
MaintenanceStarted = millis();
body += "<div class='infomsg'>&#9208;&#65039; On for ";
body += MaintenanceDuration;
body += "s</div>";
} else if (webserver.hasArg("off")){
MaintenanceMode = false;
body += "<div class='infomsg'>&#9208;&#65039; Off</div>";
}
body += "<h2>&#9208;&#65039; Maintenance Mode</h2>";
body += "<form action='/system/maintenance'><input type='hidden' name='on' value='true' /><input type='submit' value='On'/></form>";
body += "<form action='/system/maintenance'><input type='hidden' name='off' value='true' /><input type='submit' value='Off'/></form>";
body += FPSTR(HTMLfooter);
webserver.send(200, "text/html", body);
}
/*
* TODO
@ -2017,14 +2041,10 @@ void WEBroot() {
body += "</select><br>\n";
body += "Intensity: <input type='range' id='OutputPWM' name='OutputPWM' min='1' max='255' value='255'/><br>\n";
body += "Maintenance: <select id='EnableMaintenance' name='EnableMaintenance'>\n";
body += "<option disabled value='' selected hidden>---</option>\n";
body += "<option value='1'>On</option>\n";
body += "<option value='0'>Off</option>\n";
body += "</select><br>\n";
body += "<input type='submit' value='Save'>\n";
body += "</form>";
body += "</form><br>\n";
body += "<form action='/system/maintenance'><input type='submit' value='Maintenance Mode'/></form>";
body += FPSTR(HTMLfooter);
@ -2571,15 +2591,12 @@ void POSTsetOutput() {
byte OutputNr = webserver.arg("output").toInt();
//PinLEDPWM = webserver.arg("PinLEDPWM").toInt();
byte OutputPWM = webserver.arg("OutputPWM").toInt();
byte EnableMaintenance = webserver.arg("EnableMaintenance").toInt();
Serial.println(":: POSTsetOutput ::");
Serial.print("OutputState: ");
Serial.println(OutputState);
Serial.print("OutputNr: ");
Serial.println(OutputNr);
Serial.print("EnableMaintenance: ");
Serial.println(EnableMaintenance);
if((OutputNr > 3) || (OutputNr < 1) || (OutputState > 255) || (OutputState < 0)) {
webserver.send(400, "text/plain", "not valid\n");
@ -2595,14 +2612,7 @@ void POSTsetOutput() {
webserver.sendHeader("Location", String("/?success"), true);
webserver.send(302, "text/plain", "switch: success!\n");
}
if((EnableMaintenance > 0) && (UseLEDrelais == false)) {
MaintenanceMode = true;
MaintenanceStarted = millis();
} else {
MaintenanceMode = false;
}
}