Network time

This forum is for posts that might be considered off-topic but that may be useful or interesting to members. Examples include posts about electronics or programming in general, other microcontrollers or interesting devices, useful websites, etc.
Post Reply
dlh
Posts: 395
Joined: 15 December 2006, 12:12 PM
Location: ~Cincinnati

Network time

Post 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
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: Network time

Post 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.
- Don Kinzer
dlh
Posts: 395
Joined: 15 December 2006, 12:12 PM
Location: ~Cincinnati

re: Network time

Post 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?
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: re: Network time

Post 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!
- Don Kinzer
dlh
Posts: 395
Joined: 15 December 2006, 12:12 PM
Location: ~Cincinnati

Re: Network time

Post 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.
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: Network time

Post 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.
- Don Kinzer
dlh
Posts: 395
Joined: 15 December 2006, 12:12 PM
Location: ~Cincinnati

Network time

Post 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.
Post Reply