Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Commit fd85f20

Browse files
authored
Update NTP example
1 parent 821e740 commit fd85f20

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

examples/UdpNTPClient/UdpNTPClient.ino

+11-3
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,19 @@ void loop()
130130
unsigned long startMs = millis();
131131
while (!Udp.available() && (millis() - startMs) < UDP_TIMEOUT) {}
132132

133-
Serial.println(Udp.parsePacket());
133+
// if there's data available, read a packet
134+
int packetSize = Udp.parsePacket();
134135

135-
if (Udp.parsePacket())
136+
if (packetSize)
136137
{
137-
Serial.println(F("UDP Packet received"));
138+
Serial.print(F("UDP Packet received, size "));
139+
Serial.println(packetSize);
140+
Serial.print(F("From "));
141+
IPAddress remoteIp = Udp.remoteIP();
142+
Serial.print(remoteIp);
143+
Serial.print(F(", port "));
144+
Serial.println(Udp.remotePort());
145+
138146
// We've received a packet, read the data from it into the buffer
139147
Udp.read(packetBuffer, NTP_PACKET_SIZE);
140148

0 commit comments

Comments
 (0)