diff --git a/src/time.cpp b/src/time.cpp index ee24b87..1f04af0 100644 --- a/src/time.cpp +++ b/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: diff --git a/src/time.h b/src/time.h index 2a7ea23..1efac58 100644 --- a/src/time.h +++ b/src/time.h @@ -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 */ \ No newline at end of file