229 lines
7.7 KiB
C++
229 lines
7.7 KiB
C++
|
#include "globalvars.h"
|
||
|
#include <Arduino.h>
|
||
|
|
||
|
void reload_home() {
|
||
|
char time_current[3][3] = {"", "", ""};
|
||
|
if (myTime.hour() < 10) {
|
||
|
sprintf(time_current[0], "0%d", myTime.hour());
|
||
|
} else {
|
||
|
sprintf(time_current[0], "%d", myTime.hour());
|
||
|
}
|
||
|
if (myTime.minute() < 10) {
|
||
|
sprintf(time_current[1], "0%d", myTime.minute());
|
||
|
} else {
|
||
|
sprintf(time_current[1], "%d", myTime.minute());
|
||
|
}
|
||
|
if (myTime.second() < 10) {
|
||
|
sprintf(time_current[2], "0%d", myTime.second());
|
||
|
} else {
|
||
|
sprintf(time_current[2], "%d", myTime.second());
|
||
|
}
|
||
|
|
||
|
sprintf(home_html, "<!DOCTYPE html>\
|
||
|
<html lang='de'>\
|
||
|
<head>\
|
||
|
<meta charset='UTF-8'>\
|
||
|
<meta http-equiv='X-UA-Compatible' content='IE=edge'>\
|
||
|
<meta name='viewport' content='width=device-width, initial-scale=1.0'>\
|
||
|
<title>Home</title>\
|
||
|
<style>\
|
||
|
* {\
|
||
|
font-family: Arial, Helvetica, sans-serif;\
|
||
|
font-size: 40px;\
|
||
|
user-select: none;\
|
||
|
text-decoration: none;\
|
||
|
}\
|
||
|
h2 {\
|
||
|
font-size: 28px;\
|
||
|
}\
|
||
|
h2 span{\
|
||
|
font-size: inherit;\
|
||
|
font-family: monospace;\
|
||
|
}\
|
||
|
.wrapper_main {\
|
||
|
margin: 0 auto;\
|
||
|
width: fit-content;\
|
||
|
width: -moz-fit-content;\
|
||
|
text-align: center;\
|
||
|
background-color: rgb(202, 202, 202);\
|
||
|
padding: 1px 8px 8px 8px;\
|
||
|
border-radius: 4px;\
|
||
|
}\
|
||
|
.wrapper_form div a {\
|
||
|
width: 100px;\
|
||
|
}\
|
||
|
.wrapper_form div a, .animated_a {\
|
||
|
background-color: rgb(252, 255, 104);\
|
||
|
border: none;\
|
||
|
border-radius: 4px;\
|
||
|
box-shadow: rgb(180, 172, 59) 0 4px;\
|
||
|
position: relative;\
|
||
|
margin: 8px 0;\
|
||
|
padding: 2px;\
|
||
|
}\
|
||
|
.wrapper_form div a, .animated_a {\
|
||
|
display: inline-block;\
|
||
|
}\
|
||
|
a {\
|
||
|
color: black;\
|
||
|
}\
|
||
|
.wrapper_form div a, .animated_a {\
|
||
|
cursor: pointer;\
|
||
|
}\
|
||
|
.animated_a:active, .wrapper_form div a:active {\
|
||
|
box-shadow: rgb(180, 172, 59) 0 2px;\
|
||
|
top: 2px;\
|
||
|
}\
|
||
|
</style>\
|
||
|
</head>\
|
||
|
<body>\
|
||
|
<div class='wrapper_main'>\
|
||
|
<h1>Übersicht</h1>\
|
||
|
<h2>Uhrzeit: <span>%s:%s:%s</span></h2>\
|
||
|
<div class='wrapper_form'>\
|
||
|
<div>\
|
||
|
<span>Ventil 1: </span>\
|
||
|
<a href='/toggle?number=0'>%s</a>\
|
||
|
</div>\
|
||
|
<div>\
|
||
|
<span>Ventil 2:</span>\
|
||
|
<a href='/toggle?number=1'>%s</a>\
|
||
|
</div>\
|
||
|
<div>\
|
||
|
<span>Ventil 3:</span>\
|
||
|
<a href='/toggle?number=2'>%s</a>\
|
||
|
</div>\
|
||
|
<div>\
|
||
|
<span>Ventil 4:</span>\
|
||
|
<a href='/toggle?number=3'>%s</a>\
|
||
|
</div>\
|
||
|
<div>\
|
||
|
<span>Ventil 5:</span>\
|
||
|
<a href='/toggle?number=4'>%s</a>\
|
||
|
</div>\
|
||
|
<div>\
|
||
|
<span>Ventil 6:</span>\
|
||
|
<a href='/toggle?number=5'>%s</a>\
|
||
|
</div>\
|
||
|
<div>\
|
||
|
<span>Ventil 7:</span>\
|
||
|
<a href='/toggle?number=6'>%s</a>\
|
||
|
</div>\
|
||
|
<div style='display: none;'>\
|
||
|
<span>Ventil 8:</span>\
|
||
|
<a href='/toggle?number=7'>%s</a>\
|
||
|
</div>\
|
||
|
<a class='animated_a' href='/settings'>Einstellungen</a>\
|
||
|
<br>\
|
||
|
<a class='animated_a' href='#'>Kellerheizung</a>\
|
||
|
</div>\
|
||
|
</div>\
|
||
|
</body>\
|
||
|
</html>",
|
||
|
time_current[0], time_current[1], time_current[2], stat[0], stat[1],
|
||
|
stat[2], stat[3], stat[4], stat[5], stat[6], stat[7]);
|
||
|
}
|
||
|
|
||
|
void reload_settings() {
|
||
|
sprintf(settings_html, "<tr>\
|
||
|
<td>1</td>\
|
||
|
<td>%s:%s</td>\
|
||
|
<td>%s:%s</td>\
|
||
|
<td>%s:%s</td>\
|
||
|
<td>%s:%s</td>\
|
||
|
</tr>\
|
||
|
<tr>\
|
||
|
<td>2</td>\
|
||
|
<td>%s:%s</td>\
|
||
|
<td>%s:%s</td>\
|
||
|
<td>%s:%s</td>\
|
||
|
<td>%s:%s</td>\
|
||
|
</tr>\
|
||
|
<tr>\
|
||
|
<td>3</td>\
|
||
|
<td>%s:%s</td>\
|
||
|
<td>%s:%s</td>\
|
||
|
<td>%s:%s</td>\
|
||
|
<td>%s:%s</td>\
|
||
|
</tr>\
|
||
|
<tr>\
|
||
|
<td>4</td>\
|
||
|
<td>%s:%s</td>\
|
||
|
<td>%s:%s</td>\
|
||
|
<td>%s:%s</td>\
|
||
|
<td>%s:%s</td>\
|
||
|
</tr>\
|
||
|
<tr>\
|
||
|
<td>5</td>\
|
||
|
<td>%s:%s</td>\
|
||
|
<td>%s:%s</td>\
|
||
|
<td>%s:%s</td>\
|
||
|
<td>%s:%s</td>\
|
||
|
</tr>\
|
||
|
<tr>\
|
||
|
<td>6</td>\
|
||
|
<td>%s:%s</td>\
|
||
|
<td>%s:%s</td>\
|
||
|
<td>%s:%s</td>\
|
||
|
<td>%s:%s</td>\
|
||
|
</tr>\
|
||
|
<tr>\
|
||
|
<td>7</td>\
|
||
|
<td>%s:%s</td>\
|
||
|
<td>%s:%s</td>\
|
||
|
<td>%s:%s</td>\
|
||
|
<td>%s:%s</td>\
|
||
|
</tr>\
|
||
|
<tr style='display: none'>\
|
||
|
<td>8</td>\
|
||
|
<td>%s:%s</td>\
|
||
|
<td>%s:%s</td>\
|
||
|
<td>%s:%s</td>\
|
||
|
<td>%s:%s</td>\
|
||
|
</tr>\
|
||
|
</table>\
|
||
|
</div>\
|
||
|
<a class='animated_a' href='/'>Übersicht</a>\
|
||
|
</div>\
|
||
|
</body>\
|
||
|
</html>",
|
||
|
time_all[0][0], time_all[1][0], time_all[2][0], time_all[3][0],
|
||
|
time_all[4][0], time_all[5][0], time_all[6][0], time_all[7][0],
|
||
|
time_all[0][1], time_all[1][1], time_all[2][1], time_all[3][1],
|
||
|
time_all[4][1], time_all[5][1], time_all[6][1], time_all[7][1],
|
||
|
time_all[0][2], time_all[1][2], time_all[2][2], time_all[3][2],
|
||
|
time_all[4][2], time_all[5][2], time_all[6][2], time_all[7][2],
|
||
|
time_all[0][3], time_all[1][3], time_all[2][3], time_all[3][3],
|
||
|
time_all[4][3], time_all[5][3], time_all[6][3], time_all[7][3],
|
||
|
time_all[0][4], time_all[1][4], time_all[2][4], time_all[3][4],
|
||
|
time_all[4][4], time_all[5][4], time_all[6][4], time_all[7][4],
|
||
|
time_all[0][5], time_all[1][5], time_all[2][5], time_all[3][5],
|
||
|
time_all[4][5], time_all[5][5], time_all[6][5], time_all[7][5],
|
||
|
time_all[0][6], time_all[1][6], time_all[2][6], time_all[3][6],
|
||
|
time_all[4][6], time_all[5][6], time_all[6][6], time_all[7][6],
|
||
|
time_all[0][7], time_all[1][7], time_all[2][7], time_all[3][7],
|
||
|
time_all[4][7], time_all[5][7], time_all[6][7], time_all[7][7]);
|
||
|
}
|
||
|
|
||
|
void handleToggle() {
|
||
|
int i = server.arg("number")
|
||
|
.toInt(); // converts GET argument to int and does stuff xD
|
||
|
override[i] = !override[i];
|
||
|
debugln(F("---------------------------"));
|
||
|
debug(F("[RECIVED] for: "));
|
||
|
debugln(i);
|
||
|
digitalWrite(pins[i], !digitalRead(pins[i]));
|
||
|
if (digitalRead(pins[i]) == LOW) {
|
||
|
sprintf(stat[i], "AN");
|
||
|
} else {
|
||
|
sprintf(stat[i], "AUS");
|
||
|
}
|
||
|
debug(F("Status: "));
|
||
|
debugln(stat[i]);
|
||
|
reload_home();
|
||
|
server.sendHeader(F("Location"), F("/"), true);
|
||
|
server.send(302, F("text/html"), home_html);
|
||
|
debugln(override[i]);
|
||
|
debugln(F("---------------------------"));
|
||
|
}
|