Chat freely about anything...

User avatar
By Atlantis
#20426 I need to synchronize time when ESP8266 starts and connection is established.
I tried to do it by using EVENT_STAMODE_GOT_IP. Unfortunately sntp_get_current_timestamp() returns 0. I assume module is not yet ready to ask NTP server for time. Synchronization itself woks fine, when function is executed a little bit later by a timer handling periodic synchronization.
What I should to do, to get time synchronized at the beginning?
User avatar
By kolban
#23111 I am presuming that when you receive the event that you have been allocated an IP address you are doing various "startup" functions in your logic. However, as you note, when you are informed "You have an IP" ... that is probably a true statement but it may also be an early statement ... meaning you "JUST" got the IP address. Instead of doing your app startup routines then and there, maybe setup a timer to fire a few seconds AFTER you get your IP address by which time your environment will be stable.

If we assume that only AFTER you get an IP address can a request be made to a time server and that request will take some time (10msecs - 1000msecs?) to get a response back .... if the "you have just been given an IP address" event happens at the moment the system recognizes that you have an IP, it will have been too early for a response to have been sent and received from the time server.