Skip to content

Commit 3c0e3e7

Browse files
committed
Resync time via NTP once a day
Signed-off-by: John Walicki <[email protected]>
1 parent d9c16d6 commit 3c0e3e7

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

WatsonIoT/src/main.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -743,12 +743,12 @@ time_t periodic_timesync;
743743
// MQTT SSL requires a relatively accurate time between broker and client
744744
void SetTimeESP32() {
745745
time_t now = time(nullptr);
746-
Serial.print("Before time sync : ");
747-
Serial.println(ctime(&now));
746+
Serial.print("Before time sync: ");
747+
Serial.print(ctime(&now));
748748

749749
// Set time from NTP servers
750750
configTime(TZ_OFFSET * 3600, TZ_DST * 60, "time.nist.gov", "pool.ntp.org");
751-
Serial.println("\nWaiting for time");
751+
Serial.print("Waiting for time");
752752
while(time(nullptr) <= 100000) {
753753
NeoPixelStatus( LED_FIRMWARE_DFU ); // blink yellow
754754
Serial.print(".");
@@ -757,17 +757,17 @@ void SetTimeESP32() {
757757
unsigned timeout = 5000;
758758
unsigned start = millis();
759759
while (millis() - start < timeout) {
760-
time_t now = time(nullptr);
760+
now = time(nullptr);
761761
if (now > (2019 - 1970) * 365 * 24 * 3600) {
762762
break;
763763
}
764764
delay(100);
765765
}
766766
delay(1000); // Wait for time to fully sync
767767

768-
Serial.print("After time sync: ");
768+
Serial.print("\nAfter time sync : ");
769769
now = time(nullptr);
770-
Serial.println(ctime(&now));
770+
Serial.print(ctime(&now));
771771
periodic_timesync = now; // periodically resync the time to prevent drift
772772
}
773773

0 commit comments

Comments
 (0)