Post topics, source code that relate to the Arduino Platform

User avatar
By Ribeiro Santos
#44577 Hi,

I want to use ESP (and a relay) to control my curtains: open at 7:30 and close at 20:00. Like arduino, without a RTC, after some days I will have the curtains opened at 7:32 (example), next 7:34... at 8:01 ... and some day will be late at work (9:41 or even more)

What accuracy have the ESP timers or what should I use, without any RTC or Internet connection, to have the curtains opening allways at the same time.

Thanks a lot,
Ribeiro
User avatar
By PostmanPrat
#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