add last pump time and duration, chip ontime and last water leakage time to website
This commit is contained in:
parent
a0d42847c9
commit
aaf73b2dd7
@ -25,13 +25,14 @@ void WifiManager::init() {
|
||||
handleNotFound();
|
||||
});
|
||||
|
||||
// server available at 192.168.2.1
|
||||
server.begin();
|
||||
} else {
|
||||
Serial.println("Wifi Setup failed!");
|
||||
}
|
||||
}
|
||||
|
||||
WifiManager::WifiManager() : server(80) {}
|
||||
WifiManager::WifiManager() : server(80), lastPumpTime(0), lastWaterOutage(0), lastPumpDuration(0) {}
|
||||
|
||||
void WifiManager::handleRoot() {
|
||||
Serial.println("HomePage called");
|
||||
@ -41,15 +42,57 @@ void WifiManager::handleRoot() {
|
||||
EEPROM.get(0, value);
|
||||
EEPROM.end(); // stop the eeprom communication
|
||||
|
||||
const String index_html = "<!DOCTYPE HTML><html><head>\n"
|
||||
bool pumptimeset = this->lastPumpTime != 0;
|
||||
bool wateroutageset = this->lastWaterOutage != 0;
|
||||
bool pumpdurationset = this->lastPumpDuration != 0;
|
||||
|
||||
unsigned long pumptime = pumptimeset ? (millis() - this->lastPumpTime) / 1000 : 0; // in sec
|
||||
unsigned long wateroutagetime = wateroutageset ? (millis() - this->lastWaterOutage) / 1000 : 0; // in sec
|
||||
unsigned long pumpduration = pumpdurationset ? (this->lastPumpDuration) / 1000 : 0; // in sec
|
||||
|
||||
|
||||
String index_html = "<!DOCTYPE HTML><html><head>\n"
|
||||
" <title>Wastinfoboard-ConfigurationPage</title>\n"
|
||||
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n"
|
||||
" </head><body>\n"
|
||||
" <div>Aktuelle Zeit: "+ String(value / 60) +" Minuten</div>\n"
|
||||
" <div>Aktuelle Zeit: " + String(value / 60) +
|
||||
" Minuten</div>\n"
|
||||
" <form action=\"/get\">\n"
|
||||
" Zeit setzen: <input placeholder=\"Abschaltzeit in h\" type=\"text\" name=\"time\">\n"
|
||||
" <input type=\"submit\" value=\"Submit\">\n"
|
||||
" </form><br>\n"
|
||||
" </form><br>\n";
|
||||
if (pumptimeset) {
|
||||
index_html += "<div>Zeit seit letztem einschalten: " +
|
||||
String(pumptime / (60 * 60)) + "Stunden " +
|
||||
String((pumptime % 3600) / 60) + "Minuten " +
|
||||
String((pumptime % 60)) + "Sekunden</div>";
|
||||
} else {
|
||||
index_html += "<div>Zeit seit letztem einschalten: -</div>";
|
||||
}
|
||||
|
||||
if (wateroutageset) {
|
||||
index_html += "<div>Zeit seit letzem Wasserausfall: " +
|
||||
String(wateroutagetime / (60 * 60 * 24)) + "Tage " +
|
||||
String((wateroutagetime % 86400) / (60 * 60)) + "Stunden " +
|
||||
String((wateroutagetime % 3600) / 60) + "Minuten </div>";
|
||||
} else {
|
||||
index_html += "<div>Zeit seit letzem Wasserausfall: -</div>";
|
||||
}
|
||||
|
||||
if (pumpdurationset) {
|
||||
index_html += "<div>Pumpe lief zuletzt: " +
|
||||
String(pumpduration / 60) + "Minuten " +
|
||||
String((pumpduration % 60)) + "Sekunden</div>";
|
||||
} else {
|
||||
index_html += "<div>Pumpe lief zuletzt: -</div>";
|
||||
}
|
||||
unsigned long currtime = millis() / 1000;
|
||||
|
||||
index_html += "<div>Chip laeuft seit: " +
|
||||
String(currtime / (60 * 60 * 24)) + "Tage " +
|
||||
String((currtime % 86400) / (60 * 60)) + "Stunden " +
|
||||
String((currtime % 3600) / 60) + "Minuten " +
|
||||
String((currtime % 60)) + "Sekunden </div>" +
|
||||
"</body></html>";
|
||||
|
||||
server.send(200, "text/html", index_html);
|
||||
@ -98,3 +141,15 @@ int WifiManager::getWaitTime() {
|
||||
EEPROM.end(); // stop the eeprom communication
|
||||
return value;
|
||||
}
|
||||
|
||||
void WifiManager::setlastPumpTime(unsigned long lastPumpTime) {
|
||||
this->lastPumpTime = lastPumpTime;
|
||||
}
|
||||
|
||||
void WifiManager::setlastWaterOutage(unsigned long lastWaterOutage) {
|
||||
this->lastWaterOutage = lastWaterOutage;
|
||||
}
|
||||
|
||||
void WifiManager::setPumpDuration(unsigned long lastPumpDuration) {
|
||||
this->lastPumpDuration = lastPumpDuration;
|
||||
}
|
||||
|
@ -17,6 +17,11 @@ public:
|
||||
void holdAlive();
|
||||
|
||||
int getWaitTime();
|
||||
|
||||
void setlastPumpTime(unsigned long lastPumpTime);
|
||||
void setlastWaterOutage(unsigned long lastWaterOutage);
|
||||
void setPumpDuration(unsigned long lastPumpDuration);
|
||||
|
||||
private:
|
||||
ESP8266WebServer server;
|
||||
|
||||
@ -25,4 +30,6 @@ private:
|
||||
void handleNotFound();
|
||||
|
||||
void handleGet();
|
||||
|
||||
unsigned long lastPumpTime, lastWaterOutage, lastPumpDuration;
|
||||
};
|
||||
|
12
src/main.cpp
12
src/main.cpp
@ -25,12 +25,14 @@ Ticker pumpendauer;
|
||||
|
||||
WifiManager mang;
|
||||
|
||||
int turnontime = -1;
|
||||
long turnontime = -1;
|
||||
|
||||
void pumpeSchalten(bool on) {
|
||||
// digitalWrite(4,on);
|
||||
if (on) {
|
||||
Serial.println("versuche Pumpe EIN zuschalten");
|
||||
// refresh last pump counter
|
||||
mang.setlastPumpTime(millis());
|
||||
} else {
|
||||
Serial.println("versuche Pumpe AUS zuschalten");
|
||||
}
|
||||
@ -45,8 +47,11 @@ void pumpeSchalten(bool on) {
|
||||
error = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
turnontime = millis();
|
||||
}else{
|
||||
mang.setPumpDuration(millis() - turnontime);
|
||||
}
|
||||
digitalWrite(SchuetzPin, on);
|
||||
Serial.println("[Erfolg] pumpe wird geschalten");
|
||||
} else {
|
||||
@ -82,6 +87,9 @@ void WasserSensorCheck() {
|
||||
Serial.println("Wasser Sensor AUS");
|
||||
//kein Wasser dh timer auf 10min stellen
|
||||
|
||||
// refresh wateroutage counter
|
||||
mang.setlastWaterOutage(millis());
|
||||
|
||||
allow = false;
|
||||
Serial.println("Schalte pumpe aus");
|
||||
pumpeSchalten(false);
|
||||
|
Loading…
Reference in New Issue
Block a user