From 40d34dbd9cb96823e5fc645d9743469088459a55 Mon Sep 17 00:00:00 2001 From: Eric Duminil <eric.duminil@gmail.com> Date: Tue, 20 Apr 2021 12:03:09 +0200 Subject: [PATCH] Only set time when NTP didn't run --- ampel-firmware/util.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ampel-firmware/util.cpp b/ampel-firmware/util.cpp index cc2967b..e486033 100644 --- a/ampel-firmware/util.cpp +++ b/ampel-firmware/util.cpp @@ -32,13 +32,14 @@ String macToID() { namespace ntp { WiFiUDP ntpUDP; NTPClient timeClient(ntpUDP, config::ntp_server, config::utc_offset_in_seconds, 60000UL); + bool connected_at_least_once = false; void initialize() { timeClient.begin(); } void update() { - timeClient.update(); + connected_at_least_once |= timeClient.update(); } void getLocalTime(char *timestamp) { @@ -50,6 +51,9 @@ namespace ntp { timeClient.getFormattedDate(time); Serial.print(F("Current time : ")); Serial.println(time); + if (connected_at_least_once) { + Serial.println(F("NTP update already happened. Not changing anything.")); + } Serial.print(F("Setting UNIX time to : ")); Serial.println(unix_seconds); timeClient.setEpochTime(unix_seconds - seconds()); -- GitLab