Revised SNTP object for use with HTTPServer by Mike G
Rforbes
Posts: 281
I've tested this code until my eyeballs hurt, and I'm satisfied that it's solid. If you have a need to use the SNTP object to update the RTC on the spinneret, this code should work.
1- The original SNTP Demo by Beau Schwab had a couple type-O's which caused some problems. Those are fixed.
2- I've ensured that leap years are accounted for in the new HumanTime method properly (up to year 2032 and easily modifiable past that.) This method could definitely be written in a more efficient way, but I'm not up for that just yet.
*NOTE: To use this object you'll need to edit the PUB GetSntpTime(id, BufferAddress)|i in HttpServer.
The above method previously had "if i==56" and this was part of the problem, although a very minor one.
Please let me know if you see any problems with this updated stuff.
Thanks in advance,
Robert
1- The original SNTP Demo by Beau Schwab had a couple type-O's which caused some problems. Those are fixed.
2- I've ensured that leap years are accounted for in the new HumanTime method properly (up to year 2032 and easily modifiable past that.) This method could definitely be written in a more efficient way, but I'm not up for that just yet.
*NOTE: To use this object you'll need to edit the PUB GetSntpTime(id, BufferAddress)|i in HttpServer.
PUB GetSntpTime(id, BufferAddress)|i sntp.CreateUDPtimeheader(BufferAddress,@sntpIp) Socket.txUDP(id, BufferAddress) '<-- Send the UDP packet repeat 100 i := Socket.rxUDP(id, BufferAddress) if i == 52 return 1 Pause(100) '<- if 1000 = 1 sec ; 10 = 1/100th sec X 100 repeats above = 1 sec return 0 '<- Timed out without a response
The above method previously had "if i==56" and this was part of the problem, although a very minor one.
Please let me know if you see any problems with this updated stuff.
Thanks in advance,
Robert
Comments