NTP server giving time after long time

burkulesomesh43
Posts: 113
Joined: Tue Aug 14, 2018 6:21 am

NTP server giving time after long time

Postby burkulesomesh43 » Fri Jan 11, 2019 11:43 am

Hi all,
I have used sntp example from esp idf and modified it as per my use as folllows-->>>

Code: Select all

void sntp_task(void *pvParameter) {

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

	time_t now;
	struct tm timeinfo;
	struct tm *tmp;
	time(&now);
	localtime_r(&now, &timeinfo);
	while(timeinfo.tm_year < (2019 - 1900))
	{   
		printf("Time not set, trying...\n");
		vTaskDelay(5000 / portTICK_PERIOD_MS);
		time(&now);
                localtime_r(&now, &timeinfo);
      }

	while(1)
	{
		
		time(&now);
		setenv("TZ", "UTC-5:30", 1);
		tzset();
		tmp = localtime( &now );
		strftime(Timebuffer, sizeof(Timebuffer), "%d/%m/%Y  %I:%M:%S %p", tmp);
	
		vTaskDelay(999 / portTICK_RATE_MS);
	}
}
but sometimes it does not gives time instantly or can't get time.
Don't know what is the problem.
please help me out to solve this.
--
Somesh Burkule

Ritesh
Posts: 722
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: NTP server giving time after long time

Postby Ritesh » Fri Jan 11, 2019 5:04 pm

Hi,

We have used ntp into our project but we have applied all server which are used for ntp server configuration. So, We haven't faced any issue like that.

Would you please try with that as provided into sntp example and check with that?

It might be like sometime you will not get time from server and you will get it from second server as quickly as possible.
Regards,
Ritesh Prajapati

burkulesomesh43
Posts: 113
Joined: Tue Aug 14, 2018 6:21 am

Re: NTP server giving time after long time

Postby burkulesomesh43 » Fri Jan 11, 2019 5:34 pm

Ritesh wrote:
Fri Jan 11, 2019 5:04 pm
Hi,

We have used ntp into our project but we have applied all server which are used for ntp server configuration. So, We haven't faced any issue like that.

Would you please try with that as provided into sntp example and check with that?

It might be like sometime you will not get time from server and you will get it from second server as quickly as possible.
can you please provide example you have used?
how can we use two servers?
--
Somesh Burkule

Ritesh
Posts: 722
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: NTP server giving time after long time

Postby Ritesh » Sat Jan 12, 2019 10:55 am

burkulesomesh43 wrote:
Fri Jan 11, 2019 5:34 pm
Ritesh wrote:
Fri Jan 11, 2019 5:04 pm
Hi,

We have used ntp into our project but we have applied all server which are used for ntp server configuration. So, We haven't faced any issue like that.

Would you please try with that as provided into sntp example and check with that?

It might be like sometime you will not get time from server and you will get it from second server as quickly as possible.
can you please provide example you have used?
how can we use two servers?
Hi,

Please find attached code for reference purpose for SNTP Init Process.

Code: Select all

void initialize_sntp (void)
{
	sntp_setoperatingmode(SNTP_OPMODE_POLL);
	sntp_setservername(0, "pool.ntp.org");
	sntp_setservername(1, "europe.pool.ntp.org");
	sntp_setservername(2, "uk.pool.ntp.org ");
	sntp_setservername(3, "us.pool.ntp.org");
	sntp_setservername(4, "time1.google.com");
	sntp_init();
}
Let me know if still issue after using that.
Regards,
Ritesh Prajapati

burkulesomesh43
Posts: 113
Joined: Tue Aug 14, 2018 6:21 am

Re: NTP server giving time after long time

Postby burkulesomesh43 » Sat Jan 12, 2019 12:22 pm

Ritesh wrote:
Sat Jan 12, 2019 10:55 am
burkulesomesh43 wrote:
Fri Jan 11, 2019 5:34 pm
Ritesh wrote:
Fri Jan 11, 2019 5:04 pm
Hi,

We have used ntp into our project but we have applied all server which are used for ntp server configuration. So, We haven't faced any issue like that.

Would you please try with that as provided into sntp example and check with that?

It might be like sometime you will not get time from server and you will get it from second server as quickly as possible.
can you please provide example you have used?
how can we use two servers?
Hi,

Please find attached code for reference purpose for SNTP Init Process.

Code: Select all

void initialize_sntp (void)
{
	sntp_setoperatingmode(SNTP_OPMODE_POLL);
	sntp_setservername(0, "pool.ntp.org");
	sntp_setservername(1, "europe.pool.ntp.org");
	sntp_setservername(2, "uk.pool.ntp.org ");
	sntp_setservername(3, "us.pool.ntp.org");
	sntp_setservername(4, "time1.google.com");
	sntp_init();
}
Let me know if still issue after using that.
I am getting this issue again.
Actually it gives that issue sometimes only but don't know, why?
--
Somesh Burkule

Ritesh
Posts: 722
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: NTP server giving time after long time

Postby Ritesh » Sat Jan 12, 2019 1:05 pm

burkulesomesh43 wrote:
Sat Jan 12, 2019 12:22 pm
Ritesh wrote:
Sat Jan 12, 2019 10:55 am
burkulesomesh43 wrote:
Fri Jan 11, 2019 5:34 pm


can you please provide example you have used?
how can we use two servers?
Hi,

Please find attached code for reference purpose for SNTP Init Process.

Code: Select all

void initialize_sntp (void)
{
	sntp_setoperatingmode(SNTP_OPMODE_POLL);
	sntp_setservername(0, "pool.ntp.org");
	sntp_setservername(1, "europe.pool.ntp.org");
	sntp_setservername(2, "uk.pool.ntp.org ");
	sntp_setservername(3, "us.pool.ntp.org");
	sntp_setservername(4, "time1.google.com");
	sntp_init();
}
Let me know if still issue after using that.
I am getting this issue again.
Actually it gives that issue sometimes only but don't know, why?
Please send me logs in details because we are using that way and didn't face any issue yet.
Regards,
Ritesh Prajapati

Return to “ESP32 IDF”

Who is online

Users browsing this forum: jcsbanks and 16 guests