update time daily at 4 AM

This commit is contained in:
Nicu Hodos 2024-06-01 15:10:33 +02:00
parent b02c731e95
commit 8f706fe32f
3 changed files with 6 additions and 7 deletions

View File

@ -82,6 +82,9 @@ namespace Display {
static int currentHour = -1;
if (currentHour != hour()) {
currentHour = hour();
if (currentHour == 4) {
Ntp::updateTime();
}
if (currentHour == 8) {
Brightness::set(BRIGHTNESS_DAY);
Wifi::reconnect();

View File

@ -14,13 +14,11 @@ namespace Ntp {
TimeChangeRule CET = { "CET ", Last, Sun, Oct, 3, 60 }; // Central European Standard Time
Timezone CE(CEST, CET);
time_t updateTime() {
void updateTime() {
if (timeClient.forceUpdate()) {
time_t newTime = CE.toLocal(timeClient.getEpochTime());
setTime(newTime);
return newTime;
} else {
return 0;
Serial.println(asctime(localtime(&newTime)));
}
}

View File

@ -84,9 +84,7 @@ void onWifiConnected() {
Wifi::printStatus();
Ota::tLoop.enable();
Mqtt::tReConnect.enable();
if (time_t newTime = Ntp::updateTime()) {
Serial.println(asctime(localtime(&newTime)));
}
Ntp::updateTime();
}
void checkWifiCallback() {