From 99f680da57a2115ee0a7c3f4ac42913c297e3f19 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Fri, 5 Jul 2019 11:47:13 +0200 Subject: [PATCH] Add NTP drift information Add NTP drift information --- sonoff/sonoff.ino | 3 ++- sonoff/support_rtc.ino | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 02ea25524..dd564827a 100755 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -2013,7 +2013,8 @@ void PerformEverySecond(void) if (ntp_synced_message) { // Moved here to fix syslog UDP exception 9 during RtcSecond - AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION "(" D_UTC_TIME ") %s, (" D_DST_TIME ") %s, (" D_STD_TIME ") %s"), GetTime(0).c_str(), GetTime(2).c_str(), GetTime(3).c_str()); + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("NTP: Drift %d, (" D_UTC_TIME ") %s, (" D_DST_TIME ") %s, (" D_STD_TIME ") %s"), + DriftTime(), GetTime(0).c_str(), GetTime(2).c_str(), GetTime(3).c_str()); ntp_synced_message = false; } diff --git a/sonoff/support_rtc.ino b/sonoff/support_rtc.ino index 03efeb510..e55bff4c5 100644 --- a/sonoff/support_rtc.ino +++ b/sonoff/support_rtc.ino @@ -46,10 +46,16 @@ uint32_t standard_time = 0; uint32_t ntp_time = 0; uint32_t midnight = 0; uint32_t restart_time = 0; +int32_t drift_time = 0; int32_t time_timezone = 0; uint8_t midnight_now = 0; uint8_t ntp_sync_minute = 0; +int32_t DriftTime(void) +{ + return drift_time; +} + String GetBuildDateAndTime(void) { // "2017-03-07T11:08:02" - ISO8601:2004 @@ -356,6 +362,7 @@ void RtcSecond(void) ntp_time = sntp_get_current_timestamp(); if (ntp_time > 1451602800) { // Fix NTP bug in core 2.4.1/SDK 2.2.1 (returns Thu Jan 01 08:00:10 1970 after power on) ntp_force_sync = false; + if (utc_time > 1451602800) { drift_time = ntp_time - utc_time; } utc_time = ntp_time; ntp_sync_minute = 60; // Sync so block further requests if (restart_time == 0) {