-->
Page 1 of 6

NTP Client Example, working after bug fix UDP library

PostPosted: Thu Apr 09, 2015 9:26 am
by gerardwr
UPDATE 11 april 2015 : A bug in the UDP library was fixed today and a working NTP example added to the git here:
https://github.com/esp8266/Arduino/blob/esp8266/hardware/esp8266com/esp8266/libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino

I updated my running Mac OS download from github by replacing the ESP8266WiFi directory, and uploaded the NTPClient example. It runs OK:

Schermafbeelding 2015-04-12 om 13.18.14.png


The message below is not relevant anymore but I'll keep it for reference. I have removed the non-working example below.
======================================================================

Referring to the topic below on bidirectional UDP communication I compiled a sketch to get the time from an NTP server:
http://www.esp8266.com/viewtopic.php?f=28&t=2295

The sketch is attached below.

Sending the NTP request packet to an NTP server returns "success" (a 1), but no packet is received from the NTP server.

So I'm stuck here. Any suggestions?

<attachment removed>

Re: NTP Client Example (not working!)

PostPosted: Thu Apr 09, 2015 1:46 pm
by dnts
Well.. you've made some mess in your code BUT my code which is just a slight modification of a working ethernet code doesn't work either.. so we are both stuck.
Anyway - you need to have just one port, not two. That port shouldn't have any of the "well known port numbers" so 123 you used in your localport number is probably not a good idea. Anything above 1000 should work better. You are sending a full duplex UDP packet from your local port to 123 on the NTP server. NTP replies from his 123 to your local port so you need to expect the UDP packet reply on your original local port.
This is what I did. I get UDP send confirmation but nothing ever comes back on the other end...
So that makes both of us now.

Re: NTP Client Example (not working!)

PostPosted: Thu Apr 09, 2015 2:19 pm
by gerardwr
dnts wrote:Well.. you've made some mess in your code


Hah, thanks for the compliment !

Did you have a look at the discussion in the referenced topic? I am aware that in the Arduino environment there should be only 1 UDP instance used, but that does not seem to work here.

IGRR has stated that in his opinion 2 instances should be used (https://github.com/esp8266/Arduino/issues/53).

Yes, I also did try using a local port of 9999, but to no avail.

I smell a bug!

Other suggestions? Anyone?

Re: NTP Client Example (not working!)

PostPosted: Fri Apr 10, 2015 12:55 am
by dnts
Hey.. sorry for the distasteful comment I've made in my previous reply.. duh.. I then checked the referenced bug report and spent the evening crashing my ESP8266 by sending UDP packets. I suspect the root cause is too many instances of UDP opening with differnt port numbers that increment from 4097 (dunno why it starts there) until the heap is exhausted and the watchdog kicks in. Anyway, seems like Udp.begin(port number) does not control which port the UDP packet transmits from hence preventing the NTP reply from reaching the correct port on it's way back to the ESP8266. It MUST be the same port number. Now - I wonder if I can force Udp to listen to that arbitrary egress port (4097) with the Udp.begin.. guess not.
BUG.