Decoding NTP packet

Discussion about the ZBasic language including the System Library. If you're not sure where to post your message, do it here. However, do not make test posts here; that's the purpose of the Sandbox.
Post Reply
FFMan
Posts: 502
Joined: 09 January 2010, 12:52 PM

Decoding NTP packet

Post by FFMan »

Does anyone have any code that turns NTP returned packets into date & time that can be used to set the date & time in Zbasic ?

It's described here https://www.eecis.udel.edu/~mills/time.html

I daresay i can work out how to do it, but not into reinventing if someone has some proven code ?

thanks
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: Decoding NTP packet

Post by dkinzer »

FFMan wrote:Does anyone have any code that turns NTP returned packets into date & time that can be used to set the date & time in Zbasic ?
The code that accompanies AN-224 includes a UDP client that has such an NTP converter. In the project NetTime.bas the Main() routine calls a function GetTimeNTP() that does all of the UDP work and returns a value from the server representing seconds since 01 Jan 1900 0:00:00. That value is then manipulated to produce the ZBasic day number and RTC tick values to set the RTC.

So, the extraction of the data from the UDP packet is found in GetTimeNTP() and the setting of the RTC is in Main().
- Don Kinzer
FFMan
Posts: 502
Joined: 09 January 2010, 12:52 PM

Post by FFMan »

thanks Don - that'll save me a lot of time
Post Reply