@@ -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 );
@@ -146,7 +146,7 @@ bool NTPClient::forceUpdate() {
146
146
bool NTPClient::update () {
147
147
if ((millis () - this ->_lastUpdate >= this ->_updateInterval ) // Update after _updateInterval
148
148
|| this ->_lastUpdate == 0 ) { // Update if there was no update yet.
149
- if (!this ->_udpSetup ) this ->begin (); // setup the UDP client if needed
149
+ if (!this ->_udpSetup || this -> _port != NTP_DEFAULT_LOCAL_PORT ) this ->begin (this -> _port ); // setup the UDP client if needed
150
150
return this ->forceUpdate ();
151
151
}
152
152
this ->_packetSent = false ;
@@ -224,6 +224,7 @@ void NTPClient::sendNTPPacket() {
224
224
memset (this ->_packetBuffer , 0 , NTP_PACKET_SIZE);
225
225
// Initialize values needed to form NTP request
226
226
// (see URL above for details on the packets)
227
+
227
228
this ->_packetBuffer [0 ] = 0b11100011 ; // LI, Version, Mode
228
229
this ->_packetBuffer [1 ] = 0 ; // Stratum, or type of clock
229
230
this ->_packetBuffer [2 ] = 6 ; // Polling Interval
@@ -244,3 +245,8 @@ void NTPClient::sendNTPPacket() {
244
245
this ->_udp ->write (this ->_packetBuffer , NTP_PACKET_SIZE);
245
246
this ->_udp ->endPacket ();
246
247
}
248
+
249
+ void NTPClient::setRandomPort (unsigned int minValue, unsigned int maxValue) {
250
+ randomSeed (analogRead (0 ));
251
+ this ->_port = random (minValue, maxValue);
252
+ }
0 commit comments