NTP issue(2036)

somesh
Posts: 36
Joined: Tue Jun 25, 2019 6:44 am
Location: Pune
Contact:

NTP issue(2036)

Postby somesh » Tue Dec 10, 2019 10:07 am

Hello,

I am using esp idf v3.3 and trying to get time from ntp server( asia.pool.ntp.org ). but sometimes I am getting wrong time from ntp server i.e. 07/02/2036. after doing R&D into this, I found that where there is no response from NTP server time is set to year 2036.
Please check following link for your reference.
https://github.com/gmag11/NtpClient/issues/70

I am using following sample code to resolve. please check for the same and let me know how to handle such problem.

Code: Select all


void get_time() {

sntp_setoperatingmode(SNTP_OPMODE_POLL);
sntp_setservername(0,"asia.pool.ntp.org");
sntp_init();

 time_t now;
 struct tm timeinfo;
 time(&now);
 setenv("TZ", "UTC-05:30", 1);
 tzset();
 localtime_r(&now, &timeinfo);

while( timeinfo.tm_year <= 70 )
{
	time(&now);
	localtime_r(&now, &timeinfo);
	ESP_LOGI(TAG, "Trying to reach NTP server...");
		
	vTaskDelay(5000 / portTICK_PERIOD_MS);
}
	
strftime(Timebuffer, sizeof(Timebuffer), "%d-%m-%Y %T", &timeinfo);
ESP_LOGI(TAG, "The current date/time is: %s", Timebuffer);
} 

we can handle it by checking year but not looks like its good solution. please suggest.
Thanks,
Somesh Burkule

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: NTP issue(2036)

Postby ESP_Sprite » Wed Dec 11, 2019 2:12 am

Note: you may be better off creating a new issue on Github for this if you want Espressif devs to look into this.

somesh
Posts: 36
Joined: Tue Jun 25, 2019 6:44 am
Location: Pune
Contact:

Re: NTP issue(2036)

Postby somesh » Wed Dec 11, 2019 5:04 am

ESP_Sprite wrote:
Wed Dec 11, 2019 2:12 am
Note: you may be better off creating a new issue on Github for this if you want Espressif devs to look into this.
Ok. Thanks.
I have created one https://github.com/espressif/esp-idf/issues/4472.
Thanks,
Somesh Burkule

somesh
Posts: 36
Joined: Tue Jun 25, 2019 6:44 am
Location: Pune
Contact:

Re: NTP issue(2036)

Postby somesh » Wed Dec 18, 2019 12:22 pm

Hello ESP,

Please help me for the same.
Awaiting your reply.
Thanks,
Somesh Burkule

Who is online

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