add last pump time and duration, chip ontime and last water leakage time to website

This commit is contained in:
Lukas Heiligenbrunner 2020-08-01 18:00:36 +02:00
parent a0d42847c9
commit aaf73b2dd7
3 changed files with 87 additions and 17 deletions

View File

@ -11,27 +11,28 @@ void WifiManager::init() {
boolean result = WiFi.softAP("PumpenSteuerung-Heiligenbrunner", "1qayxsw2"); boolean result = WiFi.softAP("PumpenSteuerung-Heiligenbrunner", "1qayxsw2");
if (result == true) { if (result == true) {
Serial.println("Wifi Ready"); Serial.println("Wifi Ready");
Serial.println( WiFi.softAPIP()); Serial.println(WiFi.softAPIP());
server.on("/", HTTP_GET, [this](){ server.on("/", HTTP_GET, [this]() {
handleRoot(); handleRoot();
}); });
server.on("/get", [this](){ server.on("/get", [this]() {
handleGet(); handleGet();
}); });
server.onNotFound([this](){ server.onNotFound([this]() {
handleNotFound(); handleNotFound();
}); });
// server available at 192.168.2.1
server.begin(); server.begin();
} else { } else {
Serial.println("Wifi Setup failed!"); Serial.println("Wifi Setup failed!");
} }
} }
WifiManager::WifiManager() : server(80) {} WifiManager::WifiManager() : server(80), lastPumpTime(0), lastWaterOutage(0), lastPumpDuration(0) {}
void WifiManager::handleRoot() { void WifiManager::handleRoot() {
Serial.println("HomePage called"); Serial.println("HomePage called");
@ -41,16 +42,58 @@ void WifiManager::handleRoot() {
EEPROM.get(0, value); EEPROM.get(0, value);
EEPROM.end(); // stop the eeprom communication EEPROM.end(); // stop the eeprom communication
const String index_html = "<!DOCTYPE HTML><html><head>\n" bool pumptimeset = this->lastPumpTime != 0;
" <title>Wastinfoboard-ConfigurationPage</title>\n" bool wateroutageset = this->lastWaterOutage != 0;
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n" bool pumpdurationset = this->lastPumpDuration != 0;
" </head><body>\n"
" <div>Aktuelle Zeit: "+ String(value / 60) +" Minuten</div>\n" unsigned long pumptime = pumptimeset ? (millis() - this->lastPumpTime) / 1000 : 0; // in sec
" <form action=\"/get\">\n" unsigned long wateroutagetime = wateroutageset ? (millis() - this->lastWaterOutage) / 1000 : 0; // in sec
" Zeit setzen: <input placeholder=\"Abschaltzeit in h\" type=\"text\" name=\"time\">\n" unsigned long pumpduration = pumpdurationset ? (this->lastPumpDuration) / 1000 : 0; // in sec
" <input type=\"submit\" value=\"Submit\">\n"
" </form><br>\n"
"</body></html>"; 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"
" <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";
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); server.send(200, "text/html", index_html);
} }
@ -98,3 +141,15 @@ int WifiManager::getWaitTime() {
EEPROM.end(); // stop the eeprom communication EEPROM.end(); // stop the eeprom communication
return value; 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;
}

View File

@ -17,6 +17,11 @@ public:
void holdAlive(); void holdAlive();
int getWaitTime(); int getWaitTime();
void setlastPumpTime(unsigned long lastPumpTime);
void setlastWaterOutage(unsigned long lastWaterOutage);
void setPumpDuration(unsigned long lastPumpDuration);
private: private:
ESP8266WebServer server; ESP8266WebServer server;
@ -25,4 +30,6 @@ private:
void handleNotFound(); void handleNotFound();
void handleGet(); void handleGet();
unsigned long lastPumpTime, lastWaterOutage, lastPumpDuration;
}; };

View File

@ -25,12 +25,14 @@ Ticker pumpendauer;
WifiManager mang; WifiManager mang;
int turnontime = -1; long turnontime = -1;
void pumpeSchalten(bool on) { void pumpeSchalten(bool on) {
// digitalWrite(4,on); // digitalWrite(4,on);
if (on) { if (on) {
Serial.println("versuche Pumpe EIN zuschalten"); Serial.println("versuche Pumpe EIN zuschalten");
// refresh last pump counter
mang.setlastPumpTime(millis());
} else { } else {
Serial.println("versuche Pumpe AUS zuschalten"); Serial.println("versuche Pumpe AUS zuschalten");
} }
@ -45,8 +47,11 @@ void pumpeSchalten(bool on) {
error = true; error = true;
} }
}); });
turnontime = millis();
}else{
mang.setPumpDuration(millis() - turnontime);
} }
turnontime = millis();
digitalWrite(SchuetzPin, on); digitalWrite(SchuetzPin, on);
Serial.println("[Erfolg] pumpe wird geschalten"); Serial.println("[Erfolg] pumpe wird geschalten");
} else { } else {
@ -82,6 +87,9 @@ void WasserSensorCheck() {
Serial.println("Wasser Sensor AUS"); Serial.println("Wasser Sensor AUS");
//kein Wasser dh timer auf 10min stellen //kein Wasser dh timer auf 10min stellen
// refresh wateroutage counter
mang.setlastWaterOutage(millis());
allow = false; allow = false;
Serial.println("Schalte pumpe aus"); Serial.println("Schalte pumpe aus");
pumpeSchalten(false); pumpeSchalten(false);