diff --git a/include/bmp.h b/include/bmp.h index 4fcdf65..5c4f5c4 100644 --- a/include/bmp.h +++ b/include/bmp.h @@ -22,7 +22,7 @@ namespace Bmp { void setup() { Serial.begin(9600); - Serial.println(F("BMP280 test")); + Serial.println(F("BMP280 setup")); if (!bmp.begin(0x76)) { Serial.println(F("Could not find a valid BMP280 sensor, check wiring!")); diff --git a/include/ir.h b/include/ir.h index 5a4b46c..3714d28 100644 --- a/include/ir.h +++ b/include/ir.h @@ -39,7 +39,7 @@ namespace Ir { void command(const char c[]) { avrOn = true; - tCheckWifi.disable(); + tCheckWifi.cancel(); Wifi::reconnect(); Display::displayText(c); } @@ -50,7 +50,7 @@ namespace Ir { { case 0x9F: avrOn = false; - tCheckWifi.enableDelayed(); + tCheckWifi.restartDelayed(); Display::displayText("Off"); break; case 0x12: diff --git a/include/ntp_time.h b/include/ntp_time.h index 34f20c8..f02b35a 100644 --- a/include/ntp_time.h +++ b/include/ntp_time.h @@ -8,7 +8,6 @@ namespace Ntp { WiFiUDP ntpUDP; NTPClient timeClient(ntpUDP, "europe.pool.ntp.org"); - time_t lastConnectedTime; // Central European Time (Frankfurt, Paris) TimeChangeRule CEST = { "CEST", Last, Sun, Mar, 2, 120 }; // Central European Summer Time diff --git a/src/esp_clock.cpp b/src/esp_clock.cpp index f3ad33a..b0221b1 100644 --- a/src/esp_clock.cpp +++ b/src/esp_clock.cpp @@ -5,10 +5,9 @@ void onWifiConnected(); void onButtonPressed(); void onButtonCallback(); -// #define _TASK_STATUS_REQUEST #include Scheduler ts; -Task tCheckWifi(5 * TASK_SECOND, TASK_FOREVER, checkWifiCallback, &ts); +Task tCheckWifi(5 * TASK_MINUTE, TASK_ONCE, checkWifiCallback, &ts); Task tWifiConnected(TASK_IMMEDIATE, TASK_ONCE, onWifiConnected, &ts); Task tButton(TASK_IMMEDIATE, TASK_ONCE, onButtonCallback, &ts); @@ -20,9 +19,9 @@ Task tButton(TASK_IMMEDIATE, TASK_ONCE, onButtonCallback, &ts); #include "ota.h" #include "ir.h" -#define STAY_CONNECTED_AFTER_BOOT 5*60 #define BUTTON D3 + void setup() { Serial.begin(9600); @@ -48,22 +47,18 @@ void onWifiConnected() { Serial.println("Wifi connected event"); Wifi::printStatus(); Ota::tLoop.enable(); - if (!Ir::avrOn) tCheckWifi.enableDelayed(); + if (!Ir::avrOn) tCheckWifi.restartDelayed(); Mqtt::client.connect(); if (time_t newTime = Ntp::updateTime()) { Serial.println(asctime(localtime(&newTime))); - Ntp::lastConnectedTime = newTime; } } void checkWifiCallback() { - if (difftime(now(), Ntp::lastConnectedTime) > STAY_CONNECTED_AFTER_BOOT) { - Serial.println("Wifi connection timed out"); - Mqtt::client.disconnect(); - Ota::tLoop.disable(); - tCheckWifi.disable(); - Wifi::disconnect(); - } + Serial.println("Wifi connection timed out"); + Mqtt::client.disconnect(); + Ota::tLoop.disable(); + Wifi::disconnect(); } ICACHE_RAM_ATTR void onButtonPressed() {