Date and Time from a NIST DayTime Server
Posted: Sun Feb 01, 2015 5:34 pm
This is a lightweight client to get the date/time from a NIST DayTime server. The DayTime protocol was designed for minimal processing on limited hardware. The LUA code is a modified version of the httpget.lua example from the LuaLoader Quick Start Guide. Field definitions in the returned string are enumerated in the code comments. The server used is in the last line of code,
conn:connect(13,'utcnist2.colorado.edu')
I use the University of Colorado servers because they are never busy. For other servers, http://tf.nist.gov/tf-cgi/servers.cgi
Output from LuaLoader:
======================
dofile("daytime.lua")
daytime.lua started
>
received
57054 15-02-01 20:40:40 00 0 0 832.3 UTC(NIST) *
extracted Date and Time
2015-02-01 20:40:40
Disconnected
End output
==========
Incidentally, I really like LuaLoader ... thanks for making it available.
conn:connect(13,'utcnist2.colorado.edu')
I use the University of Colorado servers because they are never busy. For other servers, http://tf.nist.gov/tf-cgi/servers.cgi
Output from LuaLoader:
======================
dofile("daytime.lua")
daytime.lua started
>
received
57054 15-02-01 20:40:40 00 0 0 832.3 UTC(NIST) *
extracted Date and Time
2015-02-01 20:40:40
Disconnected
End output
==========
Incidentally, I really like LuaLoader ... thanks for making it available.
Code: Select all
-- File name: daytime.lua
-- tested on NodeMCU 0.9.5 build 20150126
-- adapted from httpget.lua (example from LuaLoader Quick Start guide)
-- Queries NIST DayTime server for a date time string
-- Fixed format returned:
-- JJJJJ YR-MO-DA HH:MM:SS TT L H msADV UTC(NIST) OTM.
-- Ex: 57053 15-01-31 20:14:43 00 0 0 703.0 UTC(NIST) *
-- JJJJJ - the modified Julian Date ( MJD is the Julian Date minus 2400000.5)
-- YR-MO-DA - the Date
-- HH:MM:SS - the Time
-- TT - USA is on Standard Time (ST) or (DST) : 00 (ST)
-- L - Leap second at the end of the month (0: no, 1: +1, 2: -1)
-- H - Health of the server (0: healthy, >0: errors)
-- msADV - time code advanced in ms for network delays
-- UTC(NIST) - the originator of this time code
-- OTM - on-time marker : * (time correct on arival)
print('DayTime.lua started')
conn = nil
conn=net.createConnection(net.TCP, 0)
-- show the server returned payload
conn:on("receive", function(conn, payload)
print('\nreceived')
print(payload)
print('extracted Date and Time')
print('20'..string.sub(payload,8,14)..
string.sub(payload,15,24))
end)
-- show disconnection
conn:on("disconnection", function(conn, payload) print('\nDisconnected') end)
--connect
conn:connect(13,'utcnist2.colorado.edu')