diff --git a/include/display.h b/include/display.h index a3c01c1..049d34a 100644 --- a/include/display.h +++ b/include/display.h @@ -83,7 +83,7 @@ namespace Display { if (currentHour != hour()) { currentHour = hour(); if (currentHour == 4) { - Ntp::updateTime(); + Ntp::tUpdateTime.restart(); } if (currentHour == 8) { Brightness::set(BRIGHTNESS_DAY); diff --git a/include/ntp_time.h b/include/ntp_time.h index b9fcbe0..fca16af 100644 --- a/include/ntp_time.h +++ b/include/ntp_time.h @@ -14,16 +14,16 @@ namespace Ntp { TimeChangeRule CET = { "CET ", Last, Sun, Oct, 3, 60 }; // Central European Standard Time Timezone CE(CEST, CET); - void updateTime() { + Task tUpdateTime(TASK_IMMEDIATE, TASK_ONCE, []{ if (timeClient.forceUpdate()) { time_t newTime = CE.toLocal(timeClient.getEpochTime()); setTime(newTime); Serial.println(asctime(localtime(&newTime))); } - } + }, &ts); void setup() { - timeClient.begin(); Serial.println("NTP setup"); + timeClient.begin(); } } \ No newline at end of file diff --git a/src/esp_clock.cpp b/src/esp_clock.cpp index d422d77..7b0ad8c 100644 --- a/src/esp_clock.cpp +++ b/src/esp_clock.cpp @@ -84,7 +84,7 @@ void onWifiConnected() { Wifi::printStatus(); Ota::tLoop.enable(); Mqtt::tReConnect.enable(); - Ntp::updateTime(); + Ntp::tUpdateTime.enable(); } void checkWifiCallback() {