Spinneret Web Server with SNTP RTC Sync and DHCP IP Renewal
Mike G
Posts: 2,702
That's a lot of acronyms. The WebServer_5100.spin (Spinneret) library has been updated to include Beau's SNTP library. On start up, the SNTP server is queried. The time returned is used to update the RTC. The marked time is also used to renew the DHCP lease in 12 hour increments.
WebServer_5100.spin contains four utilities. Two are old demos that allow clients to set and get PIN IO parameters. The other two are newer and related to the RTC and SNTP.
Let's say you want to light the Spinneret user LED.
Get the RTC time
Sync RTC with an SNTP server and return the time
Don't invoke the SNTP time multiple times quickly. Maybe once every 15 seconds - if that. Otherwise, you might get your IP blocked for a bit.
There are many SNTP server to choose from. Pick one that's close to you and update the DAT sections.
http://tf.nist.gov/tf-cgi/servers.cgi
Don't forget to set your time zone in the CON block
Let me know if you find any problems.
Please, always check the Google code for the latest source code.
WebServer_5100.spin contains four utilities. Two are old demos that allow clients to set and get PIN IO parameters. The other two are newer and related to the RTC and SNTP.
Let's say you want to light the Spinneret user LED.
http://192.168.1.110/pinstate.xml?led=23&value=1 Value = 1 -> Turn On Value = 0 -> Turn Off Value = -1 -> Query State
Get the RTC time
http://192.168.1.110/time.xml <root> <time>02/17/2013 16:59:25</time> </root>
Sync RTC with an SNTP server and return the time
Don't invoke the SNTP time multiple times quickly. Maybe once every 15 seconds - if that. Otherwise, you might get your IP blocked for a bit.
http://192.168.1.110/sntptime.xml <root> <time>02/17/2013 17:01:38</time> </root>
There are many SNTP server to choose from. Pick one that's close to you and update the DAT sections.
http://tf.nist.gov/tf-cgi/servers.cgi
DAT [B]sntpIp byte 64, 147, 116, 229[/B] '<- This SNTP server is on the west coast version byte "1.1", $0
Don't forget to set your time zone in the CON block
{{ USA Standard Time Zone Abbreviations }} #-10, HST,AtST,_PST,MST,CST,EST,AlST {{ USA Daylight Time Zone Abbreviations }} #-9, HDT,AtDT,PDT,MDT,CDT,EDT,AlDT [B]Zone = MST[/B] '<- Insert your timezone'
Let me know if you find any problems.
Please, always check the Google code for the latest source code.
Comments
Did you implement the latest bug fix in the SNTP driver? I think I have solved the issue here...
http://forums.parallax.com/showthread.php/145697-SNTP-Simple-Network-Time-Protocol-BUG-fix-Update
On a Windows PC there is a setting for Arizona.
It's not critical. I was hoping to get the time via SNTP and not write software to switch between PST and MST.
Starting in 2007, it is observed from the second Sunday in March to the first Sunday in November
Read more: Daylight Saving Time — Infoplease.com http://www.infoplease.com/spot/daylight1.html#ixzz2LITYVtc6
Am I correct in this assumption? I haven't found anything that says definitively one way or another. But to me, it makes sense that a time server would not adjust for this automatically... it just spits out the actual number of seconds since whatever date the protocol works with.
I forgot to post this earlier. I realize my humantime method isn't quite as sophisticated as what was Beau wrote, but I wanted to get the daylight savings time feature finished. Since I use my own humantime method instead of the original one in the object, I'll just post it here to show the concept.
It works great, and is quite easy to expand on. It's really nothing more than checking a set of ntp values that are encountered during daylight savings time periods. Finally, I've made a statement instead of asking more questions! heh.
And, as a FREE BONUS (insert cheesy commercial music here) here is a decoding method... it doesn't consider daylightsavings, but otherwise it works hand in hand with the above human time method. Adapting it to decode to the correct ntp value with daylight savings wouldn't be too difficult. Maybe I'll do that soon.