fixed incorrect reporting of unix timestamp; sync time every 12 hours
parent
1a65ef30c6
commit
809092ad92
10
src/time.cpp
10
src/time.cpp
|
@ -77,17 +77,19 @@ void uweather_time_handle()
|
|||
unsigned long high = word(packet_buffer[40], packet_buffer[41]);
|
||||
unsigned long low = word(packet_buffer[42], packet_buffer[43]);
|
||||
unsigned long secs = (high << 16 | low) - 2208988800UL; // subtract 70 years from time
|
||||
time_offset = millis();
|
||||
if (has_timestamp()) {
|
||||
Serial.printf("Time Drift: %lu\n", current_timestamp() - secs);
|
||||
}
|
||||
time_offset = millis()/1000;
|
||||
ntp_timestamp = secs;
|
||||
ntp_state = state::IDLE;
|
||||
Serial.printf("Received NTP response, current timestamp is %lu\n", secs);
|
||||
retry_at = millis() + 6 * 60 * 60 * 1000;
|
||||
}
|
||||
case state::IDLE:
|
||||
break;
|
||||
|
||||
case state::NO_HOST:
|
||||
if (millis() > retry_at) {
|
||||
state::INIT;
|
||||
ntp_state = state::INIT;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -6,5 +6,6 @@ void uweather_time_handle();
|
|||
|
||||
unsigned long timestamp(unsigned long);
|
||||
unsigned long current_timestamp();
|
||||
bool has_timestamp();
|
||||
|
||||
#endif /** End _UWEATHER_NTP_H_ include guard */
|
Loading…
Reference in New Issue