Description
I have the NTP time client from https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino working on an esp8266. I modified it slightly to run on an esp32 by changing ESP8266Wifi.h to Wifi.h A packet is only returned the first time through the loop. After that, I always get "no packet yet". I have tried increasing the delay(1000) to 10 seconds, 20 seconds, and get the same behavior. I added a debug print to the loop (this did not change the behavior) to verify that the IP lookup is working correctly each time.
modified loop:
WiFi.hostByName(ntpServerName, timeServerIP);
Serial.print("Time Server IP: "); /* added /
Serial.println(timeServerIP); / added */
Output:
WiFi connected
IP address:
10.0.0.31
Starting UDP
Time Server IP: 129.6.15.30
sending NTP packet...
packet received, length=48
Seconds since Jan 1 1900 = 3692108698
Unix time = 1483119898
The UTC time is 17:44:58
Time Server IP: 129.6.15.30
sending NTP packet...
no packet yet
Time Server IP: 129.6.15.30
sending NTP packet...
no packet yet
Time Server IP: 131.107.13.100
sending NTP packet...
no packet yet
Time Server IP: 132.163.4.103
sending NTP packet...
no packet yet
Time Server IP: 216.228.192.69
sending NTP packet...
no packet yet
Time Server IP: 216.228.192.69
sending NTP packet...
no packet yet