Can't update time from SNTP

erimads@gmail.com
Posts: 9
Joined: Fri Jan 26, 2024 6:53 pm

Can't update time from SNTP

Postby erimads@gmail.com » Sun Feb 11, 2024 12:57 pm

I are making a clock to this I need to update the time every 24 hours, but I only got the correct time with the first call.
Here is the code for the to calls, the wifi is connected at the first call.
First time I call the GetLocalTime, and it gives me the correct time. the following call goes to GetUpdateTime, but here I got the minute and secund saved from the first call no new time. Can anyone tell me how to get a new time from SNTP ?

//****************************************************************************************
void GetLocalTime()
{
wifi_connection();
esp_sntp_setoperatingmode(SNTP_OPMODE_POLL);
setenv("TZ","CET-1CEST,M3.5.0,M10.5.0/3",1);
tzset();
esp_sntp_setservername(0,"pool.ntp.org");
esp_sntp_init();
int retry = 0;
const int retry_count = 10;
while (Tinfo.tm_year < (2016 - 1900) && ++retry < retry_count )// timeinfo.tm_year < (2016 - 1900) && ++retry < retry_count )
{
vTaskDelay(2000 / portTICK_PERIOD_MS);
time(&now);
localtime_r(&now, &Tinfo);
}
Akt100=0;
AktSec=Tinfo.tm_sec;
AktMin=Tinfo.tm_min;
AktTim=Tinfo.tm_hour;
AktDag=Tinfo.tm_mday;
AktWdg=Tinfo.tm_wday;
AktMd =Tinfo.tm_mon;
}

//****************************************************************************************
void GetUpdateTime()
{
// wifi_connection();
//esp_sntp_setoperatingmode(SNTP_OPMODE_POLL);
setenv("TZ","CET-1CEST,M3.5.0,M10.5.0/3",1);
tzset();
esp_sntp_setservername(0,"pool.ntp.org");
esp_sntp_restart();
esp_sntp_set_sync_mode(SNTP_SYNC_MODE_IMMED);
esp_sntp_sync_time(now);
retry = 0;
const int retry_count = 10;
while (Tinfo.tm_year < (2016 - 1900) && ++retry < retry_count )// timeinfo.tm_year < (2016 - 1900) && ++retry < retry_count )
{
vTaskDelay(2000 / portTICK_PERIOD_MS);
// time(&now);
localtime_r(&now, &Tinfo);
}
Blue[63][0]=retry;
if (retry<9)
{
Akt100=0;
AktSec=Tinfo.tm_sec;
AktMin=Tinfo.tm_min;
}
TidFlag1=0;
TidFlag2=0;
}

Who is online

Users browsing this forum: No registered users and 321 guests