energia / cc3200-core

6 stars 10 forks source link

WiFiUdpNtpClient.ino example fails to get time #20

Closed rei-vilo closed 6 years ago

rei-vilo commented 7 years ago

Once issue #19 has been patched with the suggested solution, the WiFiUdpNtpClient.ino example fails to get time.

WiFiUDP::parsePacket() exits at line 277.

    int iRet = sl_Select(socketHandle+1, &readSocketHandles, NULL, &errorSocketHandles, &timeout);
    if (iRet <= 0) {
        return 0;
    }

Any idea?

robertinant commented 6 years ago

The IP address used in the Sketch is no longer associated with time.nist.gov and hence it fails since there is no NTP server at that address. Since we have DNS lookup all examples should use domain names rather than IP addresses where possible. I will go through the examples of the WiFi and Ethernet library and change the ip addresses to domain names if possible. Below is the diff to make it work again.

diff --git a/libraries/WiFi/examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino b/libraries/WiFi/examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino
index 5d92bf0..b9f538a 100644
--- a/libraries/WiFi/examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino
+++ b/libraries/WiFi/examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino
@@ -32,7 +32,7 @@ char password[] = "launchpad";

 unsigned int localPort = 2390;      // local port to listen for UDP packets

-IPAddress timeServer(206,246,122,250); // time.nist.gov NTP server
+char timeServer[] = "time.nist.gov"; // time.nist.gov NTP server

 const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message

@@ -128,7 +128,7 @@ void loop()
 }

 // send an NTP request to the time server at the given address
-unsigned long sendNTPpacket(IPAddress& address)
+unsigned long sendNTPpacket(const char *address)
 {
   //Serial.println("1");
   // set all bytes in the buffer to 0