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;
}
Can't update time from SNTP
-
- Posts: 9
- Joined: Fri Jan 26, 2024 6:53 pm
Jump to
- English Forum
- Explore
- News
- General Discussion
- FAQ
- Documentation
- Documentation
- Sample Code
- Discussion Forum
- Hardware
- ESP-IDF
- ESP-BOX
- ESP-ADF
- ESP-MDF
- ESP-WHO
- ESP-SkaiNet
- ESP32 Arduino
- IDEs for ESP-IDF
- ESP-AT
- ESP IoT Solution
- ESP RainMaker
- Rust
- ESP8266
- Report Bugs
- Showcase
- Chinese Forum 中文社区
- 活动区
- 乐鑫活动专区
- 讨论区
- 全国大学生物联网设计竞赛乐鑫答疑专区
- ESP-IDF 中文讨论版
- 《ESP32-C3 物联网工程开发实战》书籍讨论版
- 中文文档讨论版
- ESP-AT 中文讨论版
- ESP-BOX 中文讨论版
- ESP IoT Solution 中文讨论版
- ESP-ADF 中文讨论版
- ESP Mesh 中文讨论版
- ESP Cloud 中文讨论版
- ESP-WHO 中文讨论版
- ESP-SkaiNet 中文讨论版
- ESP 生产支持讨论版
- 硬件问题讨论
- 项目展示
Who is online
Users browsing this forum: Bing [Bot], Gaston1980 and 203 guests
- All times are UTC
- Top
- Delete cookies
About Us
Espressif Systems is a fabless semiconductor company providing cutting-edge low power WiFi SoCs and wireless solutions for wireless communications and Internet of Things applications. ESP8266EX and ESP32 are some of our products.