update time daily at 4 AM using task

This commit is contained in:
Nicu Hodos 2024-06-01 21:58:57 +02:00
parent 8f706fe32f
commit 8a955fa43a
3 changed files with 5 additions and 5 deletions

View File

@ -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);

View File

@ -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();
}
}

View File

@ -84,7 +84,7 @@ void onWifiConnected() {
Wifi::printStatus();
Ota::tLoop.enable();
Mqtt::tReConnect.enable();
Ntp::updateTime();
Ntp::tUpdateTime.enable();
}
void checkWifiCallback() {