If you are behind a wireless router, you can use a $3 ESP8266-01 for your RTC. Flash the ESP with the Lua nodeMCU
firmware and upload these two scripts to the ESP:
You communicate with the ESP via a serial port. init.lua will automatically run on a powercycle or
soft restart and will obtain an IPaddress. The daytime script is executed by issuing the
command: dofile("daytime.lua") which will return the date/time string, for example, 2015-02-28 16:44:07.
So, you send the command and the ESP will respond via the print statement. The NIST server will
lock you out if you try to query it more frequently than every 5 sec; so, not exactly a RTC clock, but close.
Also, the extraneous print statements and comments should probably be removed from the scripts.
I did a forum search for the ESP8266, but didn't find much except for manuka's post,
http://www.picaxeforum.co.uk/showthread.php?26811-ESP8266-WiFi-serial-module
I am using the Lua firmware because it offers so much more than the AT command set and is
very stable. It has the further advantage of off loading much of the grunt processing from the
host MCU and also has a file system for storing scripts. The disadvantage is that you need to learn
a bit of Lua. so, in case anyone is interested in the ESP with Lua here are some links,
nodeMCU forum:
http://www.esp8266.com/viewforum.php?f=17
nodeMCU firmware(see pre_build) :
https://github.com/nodemcu/nodemcu-firmware
API instruction set:
https://github.com/nodemcu/nodemcu-firmware/wiki/nodemcu_api_en
For development, I use Lua Loader and a PC console TCP client for testing networking:
http://benlo.com/esp8266/index.html#LuaLoader
firmware and upload these two scripts to the ESP:
Code:
-- File name: init.lua
print("set up wifi mode")
wifi.setmode(wifi.STATIONAP)
wifi.sta.config("ret13x","XXXXXXXXX")
--here SSID and PassWord should be modified according your wireless router
wifi.sta.connect()
tmr.alarm(1, 1000, 1, function()
if wifi.sta.getip()== nil then
print("IP unavaiable, Waiting...")
else
tmr.stop(1)
print("Config done, IP is "..wifi.sta.getip())
--dofile("yourfile.lua")
end
end)
-- File name: daytime.lua
-- tested on NodeMCU 0.9.5 build 20150126
-- 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) -- function(conn,payload)
-- show disconnection
conn:on("disconnection", function(conn, payload) print('\nDisconnected') end)
--connect
conn:connect(13,'utcnist2.colorado.edu') -- DayTime protocol sends immediately on connect
soft restart and will obtain an IPaddress. The daytime script is executed by issuing the
command: dofile("daytime.lua") which will return the date/time string, for example, 2015-02-28 16:44:07.
So, you send the command and the ESP will respond via the print statement. The NIST server will
lock you out if you try to query it more frequently than every 5 sec; so, not exactly a RTC clock, but close.
Also, the extraneous print statements and comments should probably be removed from the scripts.
I did a forum search for the ESP8266, but didn't find much except for manuka's post,
http://www.picaxeforum.co.uk/showthread.php?26811-ESP8266-WiFi-serial-module
I am using the Lua firmware because it offers so much more than the AT command set and is
very stable. It has the further advantage of off loading much of the grunt processing from the
host MCU and also has a file system for storing scripts. The disadvantage is that you need to learn
a bit of Lua. so, in case anyone is interested in the ESP with Lua here are some links,
nodeMCU forum:
http://www.esp8266.com/viewforum.php?f=17
nodeMCU firmware(see pre_build) :
https://github.com/nodemcu/nodemcu-firmware
API instruction set:
https://github.com/nodemcu/nodemcu-firmware/wiki/nodemcu_api_en
For development, I use Lua Loader and a PC console TCP client for testing networking:
http://benlo.com/esp8266/index.html#LuaLoader