boolean syncEventTriggered = false; NTPSyncEvent_t ntpEvent; void startNTPSync() { Serial.println("Starting NTP synchronization"); NTP.onNTPSyncEvent([](NTPSyncEvent_t event) { ntpEvent = event; syncEventTriggered = true; }); NTP.begin("pool.ntp.org", 1, true); NTP.setInterval(5, 3600); } void updateNtpTime() { if (syncEventTriggered) { processSyncEvent(ntpEvent); syncEventTriggered = false; } } void stopNTPSync() { NTP.stop(); } void processSyncEvent(NTPSyncEvent_t ntpEvent) { if (ntpEvent) { Serial.print("Time Sync error: "); if (ntpEvent == noResponse) Serial.println("NTP server not reachable"); else if (ntpEvent == invalidAddress) Serial.println("Invalid NTP server address"); } else { syncNtpRtc = true; } }