Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

NIST Daytime Protocol Client


  • Please log in to reply
2 replies to this topic

#1 baxter

baxter

    Advanced Member

  • Members
  • PipPipPip
  • 415 posts

Posted 11 September 2011 - 08:26 PM

I am attaching a class that implements the NIST Daytime protocol to set the Netduino Plus clock. This protocol has a lightweight easy to parse format consisting of 51 ascii bytes,
MJD   YYMMDD   HHMMSS    DST LS H  ADV  MISC
49010 93-01-23 22:01:22  00  0  0  50.0 UTC(NIST) *
DST is the daylight saving time flag. LS is the leap second flag. H is server health and ADV is the variable time advance of the transmission (in milliseconds) to compensate for the delay.

see: http://www.nist.gov/...8/grp40/its.cfm

To use it,

In main(),
Dim Nist_time as DaytimeNIST = New New DaytimeNIST("time-a.nist.gov", -8)
NIST_Time.getTimeNIST()
Debug.Print("Clock set: " & NIST_Time.successful)
Debug.Print("Server used: " & NIST_Time.TimeServer)
Debug.Print("Time from NIST  " & NIST_Time.networkDateTime)
Debug.Print("Current time set from DayTimeNIST: " & DateTime.Now.ToString)

The Netduino Plus clock is now set and running with local time corrected for UTC offset and standard/daylight savings time. The parameters are the server and the UTC offset. The example server is usually always busy on Daytime, but will demonstrate the internal selection of servers in getTimeNIST. It will try to connect to the instantiated server 3 times after waiting 5 sec. each try (per NIST instructions) and then select a new server. The internal servers are almost always reliable so you can strip out all of this for a more lightweight class.

I have incorporated this class into my port of Nevyn's webserver and it seems to work just fine getting and setting time through the browser. Commands,

http://192.168.0.106...nd.html?settime

http://192.168.0.106...nd.html?gettime

In command processor,
Case "gettime"
        Send(client, "Time from Netduino: " & DateTime.Now.ToString)       
Case "settime"               
        Dim NIST_Time As DaytimeNIST = New DaytimeNIST("time-a.nist.gov", -8)
        NIST_Time.getTimeNIST()
        Dim newTime As String = DateTime.Now.ToString
        NIST_Time = Nothing
        Send(client, "<html><body><p>" & "Set Time " & newTime & "</p></body></html>")

N.B. I had to add this statement at the very beginning of processRequest to stop a periodic exception,

If (request Is Nothing) Then Exit Sub

There is some strange interaction I haven't tracked down yet. I am getting a request from the router address in Listen (sometimes) after issuing the command settime from the browser.

Baxter

Attached Files



#2 erich

erich

    Member

  • Members
  • PipPip
  • 21 posts
  • LocationFrance

Posted 13 September 2011 - 08:09 PM

I used a Socket solution like the one mentioned here and mentioned by Moskus in another forum. It's a self contained soltion that doesnot use too much memory.

#3 Moskus

Moskus

    Advanced Member

  • Members
  • PipPipPip
  • 132 posts
  • LocationNorway

Posted 27 September 2011 - 09:21 AM

Wow, this is an excellent function! I especially likes that you have made an option to use multiple servers, if others fail. Very good! :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.