File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change 35
35
if (LOG_L2) \
36
36
Serial.println(x);
37
37
38
- #define CONNECTION_TO 6000 //ms
38
+ #define CONNECTION_TO 6000 //ms
39
39
#define RECONNECTION_TO 10000 //ms
40
+ #define RESYNCTIME 86400 // Resync the ESP32 time once a day
40
41
41
42
#define PRODUCTION_BOARD 1
Original file line number Diff line number Diff line change @@ -739,8 +739,13 @@ void NetworkEvent(WiFiEvent_t event) {
739
739
}
740
740
741
741
742
+ time_t periodic_timesync;
742
743
// MQTT SSL requires a relatively accurate time between broker and client
743
744
void SetTimeESP32 () {
745
+ time_t now = time (nullptr );
746
+ Serial.print (" Before time sync : " );
747
+ Serial.println (ctime (&now));
748
+
744
749
// Set time from NTP servers
745
750
configTime (TZ_OFFSET * 3600 , TZ_DST * 60 , " time.nist.gov" , " pool.ntp.org" );
746
751
Serial.println (" \n Waiting for time" );
@@ -759,9 +764,11 @@ void SetTimeESP32() {
759
764
delay (100 );
760
765
}
761
766
delay (1000 ); // Wait for time to fully sync
762
- Serial.println (" Time sync'd" );
763
- time_t now = time (nullptr );
767
+
768
+ Serial.print (" After time sync: " );
769
+ now = time (nullptr );
764
770
Serial.println (ctime (&now));
771
+ periodic_timesync = now; // periodically resync the time to prevent drift
765
772
}
766
773
767
774
@@ -1048,6 +1055,11 @@ void loop() {
1048
1055
if ( adxstatus )
1049
1056
NeoPixelBreathe ();
1050
1057
1058
+ if ( (time (nullptr ) - periodic_timesync) > RESYNCTIME ) {
1059
+ // Resync the ESP32 time once a day so that MQTT and Seismology time is accurate
1060
+ SetTimeESP32 ();
1061
+ }
1062
+
1051
1063
delay (10 );
1052
1064
}
1053
1065
You can’t perform that action at this time.
0 commit comments