-->
Page 1 of 1

SNTP update at EVENT_STAMODE_GOT_IP

PostPosted: Sun Jun 14, 2015 9:02 am
by Atlantis
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?

Re: SNTP update at EVENT_STAMODE_GOT_IP

PostPosted: Mon Jul 13, 2015 12:21 am
by kolban
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.