From 712c58c18e5399416650a356c39d4ee6f8dfd9db Mon Sep 17 00:00:00 2001 From: bitsy <36607587+bitsy@users.noreply.github.com> Date: Sun, 16 Sep 2018 21:11:26 -0700 Subject: [PATCH 1/6] Update NTPClient.cpp The NTPClient method update() has been changed to only return "TRUE" after a successful update. The following conditions return "FALSE": - Interval duration requirement not met - forceUpdate() times out --- NTPClient.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NTPClient.cpp b/NTPClient.cpp index 87b7a53..79924c7 100644 --- a/NTPClient.cpp +++ b/NTPClient.cpp @@ -89,7 +89,7 @@ bool NTPClient::forceUpdate() { this->_currentEpoc = secsSince1900 - SEVENZYYEARS; - return true; + return true; // return true after successful update } bool NTPClient::update() { @@ -98,7 +98,7 @@ bool NTPClient::update() { if (!this->_udpSetup) this->begin(); // setup the UDP client if needed return this->forceUpdate(); } - return true; + return false; // return false if update does not occur } unsigned long NTPClient::getEpochTime() const { From cfbe88a3e2df5b916d4a7146fa0a83dacf88bd39 Mon Sep 17 00:00:00 2001 From: James Brown Date: Sat, 12 Jan 2019 13:32:05 -0700 Subject: [PATCH 2/6] Added packet flush before request in forceUpdate(). Fixes issue #49 in the upstream repo --- NTPClient.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NTPClient.cpp b/NTPClient.cpp index 87b7a53..668d72b 100644 --- a/NTPClient.cpp +++ b/NTPClient.cpp @@ -65,6 +65,10 @@ bool NTPClient::forceUpdate() { Serial.println("Update from NTP Server"); #endif + // flush any existing packets + while(this->_udp->parsePacket() != 0) + this->_udp->flush(); + this->sendNTPPacket(); // Wait till data is there or timeout... From 151bbc5484265cbeeb0273a3752a95aedda22f2f Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Wed, 18 Sep 2019 10:01:20 +0200 Subject: [PATCH 3/6] Releasing v3.2.0 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index d4908ca..309b75d 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=NTPClient -version=3.1.0 +version=3.2.0 author=Fabrice Weinberg maintainer=Fabrice Weinberg sentence=An NTPClient to connect to a time server From 9c16cb728bbda2eb5e60781d9cbb8985e6f58207 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Thu, 19 Sep 2019 07:29:51 +0200 Subject: [PATCH 4/6] Adding documentation of function 'getEpochTime' to README --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 6c8c07a..46f9eb5 100644 --- a/README.md +++ b/README.md @@ -45,3 +45,6 @@ void loop() { delay(1000); } ``` + +## Function documentation +`getEpochTime` returns the unix epoch, which are the seconds elapsed since 00:00:00 UTC on 1 January 1970 (leap seconds are ignored, every day is treated as having 86400 seconds). **Attention**: If you have set a time offset this time offset will be added to your epoch timestamp. From 931c47169776418cc499e5195f60f6a8f18bee64 Mon Sep 17 00:00:00 2001 From: sheffieldnick Date: Wed, 26 Apr 2017 15:14:37 +0100 Subject: [PATCH 5/6] Added support for server IPAddress argument to NTPClient --- NTPClient.cpp | 8 +++++++- NTPClient.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) mode change 100644 => 100755 NTPClient.cpp mode change 100644 => 100755 NTPClient.h diff --git a/NTPClient.cpp b/NTPClient.cpp old mode 100644 new mode 100755 index 6133508..f2d484f --- a/NTPClient.cpp +++ b/NTPClient.cpp @@ -35,7 +35,13 @@ NTPClient::NTPClient(UDP& udp, const char* poolServerName) { this->_poolServerName = poolServerName; } -NTPClient::NTPClient(UDP& udp, const char* poolServerName, long timeOffset) { +NTPClient::NTPClient(UDP& udp, IPAddress poolServerIP) { + this->_udp = &udp; + this->_poolServerIP = poolServerIP; + this->_poolServerName = NULL; +} + +NTPClient::NTPClient(UDP& udp, const char* poolServerName, int timeOffset) { this->_udp = &udp; this->_timeOffset = timeOffset; this->_poolServerName = poolServerName; diff --git a/NTPClient.h b/NTPClient.h old mode 100644 new mode 100755 index 02d8752..08c6ee1 --- a/NTPClient.h +++ b/NTPClient.h @@ -30,6 +30,7 @@ class NTPClient { NTPClient(UDP& udp); NTPClient(UDP& udp, long timeOffset); NTPClient(UDP& udp, const char* poolServerName); + NTPClient(UDP& udp, IPAddress poolServerIP); NTPClient(UDP& udp, const char* poolServerName, long timeOffset); NTPClient(UDP& udp, const char* poolServerName, long timeOffset, unsigned long updateInterval); From a80086968a0dfcf0f7d9f336facd1fc09cfa9b58 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Thu, 19 Sep 2019 10:10:00 +0200 Subject: [PATCH 6/6] Fixing function signature error of 'NTPClient(UDP& udp, const char* poolServerName, long timeOffset)' (long timeOffset instead of int timeOffset) and adding the overloaded ctors also for an IPAddress --- NTPClient.cpp | 25 ++++++++++++++++++++++--- NTPClient.h | 5 ++++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/NTPClient.cpp b/NTPClient.cpp index f2d484f..fffe105 100755 --- a/NTPClient.cpp +++ b/NTPClient.cpp @@ -37,16 +37,23 @@ NTPClient::NTPClient(UDP& udp, const char* poolServerName) { NTPClient::NTPClient(UDP& udp, IPAddress poolServerIP) { this->_udp = &udp; - this->_poolServerIP = poolServerIP; + this->_poolServerIP = poolServerIP; this->_poolServerName = NULL; } -NTPClient::NTPClient(UDP& udp, const char* poolServerName, int timeOffset) { +NTPClient::NTPClient(UDP& udp, const char* poolServerName, long timeOffset) { this->_udp = &udp; this->_timeOffset = timeOffset; this->_poolServerName = poolServerName; } +NTPClient::NTPClient(UDP& udp, IPAddress poolServerIP, long timeOffset){ + this->_udp = &udp; + this->_timeOffset = timeOffset; + this->_poolServerIP = poolServerIP; + this->_poolServerName = NULL; +} + NTPClient::NTPClient(UDP& udp, const char* poolServerName, long timeOffset, unsigned long updateInterval) { this->_udp = &udp; this->_timeOffset = timeOffset; @@ -54,6 +61,14 @@ NTPClient::NTPClient(UDP& udp, const char* poolServerName, long timeOffset, unsi this->_updateInterval = updateInterval; } +NTPClient::NTPClient(UDP& udp, IPAddress poolServerIP, long timeOffset, unsigned long updateInterval) { + this->_udp = &udp; + this->_timeOffset = timeOffset; + this->_poolServerIP = poolServerIP; + this->_poolServerName = NULL; + this->_updateInterval = updateInterval; +} + void NTPClient::begin() { this->begin(NTP_DEFAULT_LOCAL_PORT); } @@ -179,7 +194,11 @@ void NTPClient::sendNTPPacket() { // all NTP fields have been given values, now // you can send a packet requesting a timestamp: - this->_udp->beginPacket(this->_poolServerName, 123); //NTP requests are to port 123 + if (this->_poolServerName) { + this->_udp->beginPacket(this->_poolServerName, 123); + } else { + this->_udp->beginPacket(this->_poolServerIP, 123); + } this->_udp->write(this->_packetBuffer, NTP_PACKET_SIZE); this->_udp->endPacket(); } diff --git a/NTPClient.h b/NTPClient.h index 08c6ee1..20ec43b 100755 --- a/NTPClient.h +++ b/NTPClient.h @@ -14,6 +14,7 @@ class NTPClient { bool _udpSetup = false; const char* _poolServerName = "pool.ntp.org"; // Default time server + IPAddress _poolServerIP; int _port = NTP_DEFAULT_LOCAL_PORT; long _timeOffset = 0; @@ -30,9 +31,11 @@ class NTPClient { NTPClient(UDP& udp); NTPClient(UDP& udp, long timeOffset); NTPClient(UDP& udp, const char* poolServerName); - NTPClient(UDP& udp, IPAddress poolServerIP); NTPClient(UDP& udp, const char* poolServerName, long timeOffset); NTPClient(UDP& udp, const char* poolServerName, long timeOffset, unsigned long updateInterval); + NTPClient(UDP& udp, IPAddress poolServerIP); + NTPClient(UDP& udp, IPAddress poolServerIP, long timeOffset); + NTPClient(UDP& udp, IPAddress poolServerIP, long timeOffset, unsigned long updateInterval); /** * Set time server name