From 0825e0cc0780ae2b25ae54ebc83e61758a2f2b1c Mon Sep 17 00:00:00 2001 From: pabloandresm Date: Mon, 27 Mar 2017 11:17:43 -0400 Subject: [PATCH 1/7] fixes updateInterval & lastUpdate variable type --- NTPClient.cpp | 4 ++-- NTPClient.h | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/NTPClient.cpp b/NTPClient.cpp index 7b1a4e2..def941e 100644 --- a/NTPClient.cpp +++ b/NTPClient.cpp @@ -41,7 +41,7 @@ NTPClient::NTPClient(UDP& udp, const char* poolServerName, int timeOffset) { this->_poolServerName = poolServerName; } -NTPClient::NTPClient(UDP& udp, const char* poolServerName, int timeOffset, int updateInterval) { +NTPClient::NTPClient(UDP& udp, const char* poolServerName, int timeOffset, unsigned long updateInterval) { this->_udp = &udp; this->_timeOffset = timeOffset; this->_poolServerName = poolServerName; @@ -144,7 +144,7 @@ void NTPClient::setTimeOffset(int timeOffset) { this->_timeOffset = timeOffset; } -void NTPClient::setUpdateInterval(int updateInterval) { +void NTPClient::setUpdateInterval(unsigned long updateInterval) { this->_updateInterval = updateInterval; } diff --git a/NTPClient.h b/NTPClient.h index 4d5630d..78eb1dd 100644 --- a/NTPClient.h +++ b/NTPClient.h @@ -17,7 +17,7 @@ class NTPClient { int _port = NTP_DEFAULT_LOCAL_PORT; int _timeOffset = 0; - unsigned int _updateInterval = 60000; // In ms + unsigned long _updateInterval = 60000; // In ms unsigned long _currentEpoc = 0; // In s unsigned long _lastUpdate = 0; // In ms @@ -31,7 +31,7 @@ class NTPClient { NTPClient(UDP& udp, int timeOffset); NTPClient(UDP& udp, const char* poolServerName); NTPClient(UDP& udp, const char* poolServerName, int timeOffset); - NTPClient(UDP& udp, const char* poolServerName, int timeOffset, int updateInterval); + NTPClient(UDP& udp, const char* poolServerName, int timeOffset, unsigned long updateInterval); /** * Starts the underlying UDP client with the default local port @@ -72,7 +72,7 @@ class NTPClient { * Set the update interval to another frequency. E.g. useful when the * timeOffset should not be set in the constructor */ - void setUpdateInterval(int updateInterval); + void setUpdateInterval(unsigned long updateInterval); /** * @return time formatted like `hh:mm:ss` From ea200235c7049a06d4c3956199166bf551db3de8 Mon Sep 17 00:00:00 2001 From: Testato Date: Sun, 23 Jul 2017 09:05:51 +0300 Subject: [PATCH 2/7] New default server https://github.com/arduino-libraries/NTPClient/issues/34 --- NTPClient.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NTPClient.h b/NTPClient.h index 78eb1dd..cdbf55a 100644 --- a/NTPClient.h +++ b/NTPClient.h @@ -13,7 +13,7 @@ class NTPClient { UDP* _udp; bool _udpSetup = false; - const char* _poolServerName = "time.nist.gov"; // Default time server + const char* _poolServerName = "pool.ntp.org"; // Default time server int _port = NTP_DEFAULT_LOCAL_PORT; int _timeOffset = 0; From 126ea3093bc4dcf1b44e1830a1821c90fe3b3536 Mon Sep 17 00:00:00 2001 From: Testato Date: Mon, 24 Jul 2017 10:09:33 +0200 Subject: [PATCH 3/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index af9802a..6c8c07a 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ const char *password = ""; WiFiUDP ntpUDP; -// By default 'time.nist.gov' is used with 60 seconds update interval and +// By default 'pool.ntp.org' is used with 60 seconds update interval and // no offset NTPClient timeClient(ntpUDP); From 70d6ec4e9031c99fe9d6c5b3bf1604d7e1925f83 Mon Sep 17 00:00:00 2001 From: Kosh <106480+koshatul@users.noreply.github.com> Date: Wed, 27 Jun 2018 20:17:09 +1000 Subject: [PATCH 4/7] Changed timeOffset from int to long to support timezones with more than 32000 seconds difference from GMT (eg, Australia +10 (36000)) (#42) --- NTPClient.cpp | 6 +++--- NTPClient.h | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/NTPClient.cpp b/NTPClient.cpp index def941e..011c89c 100644 --- a/NTPClient.cpp +++ b/NTPClient.cpp @@ -25,7 +25,7 @@ NTPClient::NTPClient(UDP& udp) { this->_udp = &udp; } -NTPClient::NTPClient(UDP& udp, int timeOffset) { +NTPClient::NTPClient(UDP& udp, long timeOffset) { this->_udp = &udp; this->_timeOffset = timeOffset; } @@ -35,13 +35,13 @@ NTPClient::NTPClient(UDP& udp, const char* poolServerName) { this->_poolServerName = poolServerName; } -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, const char* poolServerName, int timeOffset, unsigned long updateInterval) { +NTPClient::NTPClient(UDP& udp, const char* poolServerName, long timeOffset, unsigned long updateInterval) { this->_udp = &udp; this->_timeOffset = timeOffset; this->_poolServerName = poolServerName; diff --git a/NTPClient.h b/NTPClient.h index cdbf55a..b9c6123 100644 --- a/NTPClient.h +++ b/NTPClient.h @@ -15,7 +15,7 @@ class NTPClient { const char* _poolServerName = "pool.ntp.org"; // Default time server int _port = NTP_DEFAULT_LOCAL_PORT; - int _timeOffset = 0; + long _timeOffset = 0; unsigned long _updateInterval = 60000; // In ms @@ -28,10 +28,10 @@ class NTPClient { public: NTPClient(UDP& udp); - NTPClient(UDP& udp, int timeOffset); + NTPClient(UDP& udp, long timeOffset); NTPClient(UDP& udp, const char* poolServerName); - NTPClient(UDP& udp, const char* poolServerName, int timeOffset); - NTPClient(UDP& udp, const char* poolServerName, int timeOffset, unsigned long updateInterval); + NTPClient(UDP& udp, const char* poolServerName, long timeOffset); + NTPClient(UDP& udp, const char* poolServerName, long timeOffset, unsigned long updateInterval); /** * Starts the underlying UDP client with the default local port From 10125217d91e16c8463f1740eeab4a37bc1088c9 Mon Sep 17 00:00:00 2001 From: Tamas Karpati Date: Tue, 20 Feb 2018 21:32:17 +0100 Subject: [PATCH 5/7] Make getter methods const --- NTPClient.cpp | 12 ++++++------ NTPClient.h | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/NTPClient.cpp b/NTPClient.cpp index 011c89c..a26747b 100644 --- a/NTPClient.cpp +++ b/NTPClient.cpp @@ -101,26 +101,26 @@ bool NTPClient::update() { return true; } -unsigned long NTPClient::getEpochTime() { +unsigned long NTPClient::getEpochTime() const { return this->_timeOffset + // User offset this->_currentEpoc + // Epoc returned by the NTP server ((millis() - this->_lastUpdate) / 1000); // Time since last update } -int NTPClient::getDay() { +int NTPClient::getDay() const { return (((this->getEpochTime() / 86400L) + 4 ) % 7); //0 is Sunday } -int NTPClient::getHours() { +int NTPClient::getHours() const { return ((this->getEpochTime() % 86400L) / 3600); } -int NTPClient::getMinutes() { +int NTPClient::getMinutes() const { return ((this->getEpochTime() % 3600) / 60); } -int NTPClient::getSeconds() { +int NTPClient::getSeconds() const { return (this->getEpochTime() % 60); } -String NTPClient::getFormattedTime() { +String NTPClient::getFormattedTime() const { unsigned long rawTime = this->getEpochTime(); unsigned long hours = (rawTime % 86400L) / 3600; String hoursStr = hours < 10 ? "0" + String(hours) : String(hours); diff --git a/NTPClient.h b/NTPClient.h index b9c6123..a99c7e0 100644 --- a/NTPClient.h +++ b/NTPClient.h @@ -58,10 +58,10 @@ class NTPClient { */ bool forceUpdate(); - int getDay(); - int getHours(); - int getMinutes(); - int getSeconds(); + int getDay() const; + int getHours() const; + int getMinutes() const; + int getSeconds() const; /** * Changes the time offset. Useful for changing timezones dynamically @@ -77,12 +77,12 @@ class NTPClient { /** * @return time formatted like `hh:mm:ss` */ - String getFormattedTime(); + String getFormattedTime() const; /** * @return time in seconds since Jan. 1, 1970 */ - unsigned long getEpochTime(); + unsigned long getEpochTime() const; /** * Stops the underlying UDP client From 6bb8cdafc703c9459f89cc7aa00ddb949acab421 Mon Sep 17 00:00:00 2001 From: Peeter Normak Date: Tue, 31 Oct 2017 11:01:47 +0200 Subject: [PATCH 6/7] added method for changing time server --- NTPClient.cpp | 4 ++++ NTPClient.h | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/NTPClient.cpp b/NTPClient.cpp index a26747b..87b7a53 100644 --- a/NTPClient.cpp +++ b/NTPClient.cpp @@ -148,6 +148,10 @@ void NTPClient::setUpdateInterval(unsigned long updateInterval) { this->_updateInterval = updateInterval; } +void NTPClient::setPoolServerName(const char* poolServerName) { + this->_poolServerName = poolServerName; +} + void NTPClient::sendNTPPacket() { // set all bytes in the buffer to 0 memset(this->_packetBuffer, 0, NTP_PACKET_SIZE); diff --git a/NTPClient.h b/NTPClient.h index a99c7e0..02d8752 100644 --- a/NTPClient.h +++ b/NTPClient.h @@ -33,6 +33,13 @@ class NTPClient { NTPClient(UDP& udp, const char* poolServerName, long timeOffset); NTPClient(UDP& udp, const char* poolServerName, long timeOffset, unsigned long updateInterval); + /** + * Set time server name + * + * @param poolServerName + */ + void setPoolServerName(const char* poolServerName); + /** * Starts the underlying UDP client with the default local port */ From 020aaf868d53331a6f2909f7f6a475998c527ae4 Mon Sep 17 00:00:00 2001 From: vincentVDB Date: Tue, 10 Jul 2018 19:30:50 +0200 Subject: [PATCH 7/7] Update keywords.txt forget ? setTimeOffset KEYWORD2 setUpdateInterval KEYWORD2 setPoolServerName KEYWORD2 --- keywords.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/keywords.txt b/keywords.txt index 1430d04..6f7bc6f 100644 --- a/keywords.txt +++ b/keywords.txt @@ -18,3 +18,6 @@ getMinutes KEYWORD2 getSeconds KEYWORD2 getFormattedTime KEYWORD2 getEpochTime KEYWORD2 +setTimeOffset KEYWORD2 +setUpdateInterval KEYWORD2 +setPoolServerName KEYWORD2