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
......@@ -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());
......
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