I am trying to get the NTP client call implemented into my project and ran into a strange issue. Line for line I have pretty much copied in the Ethernet example for a NTP client but the code execution stops at the Udp.endPacket(); function and does not continue. I did not copy over the line for the MAC address as it would be different for my Ethernet shield
I have a telnet server running on 23 as well in the background but I don't see how it would get in the way. I also implemented slightly differently but it should work. I have a function getTime() that executes in the setup() section which sends the ntp packet to the server using the sub function sendNTPpacket(timeServer); - This is the function that has the endPacket() and gets stuck.
// send an NTP request to the time server at the given address
void sendNTPpacket(IPAddress& address) {
// set all bytes in the buffer to 0
memset(packetBuffer, 0, NTP_PACKET_SIZE);
lcd.print(".");
// Initialize values needed to form NTP request
// (see URL above for details on the packets)
packetBuffer[0] = 0b11100011; // LI, Version, Mode
packetBuffer[1] = 0; // Stratum, or type of clock
packetBuffer[2] = 6; // Polling Interval
packetBuffer[3] = 0xEC; // Peer Clock Precision
// 8 bytes of zero for Root Delay & Root Dispersion
packetBuffer[12] = 49;
packetBuffer[13] = 0x4E;
packetBuffer[14] = 49;
packetBuffer[15] = 52;
// all NTP fields have been given values, now
// you can send a packet requesting a timestamp:
Udp.beginPacket(address, 123); //NTP requests are to port 123
lcd.print(".");
Udp.write(packetBuffer,NTP_PACKET_SIZE);
lcd.print(".");
Udp.endPacket();
lcd.print(".");
return;
}
I also tried changing it to void with a return; and alternately removing the & after IPAddress in the function prototype (not sure what it means). I also changed the variable NTP_PACKET_SIZE to a define with a value of 48.
edit: Just after posting this I verified and uploaded the sketch again and it seems to be passing through the function without any problems on the sending side though it is not detecting any incoming packets. Do I need to port forward any other port to my Ethernet shield (I would think not for the client side)?
[quote author=Nick Gammon link=topic=95040.msg716570#msg716570 date=1331065640]
What? But your PC isn't an NTP server is it? But even if it is, use its local IP address. This seems a hopelessly muddled way of getting one device on your internal network to talk to another device. You use a host-name lookup of a dynamic address maintained on an external web site, when all you have to do is connect to 192.168.0.22 or whatever it is.[/quote]
I configured two of my computers as NTP servers and they work fine on the local subnet.The purpose of the external dyndns domain name is so that when I bring my laptop outside my subnet, I can still have it connect to my NTP server by getting the IP of my router dynamically. The problem is that it isn't working with the dyndns domain despite it replying with the right IP when I ping it. As I mentioned above I port forwarded 123 UDP/TCP to the internal NTP server.
This is issue #2
I would like to also get this to work (and it isn't right now). I tried using the supplied time.nist.gov (might be wrong) IP that is in the NTP Client code with no success on the arduino syncing with it. That same time server works fine on my computers.
This is issue #1