I have a large sketch on a Mega 2560 that tracks the time, reads sensor data, and writes a timestamp and data to an SD card and a web server. All worked fine for months–until I changed from using a fixed NIST ip address for syncing the time to using time.nist.gov.
The time will sync with time.nist.gov at startup (usually after a couple tries), but later it starts failing. I’ve replicated the problem by combining the TimeNTP and WebServer example sketches (attached due to space limitation), modified to count and display the number of sync successes and failures.
The sketch can be compiled using a fixed ip for the time server, or time.nist.gov, and the SD and web server functionality can be turned on or off by commenting out the appropriate “defines” at the beginning of the sketch.
Here are the sync failure rates I get with time.nist.gov after around 100 - 200 sync attempts:
1.5% with both web server and sd logging turned off (after two failures at startup)
4% with web server off and sd logging on (after two failures at startup)
85% with web server on and sd logging off;
98% with web server on and sd logging on
Syncing with an ip address for the time server, I get a 0% failure rate in all cases. But I’d rather use the time.nist.gov url to ensure that there is always a time server available.
Is there something in my code causing the high sync failure rate with time.nist.gov, particularly with the web server on? Or is this a hardware/firmware issue? Both my Mega 2560 and Ethernet shield (Wiznet 5100) are clones. I am using IDE 1.6.12. The DNS server is my router, set by default, which uses dynamic DNS.
Thanks for any thoughts anyone has on this.
TimeNTPLogSDweb2.ino (9.01 KB)