NTP, send Voltage to Frontend
This commit is contained in:
@@ -49,6 +49,29 @@ String getCurrentTimeJSON() {
|
||||
return response;
|
||||
}
|
||||
|
||||
void syncTimeWithNTP(const char *ntpServer = "pool.ntp.org",
|
||||
long gmtOffset_sec = 3600, int daylightOffset_sec = 0) {
|
||||
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
|
||||
Serial.println("Warte auf NTP-Zeit (max 5s)...");
|
||||
struct tm timeinfo;
|
||||
unsigned long start = millis();
|
||||
bool synced = false;
|
||||
while (millis() - start < 5000) {
|
||||
if (getLocalTime(&timeinfo, 10)) { // 10ms Timeout pro Versuch
|
||||
synced = true;
|
||||
break;
|
||||
}
|
||||
delay(10); // Kurze Pause, damit der Loop nicht blockiert
|
||||
}
|
||||
if (synced) {
|
||||
Serial.println("\nNTP-Zeit synchronisiert!");
|
||||
Serial.printf("Aktuelle Zeit: %02d:%02d:%02d\n", timeinfo.tm_hour,
|
||||
timeinfo.tm_min, timeinfo.tm_sec);
|
||||
} else {
|
||||
Serial.println("\nNTP-Sync fehlgeschlagen (Timeout nach 5s)");
|
||||
}
|
||||
}
|
||||
|
||||
// Hilfsfunktion: Setzt die Systemzeit auf den angegebenen Zeitstempel.
|
||||
bool setSystemTime(long timestamp) {
|
||||
struct timeval tv;
|
||||
|
||||
Reference in New Issue
Block a user