ESP8266_RTOS_SDK_v2.x.x => Problem using configTime and getting time

fmuller-pi

ESP8266_RTOS_SDK_v2.x.x => Problem using configTime and getting time

Postby fmuller-pi » Fri Feb 01, 2019 7:25 am

Hi all,

I am using the ESP8266_RTOS_SDK_v2.x.x with my ESP8266. I need to connect to my Cloud (using Google Cloud Platform) and to do this, I generate a JWT. For that, I need the Unix time so I can set the validity of the token I am creating.
So, I am trying to use the API

Code: Select all

configTime
for that. I call it like that:

Code: Select all

   
   ret_bool = configTime(1, 1, "pool.ntp.org", NULL, NULL, true);
    ESP_LOG_INFO("ret_bool after: %d", ret_bool);
    time_t now = time(NULL);


The problem is that, even though ret_bool is returning 1 (everything went well calling

Code: Select all

configTime
), it doesn't work (time(NULL) = a random int that is wrong) and I get the message
please start sntp first !
everytime.

I can't figure out what is going wrong, as I am using the time.h API provided in the ESP8266_RTOS_SDK_v2.x.x

Does anyone have an idea of what I could be doing wrong?

PS: I do establish a WiFI internet connection prior to calling

Code: Select all

configTime


Thanks

Her Mary
Posts: 537
Joined: Mon Oct 27, 2014 11:09 am

Re: ESP8266_RTOS_SDK_v2.x.x => Problem using configTime and getting time

Postby Her Mary » Fri Feb 01, 2019 11:45 am

Why don't you use the latest V3.1? There is an example https://github.com/espressif/ESP8266_RT ... ocols/sntp

fmuller-pi

Re: ESP8266_RTOS_SDK_v2.x.x => Problem using configTime and getting time

Postby fmuller-pi » Fri Feb 01, 2019 3:05 pm

Thanks for your reply. Unfortunately, I just started to work on this project and picked it up from a previous coworker. We don't want to move to the 3.1 because the SDK totally changed between the 2.x.x that we started working with and the latest version. And the deadline for that project is too tight.
In any case, I was actually able to find a piece of example for the v2.x.x here: https://github.com/espressif/ESP8266_RTOS_SDK/blob/release/v2.x.x/examples/wolfssl_demo/user/wolfssl_client.c

I guess I am still confused on why the APIs in time.c for that version are still implemented since they obviously don't seem to be working as one would be expecting.

Thanks for your help!

btomic
Posts: 5
Joined: Thu May 04, 2017 7:01 pm

Re: ESP8266_RTOS_SDK_v2.x.x => Problem using configTime and getting time

Postby btomic » Mon Feb 11, 2019 5:38 pm

I initialize sntp like this

#include "apps/sntp.h"
#include "apps/sntp_time.h"
#include "apps/time.h"

.
.
.
updateTime(60*60000);
sntp_setoperatingmode(SNTP_OPMODE_POLL);
sntp_setservername(0, "pool.ntp.org");
sntp_set_timezone(user_timezone); // user defined (in my case user_timezone=1)
sntp_init();
while (sntp_get_current_timestamp() == 0) // this loop should be limited in case wifi is not available (otherwise it will get stuck in it)!
vTaskDelay(1000 / portTICK_RATE_MS);

After this initialization I usually see one-time message

"please start sntp first !"

and then it exits the loop with sntp properly initialized. From then each call to time(NULL) will return proper epoch time (adjusted for timezone).

fmuller-pi

Re: ESP8266_RTOS_SDK_v2.x.x => Problem using configTime and getting time

Postby fmuller-pi » Tue Feb 12, 2019 1:23 am

Thank you for your help! :)

Who is online

Users browsing this forum: No registered users and 181 guests