Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By gerardwr
#13984 UPDATE 11 april 2015 : A bug in the UDP library was fixed today and a working NTP example added to the git here:

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:

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>
You do not have the required permissions to view the files attached to this post.
Last edited by gerardwr on Sun Apr 12, 2015 6:21 am, edited 3 times in total.
User avatar
By dnts
#14013 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.
User avatar
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?
Last edited by gerardwr on Thu Apr 09, 2015 2:31 pm, edited 2 times in total.
User avatar
By dnts
#14061 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.