118 lines
4.2 KiB
C++
118 lines
4.2 KiB
C++
String logfile = "";
|
|
|
|
void setup_webserver(){
|
|
server.on("/log", []() { //Define the handling function for the path
|
|
|
|
server.send(200, "text/plain", logfile);
|
|
|
|
});
|
|
|
|
server.on("/", handleRootPath); //Associate the handler function to the path
|
|
server.begin(); //Start the server
|
|
}
|
|
|
|
void handle_webserver(){
|
|
server.handleClient(); //Handling of incoming requests
|
|
}
|
|
|
|
|
|
String Header = "<!DOCTYPE html><html><head><meta charset=\"UTF-8\"><title>Lichtwecker</title></head><body><div id=\"header\"><h1>Licht Wecker</h1></div><div id=\"content\" style=\"font-size:1.2em;\">";
|
|
String Footer = "</div><br><br><br><div id=\"footer\">Hardware: " + Hardware + ", Software:"+ Software +"</div></body></html> ";
|
|
|
|
void handleRootPath() { //Handler for the rooth path
|
|
handleArgs();
|
|
}
|
|
|
|
//############################################################
|
|
//WebPage Args
|
|
void handleArgs(){
|
|
for (int i = 0; i < server.args(); i++) {
|
|
//write_log(server.argName(i) +" : " +server.arg(i));
|
|
if(server.argName(i) == "ntp"){
|
|
if(server.arg(i) == "true"){
|
|
if (ntp_update != true){
|
|
ntp_update = true;
|
|
write_eeprom();
|
|
}
|
|
}
|
|
else if (server.arg(i) == "false"){
|
|
if (ntp_update != false){
|
|
ntp_update = false;
|
|
write_eeprom();
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
else if(server.argName(i) == "a1"){
|
|
if(server.arg(i) == "true"){
|
|
Clock.turnOnAlarm(1);
|
|
}
|
|
else if (server.arg(i) == "false"){
|
|
Clock.turnOffAlarm(1);
|
|
}
|
|
break;
|
|
}
|
|
else if(server.argName(i) == "a2"){
|
|
if(server.arg(i) == "true"){
|
|
Clock.turnOnAlarm(2);
|
|
}
|
|
else if (server.arg(i) == "false"){
|
|
Clock.turnOffAlarm(2);
|
|
}
|
|
break;
|
|
}
|
|
else if(server.argName(i) == "al1h" && server.argName(i +1) == "al1m"){
|
|
al1h = server.arg(i).toInt();
|
|
al1m = server.arg(i+1).toInt();
|
|
set_alarm1();
|
|
break;
|
|
}
|
|
else if(server.argName(i) == "al2h" && server.argName(i +1) == "al2m"){
|
|
al2h = server.arg(i).toInt();
|
|
al2m = server.arg(i+1).toInt();
|
|
set_alarm2();
|
|
break;
|
|
}
|
|
else if(server.argName(i) == "reset" && server.arg(i) == "true"){
|
|
ESP.restart();
|
|
break;
|
|
}
|
|
}
|
|
print_website();
|
|
}
|
|
|
|
|
|
void print_website(){
|
|
bool A1 = Clock.checkAlarmEnabled(1);
|
|
bool A2 = Clock.checkAlarmEnabled(2);
|
|
String Alarm1 = "Alarm 1: <form action=\"/\" methode=\"get\"><input type=\"text\" name=\"al1h\" value=\"" + String(al1h) + "\">:<input type=\"text\" name=\"al1m\" value=\"" + String(al1m) + "\"><input type=\"submit\" value=\"Speichern\"></form> Sommerzeit: " + getBoolString(summer) + " Aktiv: " + getBoolString(A1) + "<br><a href=\"?a1=true\">Aktivieren</a> " + " <a href=\"?a1=false\">Deaktivieren</a>";
|
|
String Alarm2 = "Alarm 2: <form action=\"/\" methode=\"get\"><input type=\"text\" name=\"al2h\" value=\"" + String(al2h) + "\">:<input type=\"text\" name=\"al2m\" value=\"" + String(al2m) + "\"><input type=\"submit\" value=\"Speichern\"></form> Sommerzeit: " + getBoolString(summer) + " Aktiv: " + getBoolString(A2) + "<br><a href=\"?a2=true\">Aktivieren</a> " + " <a href=\"?a2=false\">Deaktivieren</a>";
|
|
String Alarm = "<h3>Alarm</h3>" + Alarm1 + "<br><br>" + Alarm2;
|
|
String Zeit = "<br><h3>Zeit</h3>" + String(h) + ":" + String(m) + ":" + String(s) + " - " + String(d) + "." + String(M) + "." + String(y) + " | DST: " + String(summertime_EU(y,M,d,h,1));
|
|
String NTP = "<br><h3>NTP</h3>" + String("stündliches Zeit Update über Netzwerk: ") + getBoolString(ntp_update) + "<br><a href=\"?ntp=true\">Aktivieren</a> " + " <a href=\"?ntp=false\">Deaktivieren</a>";
|
|
String Reboot = "<br><h3>System:</h3><a href=\"?reset=true\">Neustart</a>";
|
|
String Body = Alarm + Zeit + NTP + Reboot;
|
|
server.send(200, "text/html", Header + Body + Footer);
|
|
}
|
|
|
|
|
|
//Helpers
|
|
//####################################################################################
|
|
String getBoolString(bool value){
|
|
if(value)
|
|
{
|
|
return "Ja";
|
|
}
|
|
return "Nein";
|
|
}
|
|
|
|
|
|
void write_log(String text){
|
|
Serial.println(text);
|
|
logfile = logfile + String(text) + "\r\n";
|
|
if (logfile.length() > 140000) {
|
|
logfile = logfile.substring((logfile.length()-100000));
|
|
}
|
|
}
|
|
|