Skip to content

Commit a9803d7

Browse files
committed
Added several methods useful for dynamically changing the NTP server.
1 parent 61684d4 commit a9803d7

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

NTPClient.cpp

100755100644
+21
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,35 @@ void NTPClient::setTimeOffset(int timeOffset) {
173173
this->_timeOffset = timeOffset;
174174
}
175175

176+
long NTPClient::getTimeOffset() {
177+
return this->_timeOffset;
178+
}
179+
176180
void NTPClient::setUpdateInterval(unsigned long updateInterval) {
177181
this->_updateInterval = updateInterval;
178182
}
179183

184+
unsigned long NTPClient::getUpdateInterval() {
185+
return this->_updateInterval;
186+
}
187+
180188
void NTPClient::setPoolServerName(const char* poolServerName) {
181189
this->_poolServerName = poolServerName;
182190
}
183191

192+
const char *NTPClient::getPoolServerName() {
193+
return this->_poolServerName;
194+
}
195+
196+
void NTPClient::setPoolServerIP(IPAddress poolServerIP) {
197+
this->_poolServerIP = poolServerIP;
198+
this->_poolServerName = NULL;
199+
}
200+
201+
IPAddress NTPClient::getPoolServerIP() {
202+
return this->_poolServerIP;
203+
}
204+
184205
void NTPClient::sendNTPPacket() {
185206
// set all bytes in the buffer to 0
186207
memset(this->_packetBuffer, 0, NTP_PACKET_SIZE);

NTPClient.h

100755100644
+27
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,23 @@ class NTPClient {
4444
*/
4545
void setPoolServerName(const char* poolServerName);
4646

47+
/**
48+
* Get time server name
49+
*/
50+
const char *getPoolServerName();
51+
52+
/**
53+
* Set time server IP
54+
*
55+
* @param poolServerIP
56+
*/
57+
void setPoolServerIP(IPAddress poolServerIP);
58+
59+
/*
60+
* Get time server IP
61+
*/
62+
IPAddress getPoolServerIP();
63+
4764
/**
4865
* Set random local port
4966
*/
@@ -91,12 +108,22 @@ class NTPClient {
91108
*/
92109
void setTimeOffset(int timeOffset);
93110

111+
/**
112+
* Get the time offset
113+
*/
114+
long getTimeOffset();
115+
94116
/**
95117
* Set the update interval to another frequency. E.g. useful when the
96118
* timeOffset should not be set in the constructor
97119
*/
98120
void setUpdateInterval(unsigned long updateInterval);
99121

122+
/**
123+
* Get the update interval
124+
*/
125+
unsigned long getUpdateInterval();
126+
100127
/**
101128
* @return time formatted like `hh:mm:ss`
102129
*/

0 commit comments

Comments
 (0)