How to check if sntp_init() completed?

deadmetaphor
Posts: 6
Joined: Tue Aug 11, 2015 2:41 pm

How to check if sntp_init() completed?

Postby deadmetaphor » Tue Aug 11, 2015 2:57 pm

I am trying to get the current time using the SNTP APIs in the SDK.

It works fine except that sometimes when I call

Code: Select all

sntp_get_current_timestamp()


it returns the time equivalent to "1970.01.01 00:00:00" and logs an error

Code: Select all

please start sntp first !


How to I test if sntp_init() has completed? Or, provide a callback perhaps?

ESP_Faye
Posts: 1641
Joined: Mon Oct 27, 2014 11:08 am

Re: How to check if sntp_init() completed?

Postby ESP_Faye » Tue Aug 11, 2015 3:08 pm

Hi,

So sorry for the inconvenience.

Set a timer to check if current_stamp got a real timestamp, not 0 any more.

Code: Select all

uint32 current_stamp;
current_stamp = sntp_get_current_timestamp();


We will update our example in documentation.

Thanks for your interest in ESP8266 !

deadmetaphor
Posts: 6
Joined: Tue Aug 11, 2015 2:41 pm

Re: How to check if sntp_init() completed?

Postby deadmetaphor » Tue Aug 11, 2015 4:43 pm

Thanks!

derekh
Posts: 4
Joined: Thu Aug 13, 2015 1:47 pm

Re: How to check if sntp_init() completed?

Postby derekh » Thu Aug 13, 2015 1:52 pm

please consider adding a callback.

also when RTOS SDK will have SNTP support?

PaulTsai111
Posts: 48
Joined: Wed May 04, 2016 7:32 pm

Re: How to check if sntp_init() completed?

Postby PaulTsai111 » Fri Jun 03, 2016 6:47 pm

Hi Espressif :

I have encountered the same question , sntp_get_real_time got 1970 ..........

Can you show me where I can find espressif Documents ? about sntp_get_real_time usage ?

I hope to correct my code thanks you !!

ESP_Faye
Posts: 1641
Joined: Mon Oct 27, 2014 11:08 am

Re: How to check if sntp_init() completed?

Postby ESP_Faye » Mon Jun 06, 2016 10:14 am

Hi,

Please refer to the documentation "ESP8266 Non-OS SDK API Guide" http://www.espressif.com/support/download/documents.

Thanks for your interest in ESP8266 !

PaulTsai111
Posts: 48
Joined: Wed May 04, 2016 7:32 pm

Re: How to check if sntp_init() completed?

Postby PaulTsai111 » Tue Jun 07, 2016 11:38 am

Hi Espressif :

About the usage of testing the sntp I have changed to the api provided example way to do.

The results still shows sntp start first !

Does this sntp api should first connect to router ?

because connect to server right ?

ESP_Faye
Posts: 1641
Joined: Mon Oct 27, 2014 11:08 am

Re: How to check if sntp_init() completed?

Postby ESP_Faye » Wed Jun 08, 2016 2:05 pm

Hi,

Yes. SNTP is getting time info from internet, it needs to connect to router first.

eriksl
Posts: 157
Joined: Fri May 22, 2015 6:22 pm

Re: How to check if sntp_init() completed?

Postby eriksl » Sun Jun 19, 2016 6:20 pm

The current (as of 1.5.2) implementation has a nasty quirk though. Time is only fetched ONCE. As the internal clock of the ESP8266 isn't quite "real time", your clock will be off by 1-60 minutes every 24h. The concept of NTP is that it's run periodically to care for clock drift. I had to workaround this by stopping and starting NTP every now and then.

Who is online

Users browsing this forum: Google [Bot] and 5 guests