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

Commit e9e96f9

Browse files
authored
Update UDP example
1 parent 1e4e1e8 commit e9e96f9

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

examples/UdpNTPClient/UdpNTPClient.ino

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,19 @@ void loop()
122122
unsigned long startMs = millis();
123123
while (!Udp.available() && (millis() - startMs) < UDP_TIMEOUT) {}
124124

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

127-
if (Udp.parsePacket())
128+
if (packetSize)
128129
{
129-
Serial.println(F("UDP Packet received"));
130+
Serial.print(F("UDP Packet received, size "));
131+
Serial.println(packetSize);
132+
Serial.print(F("From "));
133+
IPAddress remoteIp = Udp.remoteIP();
134+
Serial.print(remoteIp);
135+
Serial.print(F(", port "));
136+
Serial.println(Udp.remotePort());
137+
130138
// We've received a packet, read the data from it into the buffer
131139
Udp.read(packetBuffer, NTP_PACKET_SIZE);
132140

0 commit comments

Comments
 (0)