Page 1 of 1

Network time

Posted: 06 December 2015, 6:40 AM
by dlh
For use with the ESP8266 can anyone convert either the LUA code that retrieves the Google HEAD data which includes the current time...
https://geonomad.wordpress.com/2015/01/ ... n-esp8266/
or this NTP.c code which gets network time?
https://github.com/shantanugoel/esp8266 ... user/ntp.c

Re: Network time

Posted: 06 December 2015, 8:05 AM
by dkinzer
dlh wrote:For use with the ESP8266 can anyone convert either the LUA code that retrieves the Google HEAD data which includes the current time...
In the Examples-ESP8266 subdirectory of the ZBasic installation directory you'll find a project named ClientTCP which could easily be modified to make a request for the Google page. Then, when the response is received it is a fairly simple matter to extract the time from the text.

Change lines 36 and 37 to

Code: Select all

Const domain as String = "google.com"
Const request as String = "GET / HTTP/1.1" & CRLF
Parsing the response is left as an exercise but you'd replace the code at lines 170-182 with a call to the parsing routine.
dlh wrote:or this NTP.c code which gets network time?
In the same examples directory, the ClientUDP project queries an NTP server and displays the returned time.

re: Network time

Posted: 22 December 2015, 12:33 PM
by dlh
I have an application where I want to use an ESP8266 to act as a serial connection via WiFi and also get NTP time periodically, updating the RTC as needed. I plan to use a TPS2110 MUX to automatically switch the ESP8266 to 3V battery power when the main power is lost, record the time and date to RTC flash (RTC.MemWrite), and go into DeepSleep. When main power is restored the ESP8266 will wake, get NTP time, update the RTC and report the length of the outage.

How do I signal the ESP8266 to wake up?

Re: re: Network time

Posted: 22 December 2015, 12:59 PM
by dkinzer
dlh wrote:How do I signal the ESP8266 to wake up?
As indicated in the description for DeepSleep, GPIO16 will go low when the deep sleep period expires. Connect GPIO16 to reset (using a diode, cathode to GPIO16), et voila!

Re: Network time

Posted: 22 December 2015, 13:32 PM
by dlh
dkinzer wrote:As indicated in the description for DeepSleep, GPIO16 will go low when the deep sleep period expires. Connect GPIO16 to reset (using a diode, cathode to GPIO16), et voila!
I need external control. Ideally, I'd like to use a single pin to signal the ESP8266 when the switch to battery has occurred and when the main power has been restored (which may not occur until long after the battery is exhausted).

I'm trying to duplicate the functionality of the M41T81 RTC IC which senses when it switches to battery power and writes the time/date to a register which can be read once the main power is restored.

I do have a 328P (not battery backed) in the mix so it can reset the ESP8266 at power-up, if needed.

Re: Network time

Posted: 22 December 2015, 14:21 PM
by dkinzer
dlh wrote:I'd like to use a single pin to signal the ESP8266 when the switch to battery has occurred and when the main power has been restored (which may not occur until long after the battery is exhausted).
I'm not sure what the power consumption of the ESP8266 will be when it comes out of Deep Sleep with GPIO16 not connected to reset. If it just sits there at a low power level, perhaps you could just reset it from an external source when power is restored. I suspect that you'll want to use Persistent Memory rather than the RTC memory because when the battery is exhausted the RTC contents disappears.

So, when the "on battery" signal occurs, write the current time to Persistent Memory and go into Deep Sleep. Later, when the "not on battery" signal is present when the device is reset and there is a valid time stored in Persistent Memory, reset the RTC using that data.

Network time

Posted: 22 December 2015, 15:57 PM
by dlh
After gnawing it over I've come to the confusion that sticking with the M41T81S for an RTC is the simplest way to go. It can keep time for 10+ years powered by a coin cell battery. And, there's no significant difference in cost or board space.