Shop OBEX P1 Docs P2 Docs Learn Events
Revised SNTP object for use with HTTPServer by Mike G — Parallax Forums

Revised SNTP object for use with HTTPServer by Mike G

RforbesRforbes Posts: 281
edited 2012-12-08 15:47 in Accessories
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. :smile:

*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

  • Mike GMike G Posts: 2,702
    edited 2012-12-07 17:19
    Awesome Rforbes! Thank you for the contribution. I plan to roll SNTP1.2 into a socket object for the W5200. This will be very useful for DHCP lease renewal.
  • RforbesRforbes Posts: 281
    edited 2012-12-08 15:47
    Haha!!!! That's really flattering. :smile: But uhhh... if it blows up, my evil twin wrote it!! Yeah. My Evil twin!!!
Sign In or Register to comment.