RTCS SNTP Always Timeout

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

RTCS SNTP Always Timeout

跳至解决方案
1,253 次查看
mohwaqas12
Contributor III

Hello users,

I am trying to use SNTP_oneshot to fetch the time on system start , but i always get timeout , i do not understand what is wrong ,I have initilized my network before using sntp_oneshot, i tried using the same code and tested with my local ip just to see wheather ntp request reach the destination or not.It does reach the destination , attached is the image showing packets captured using wireshark.It timeouts even with any public ntp server.Could anyone suggest what might be wrong.

In attached image :

IP OF MQX : 192.168.10.6

IP OF WINDOWS MACHINE : 192.168.10.19 

Here is the code,

     // Set The time using SNTP  // 192.168.10.19 ip of windows machine which possibly has ntp server

   printf("Fetching Time\n");

  error = SNTP_oneshot(inet_addr("192.168.10.19"),20000);

  if (error!=RTCS_OK){      // IF some error print it

   if(error==RTCSERR_TIMEOUT)

     printf("SNTP Timeout\n");

 

  }

ntp.JPG

标签 (1)
标记 (3)
0 项奖励
1 解答
595 次查看
mohwaqas12
Contributor III

Guys,

     This problem seemed to be solved. I used public ntp server this time , and i got the reply and time was set, but i dont understand why did it get timeout before so many times. Do i have to give some delay to let rtcs initialization to complete before i run sntp_oneshot.

I am now working on setting time to correct timezone , i think i have to plus or minus ticks from the the time struct and set mqx time again with _time_set .

在原帖中查看解决方案

0 项奖励
2 回复数
595 次查看
Nana
Contributor II

If you are watching on the reply from server NTP I believe you used windows w32tm service the server respond to yours ntp request with server 3 version ! If you go deeper in the sntp request when you receive the packet form the server you will make a comparation with the  transmitted message and watch to see if the received header is validated in function "SNTP_valid_header" and another problem is if you watch on the flags you will have set the Unsyncronized alarm set so this means your clock source is not valid!

In the flags field you have :

b7--- b6, b5---b3, b2--b0

Alarm, NTP ver, Mode (serv/client)

So in your send packet you have 0xdc that means 11 for alarm (Unsync), 011,NTP Server ver3, and 100 mode Server

The alarm don't let you to set the correct time and give you timeout error form SNTp_oneshot !

I hope I fully clarify yours problem !

0 项奖励
596 次查看
mohwaqas12
Contributor III

Guys,

     This problem seemed to be solved. I used public ntp server this time , and i got the reply and time was set, but i dont understand why did it get timeout before so many times. Do i have to give some delay to let rtcs initialization to complete before i run sntp_oneshot.

I am now working on setting time to correct timezone , i think i have to plus or minus ticks from the the time struct and set mqx time again with _time_set .

0 项奖励