move turnontime back to on and off context

live view of pressure and watersensor
This commit is contained in:
Lukas Heiligenbrunner 2020-08-02 11:31:36 +00:00
parent aaf73b2dd7
commit 0261f186bd
3 changed files with 35 additions and 17 deletions

View File

@ -8,7 +8,7 @@
void WifiManager::init() {
Serial.print("Setting up Access Point");
// start softap
boolean result = WiFi.softAP("PumpenSteuerung-Heiligenbrunner", "1qayxsw2");
const bool result = WiFi.softAP("PumpenSteuerung-Heiligenbrunner", "1qayxsw2");
if (result == true) {
Serial.println("Wifi Ready");
Serial.println(WiFi.softAPIP());
@ -25,7 +25,7 @@ void WifiManager::init() {
handleNotFound();
});
// server available at 192.168.2.1
// server available at 192.168.4.1
server.begin();
} else {
Serial.println("Wifi Setup failed!");
@ -37,30 +37,33 @@ WifiManager::WifiManager() : server(80), lastPumpTime(0), lastWaterOutage(0), la
void WifiManager::handleRoot() {
Serial.println("HomePage called");
// read maxpumptime from eeprom
int value = 0;
EEPROM.begin(4096); // init the eeprom
EEPROM.get(0, value);
EEPROM.end(); // stop the eeprom communication
bool pumptimeset = this->lastPumpTime != 0;
bool wateroutageset = this->lastWaterOutage != 0;
bool pumpdurationset = this->lastPumpDuration != 0;
const bool pumptimeset = this->lastPumpTime != 0;
const bool wateroutageset = this->lastWaterOutage != 0;
const 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
const unsigned long pumptime = pumptimeset ? (millis() - this->lastPumpTime) / 1000 : 0; // in sec
const unsigned long wateroutagetime = wateroutageset ? (millis() - this->lastWaterOutage) / 1000 : 0; // in sec
const 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) +
" <div>Aktuelle Max-Pumpzeit: " + 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";
// append last pump pump cycle
if (pumptimeset) {
index_html += "<div>Zeit seit letztem einschalten: " +
String(pumptime / (60 * 60)) + "Stunden " +
@ -70,6 +73,7 @@ void WifiManager::handleRoot() {
index_html += "<div>Zeit seit letztem einschalten: -</div>";
}
// append last water outage info
if (wateroutageset) {
index_html += "<div>Zeit seit letzem Wasserausfall: " +
String(wateroutagetime / (60 * 60 * 24)) + "Tage " +
@ -79,6 +83,7 @@ void WifiManager::handleRoot() {
index_html += "<div>Zeit seit letzem Wasserausfall: -</div>";
}
// append pump run duration
if (pumpdurationset) {
index_html += "<div>Pumpe lief zuletzt: " +
String(pumpduration / 60) + "Minuten " +
@ -86,14 +91,20 @@ void WifiManager::handleRoot() {
} else {
index_html += "<div>Pumpe lief zuletzt: -</div>";
}
unsigned long currtime = millis() / 1000;
// append chip alive time
const 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>";
String((currtime % 60)) + "Sekunden </div></br>";
// read live sensor values
index_html += "<div>Drucksensor: " + String((digitalRead(DruckSensorPin) ? "EIN" : "AUS")) + "</div>";
index_html += "<div>Wassersensor: " + String((digitalRead(WasserSensorPin) ? "EIN" : "AUS")) + "</div>";
index_html += "</body></html>";
server.send(200, "text/html", index_html);
}
@ -105,7 +116,7 @@ void WifiManager::handleNotFound() {
void WifiManager::handleGet() {
Serial.println("get called");
String s = "<!DOCTYPE HTML><html><head>\n"
const String s = "<!DOCTYPE HTML><html><head>\n"
" <title>Wastinfoboard-ConfigurationPage</title>\n"
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n"
" <meta http-equiv=\"refresh\" content=\"0; URL=/\">\n"

View File

@ -23,6 +23,10 @@ public:
void setPumpDuration(unsigned long lastPumpDuration);
private:
// todo more dynamic
static const uint8_t WasserSensorPin = 14;
static const uint8_t DruckSensorPin = 12;
ESP8266WebServer server;
void handleRoot();

View File

@ -39,7 +39,8 @@ void pumpeSchalten(bool on) {
if (allow && !error) {
if (on) {
pumpendauer.once(maxpumpdauer + 1, []() { //erlaube keine einschaltung von mehr als 60 sek
pumpendauer.once(maxpumpdauer + 1, []() {
//erlaube keine einschaltung von mehr als 60 sek
if (millis() - turnontime >= maxpumpdauer * 1000 && turnontime != -1) {
//error zu lange
Serial.println("\n\npumpe lief mehr als 10 Minuten durchgaengig");
@ -47,11 +48,13 @@ void pumpeSchalten(bool on) {
error = true;
}
});
turnontime = millis();
} else {
mang.setPumpDuration(millis() - turnontime);
}
// save pump start time
turnontime = millis();
digitalWrite(SchuetzPin, on);
Serial.println("[Erfolg] pumpe wird geschalten");
} else {