@@ -73,7 +73,7 @@ void NTPClient::begin() {
73
73
this ->begin (NTP_DEFAULT_LOCAL_PORT);
74
74
}
75
75
76
- void NTPClient::begin (int port) {
76
+ void NTPClient::begin (unsigned int port) {
77
77
this ->_port = port;
78
78
79
79
this ->_udp ->begin (this ->_port );
@@ -120,7 +120,7 @@ bool NTPClient::forceUpdate() {
120
120
bool NTPClient::update () {
121
121
if ((millis () - this ->_lastUpdate >= this ->_updateInterval ) // Update after _updateInterval
122
122
|| this ->_lastUpdate == 0 ) { // Update if there was no update yet.
123
- if (!this ->_udpSetup ) this ->begin (); // setup the UDP client if needed
123
+ if (!this ->_udpSetup || this -> _port != NTP_DEFAULT_LOCAL_PORT ) this ->begin (this -> _port ); // setup the UDP client if needed
124
124
return this ->forceUpdate ();
125
125
}
126
126
return false ; // return false if update does not occur
@@ -182,6 +182,7 @@ void NTPClient::sendNTPPacket() {
182
182
memset (this ->_packetBuffer , 0 , NTP_PACKET_SIZE);
183
183
// Initialize values needed to form NTP request
184
184
// (see URL above for details on the packets)
185
+
185
186
this ->_packetBuffer [0 ] = 0b11100011 ; // LI, Version, Mode
186
187
this ->_packetBuffer [1 ] = 0 ; // Stratum, or type of clock
187
188
this ->_packetBuffer [2 ] = 6 ; // Polling Interval
@@ -202,3 +203,8 @@ void NTPClient::sendNTPPacket() {
202
203
this ->_udp ->write (this ->_packetBuffer , NTP_PACKET_SIZE);
203
204
this ->_udp ->endPacket ();
204
205
}
206
+
207
+ void NTPClient::setRandomPort (unsigned int minValue, unsigned int maxValue) {
208
+ randomSeed (analogRead (0 ));
209
+ this ->_port = random (minValue, maxValue);
210
+ }
0 commit comments