From c6871fc401f457d386e5eee2458572beec603093 Mon Sep 17 00:00:00 2001 From: Ollo Date: Tue, 20 Oct 2020 18:40:24 +0200 Subject: [PATCH] Timer added --- esp32/platformio.ini | 2 +- esp32/src/main.cpp | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/esp32/platformio.ini b/esp32/platformio.ini index 1b0fc90..e775a5e 100644 --- a/esp32/platformio.ini +++ b/esp32/platformio.ini @@ -18,5 +18,5 @@ board_build.partitions = huge_app.csv ; the latest development brankitchen-lightch (convention V3.0.x) lib_deps = https://github.com/homieiot/homie-esp8266.git#v3.0 OneWire - + upload_port = /dev/ttyUSB0 diff --git a/esp32/src/main.cpp b/esp32/src/main.cpp index e382672..91664b4 100644 --- a/esp32/src/main.cpp +++ b/esp32/src/main.cpp @@ -16,6 +16,7 @@ #include "time.h" #include "esp_sleep.h" #include "RunningMedian.h" +#include const unsigned long TEMPREADCYCLE = 30000; /**< Check temperature all half minutes */ @@ -66,6 +67,9 @@ int readCounter = 0; int mButtonClicks = 0; bool mConfigured = false; + +auto wait4sleep = timer_create_default(); // create a timer with default settings + RTC_DATA_ATTR int gBootCount = 0; RTC_DATA_ATTR int gCurrentPlant = 0; /**< Value Range: 1 ... 7 (0: no plant needs water) */ @@ -105,9 +109,10 @@ long getCurrentTime(){ } //wait till homie flushed mqtt ect. -void prepareSleep() { +bool prepareSleep(void *) { //FIXME wait till pending mqtt is done, then start sleep via event or whatever //Homie.prepareToSleep(); + return true; // repeat? true there is something in the queue to be done } void mode2MQTT(){ @@ -128,7 +133,8 @@ void mode2MQTT(){ /* let the ESP sleep qickly, as nothing must be done */ if ((millis() >= (MIN_TIME_RUNNING * MS_TO_S)) && (deepSleepTime.get() > 0)) { Serial << "No Water for pumps" << endl; - t.after(50, prepareSleep); + /* in 500 microseconds */ + wait4sleep.in(500, prepareSleep); return; } } @@ -156,7 +162,7 @@ void mode2MQTT(){ bool lipoTempWarning = abs(temp[1] - temp[2]) > 5; if(lipoTempWarning){ - t.after(50, prepareSleep); + wait4sleep.in(500, prepareSleep); return; }