Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an overloaded method for updateNTP returns mS correction amount #95

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/ezTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,23 +371,30 @@ namespace ezt {
#ifdef EZTIME_NETWORK_ENABLE

void updateNTP() {
updateNTP(nullptr);
}

void updateNTP(int32_t *correction) {
deleteEvent(updateNTP); // Delete any events pointing here, in case called manually
time_t t;
unsigned long measured_at;
if (queryNTP(_ntp_server, t, measured_at)) {
int32_t correction = ( (t - _last_sync_time) * 1000 ) - ( measured_at - _last_sync_millis );
int32_t lcorrection = ( (t - _last_sync_time) * 1000 ) - ( measured_at - _last_sync_millis );
if (correction) {
*correction = lcorrection;
}
_last_sync_time = t;
_last_sync_millis = measured_at;
_last_read_ms = ( millis() - measured_at) % 1000;
info(F("Received time: "));
info(UTC.dateTime(t, F("l, d-M-y H:i:s.v T")));
if (_time_status != timeNotSet) {
info(F(" (internal clock was "));
if (!correction) {
if (!lcorrection) {
infoln(F("spot on)"));
} else {
info(String(abs(correction)));
if (correction > 0) {
info(String(abs(lcorrection)));
if (lcorrection > 0) {
infoln(F(" ms fast)"));
} else {
infoln(F(" ms slow)"));
Expand Down
1 change: 1 addition & 0 deletions src/ezTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ namespace ezt {
void setInterval(const uint16_t seconds = 0);
void setServer(const String ntp_server = NTP_SERVER);
void updateNTP();
void updateNTP(int32_t *correction);
bool waitForSync(const uint16_t timeout = 0);
time_t lastNtpUpdateTime();
#endif
Expand Down