RTCS SNTP Always Timeout

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

RTCS SNTP Always Timeout

Jump to solution
1,214 Views
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

Labels (1)
Tags (3)
0 Kudos
1 Solution
556 Views
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 .

View solution in original post

0 Kudos
2 Replies
556 Views
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 Kudos
557 Views
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 Kudos