OTA flashing is disabling deepsleep at start

This commit is contained in:
c3ma 2020-10-21 16:43:26 +02:00
parent 94c78bd571
commit 9b27df7172

View File

@ -17,6 +17,7 @@
#include "esp_sleep.h" #include "esp_sleep.h"
#include "RunningMedian.h" #include "RunningMedian.h"
#include <arduino-timer.h> #include <arduino-timer.h>
#include <stdint.h>
const unsigned long TEMPREADCYCLE = 30000; /**< Check temperature all half minutes */ const unsigned long TEMPREADCYCLE = 30000; /**< Check temperature all half minutes */
@ -305,9 +306,6 @@ void readSensors() {
digitalWrite(OUTPUT_SENSOR, LOW); digitalWrite(OUTPUT_SENSOR, LOW);
} }
//Homie.getMqttClient().disconnect(); //Homie.getMqttClient().disconnect();
void onHomieEvent(const HomieEvent& event) { void onHomieEvent(const HomieEvent& event) {
@ -333,6 +331,17 @@ void onHomieEvent(const HomieEvent& event) {
Homie.getLogger() << "rtsleep" << endl; Homie.getLogger() << "rtsleep" << endl;
esp_deep_sleep_start(); esp_deep_sleep_start();
break; break;
case HomieEventType::OTA_STARTED:
Serial.println("OTA DS Disabled");
mode3Active=true;
break;
case HomieEventType::OTA_SUCCESSFUL:
Serial.println("OTA DS reenabled");
mode3Active=false;
break;
default:
printf("Event %d\r\n", (uint8_t) event.type);
break;
} }
} }
@ -415,13 +424,13 @@ bool switchGeneralPumpHandler(const int pump, const HomieRange& range, const Str
*/ */
bool aliveHandler(const HomieRange& range, const String& value) { bool aliveHandler(const HomieRange& range, const String& value) {
if (range.isRange) return false; // only one controller is present if (range.isRange) return false; // only one controller is present
Serial << value << endl;
if (value.equals("ON") || value.equals("On") || value.equals("1")) { if (value.equals("ON") || value.equals("On") || value.equals("1")) {
mode3Active=true; mode3Active=true;
} else { } else {
mode3Active=false; mode3Active=false;
esp_deep_sleep_start();
} }
Serial << (mode3Active ? "stayalive" : "") << endl;
return true; return true;
} }
@ -690,9 +699,12 @@ void setup() {
void loop() { void loop() {
Homie.loop(); Homie.loop();
if(mode3Active){
digitalWrite(OUTPUT_SENSOR, HIGH);
}
if(millis() > 30000 && !mode3Active){ if(millis() > 30000 && !mode3Active){
Serial << (millis()/ 1000) << " ds watchdog" << endl; Serial << (millis()/ 1000) << "s gone" << endl;
Serial.flush(); Serial.flush();
esp_deep_sleep_start(); esp_deep_sleep_start();
} }