Commit 40d34dbd authored by Eric Duminil's avatar Eric Duminil
Browse files

Only set time when NTP didn't run

parent 917d1df9
Pipeline #2940 passed with stage
in 1 minute and 38 seconds
Showing with 5 additions and 1 deletion
+5 -1
...@@ -32,13 +32,14 @@ String macToID() { ...@@ -32,13 +32,14 @@ String macToID() {
namespace ntp { namespace ntp {
WiFiUDP ntpUDP; WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, config::ntp_server, config::utc_offset_in_seconds, 60000UL); NTPClient timeClient(ntpUDP, config::ntp_server, config::utc_offset_in_seconds, 60000UL);
bool connected_at_least_once = false;
void initialize() { void initialize() {
timeClient.begin(); timeClient.begin();
} }
void update() { void update() {
timeClient.update(); connected_at_least_once |= timeClient.update();
} }
void getLocalTime(char *timestamp) { void getLocalTime(char *timestamp) {
...@@ -50,6 +51,9 @@ namespace ntp { ...@@ -50,6 +51,9 @@ namespace ntp {
timeClient.getFormattedDate(time); timeClient.getFormattedDate(time);
Serial.print(F("Current time : ")); Serial.print(F("Current time : "));
Serial.println(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.print(F("Setting UNIX time to : "));
Serial.println(unix_seconds); Serial.println(unix_seconds);
timeClient.setEpochTime(unix_seconds - seconds()); timeClient.setEpochTime(unix_seconds - seconds());
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment