@@ -37,23 +37,38 @@ NTPClient::NTPClient(UDP& udp, const char* poolServerName) {
37
37
38
38
NTPClient::NTPClient (UDP& udp, IPAddress poolServerIP) {
39
39
this ->_udp = &udp;
40
- this ->_poolServerIP = poolServerIP;
40
+ this ->_poolServerIP = poolServerIP;
41
41
this ->_poolServerName = NULL ;
42
42
}
43
43
44
- NTPClient::NTPClient (UDP& udp, const char * poolServerName, int timeOffset) {
44
+ NTPClient::NTPClient (UDP& udp, const char * poolServerName, long timeOffset) {
45
45
this ->_udp = &udp;
46
46
this ->_timeOffset = timeOffset;
47
47
this ->_poolServerName = poolServerName;
48
48
}
49
49
50
+ NTPClient::NTPClient (UDP& udp, IPAddress poolServerIP, long timeOffset){
51
+ this ->_udp = &udp;
52
+ this ->_timeOffset = timeOffset;
53
+ this ->_poolServerIP = poolServerIP;
54
+ this ->_poolServerName = NULL ;
55
+ }
56
+
50
57
NTPClient::NTPClient (UDP& udp, const char * poolServerName, long timeOffset, unsigned long updateInterval) {
51
58
this ->_udp = &udp;
52
59
this ->_timeOffset = timeOffset;
53
60
this ->_poolServerName = poolServerName;
54
61
this ->_updateInterval = updateInterval;
55
62
}
56
63
64
+ NTPClient::NTPClient (UDP& udp, IPAddress poolServerIP, long timeOffset, unsigned long updateInterval) {
65
+ this ->_udp = &udp;
66
+ this ->_timeOffset = timeOffset;
67
+ this ->_poolServerIP = poolServerIP;
68
+ this ->_poolServerName = NULL ;
69
+ this ->_updateInterval = updateInterval;
70
+ }
71
+
57
72
void NTPClient::begin () {
58
73
this ->begin (NTP_DEFAULT_LOCAL_PORT);
59
74
}
@@ -179,7 +194,11 @@ void NTPClient::sendNTPPacket() {
179
194
180
195
// all NTP fields have been given values, now
181
196
// you can send a packet requesting a timestamp:
182
- this ->_udp ->beginPacket (this ->_poolServerName , 123 ); // NTP requests are to port 123
197
+ if (this ->_poolServerName ) {
198
+ this ->_udp ->beginPacket (this ->_poolServerName , 123 );
199
+ } else {
200
+ this ->_udp ->beginPacket (this ->_poolServerIP , 123 );
201
+ }
183
202
this ->_udp ->write (this ->_packetBuffer , NTP_PACKET_SIZE);
184
203
this ->_udp ->endPacket ();
185
204
}
0 commit comments