- Thu Mar 31, 2016 5:53 pm
#44607
I found this code from a quick google on the subject and it explains how to send a query to google to get the time - you could use this if your ESP has an internet connection
-- retrieve the current time from Google
-- tested on NodeMCU 0.9.5 build 20150108
conn=net.createConnection(net.TCP, 0)
conn:on("connection",function(conn, payload)
conn:send("HEAD / HTTP/1.1\r\n"..
"Host: google.com\r\n"..
"Accept: */*\r\n"..
"User-Agent: Mozilla/4.0 (compatible; esp8266 Lua;)"..
"\r\n\r\n")
end)
conn:on("receive", function(conn, payload)
print('\nRetrieved in '..((tmr.now()-t)/1000)..' milliseconds.')
print('Google says it is '..string.sub(payload,string.find(payload,"Date: ")
+6,string.find(payload,"Date: ")+35))
conn:close()
end)
t = tmr.now()
conn:connect(80,'google.com')
code courtesy of
http://benlo.com/esp8266/esp8266Project ... googleTime