Controller will stay alive if it has to

This commit is contained in:
Ollo 2020-10-13 21:47:56 +02:00
parent 7991a37d4d
commit 089476facc

View File

@ -240,7 +240,6 @@ void loopHandler() {
/* Pump is running, go to sleep after defined time */ /* Pump is running, go to sleep after defined time */
if (millis() >= ((MIN_TIME_RUNNING + 5) && if (millis() >= ((MIN_TIME_RUNNING + 5) &&
(deepSleepTime.get() > 0))) { (deepSleepTime.get() > 0))) {
Serial << "No sleeping activated (maximum)" << endl;
mDeepSleep = true; mDeepSleep = true;
} else if ((millis() >= ((MIN_TIME_RUNNING * MS_TO_S) + 0)) && } else if ((millis() >= ((MIN_TIME_RUNNING * MS_TO_S) + 0)) &&
(deepSleepTime.get() > 0)) { (deepSleepTime.get() > 0)) {
@ -303,7 +302,7 @@ bool aliveHandler(const HomieRange& range, const String& value) {
} else { } else {
mAlive=false; mAlive=false;
} }
Serial << "Controller " << (mAlive ? " has coffee" : " is tired") << endl; Serial << "HOMIE | Controller " << (mAlive ? " has coffee" : " is tired") << endl;
return true; return true;
} }
@ -502,7 +501,7 @@ void setup() {
.setUnit("V"); .setUnit("V");
sensorWater.advertise("remaining").setDatatype("number").setUnit("%"); sensorWater.advertise("remaining").setDatatype("number").setUnit("%");
stayAlive.advertise("stay").setName("Alive").setDatatype("number").settable(aliveHandler); stayAlive.advertise("alive").setName("Alive").setDatatype("number").settable(aliveHandler);
} }
Homie.setup(); Homie.setup();
@ -669,8 +668,17 @@ void loop() {
} }
} else { } else {
Serial << (millis()/ 1000) << "s running; sleeeping ..." << endl; if (!mAlive) {
Serial.flush(); Serial << (millis()/ 1000) << "s running; sleeeping ..." << endl;
esp_deep_sleep_start(); Serial.flush();
esp_deep_sleep_start();
} else {
mDeepSleep = false;
if (((millis()) % 10000) == 0) {
/* tell everybody how long we are awoken */
stayAlive.setProperty("alive").send( String(millis()/ 1000) );
}
}
} }
} }