The information I have found is conflicting. Is there a way to set the internal clock on the ESP8266 and have it keep time? Yes I know it drifts a bit. I'm trying to design something that sends an email if a door is left open after a certain time. I found an example that grabs the time via NTP and sends an email but the time is just a static variable, it never increments. I need the ESP8266 to just keep track of the time and send an email if the door is left open say after 22:00. I found the NTP example libraries but they keep hitting the NTP server for updates. It should really only have to adjust once a day. I planned on using a state machine to keep track of the time and the door status. Thanks.
The ESP8266 does not have an internal "RTC". Any 'clock', like a timepiece, would be based on millis (). The NTP could be used to 'zero' it out (once a day, or however often).
see the NTP-TZ-DST example
notice this part
// OPTIONAL: change SNTP update delay
// a weak function is already defined and returns 1 hour
// it can be redefined:
// uint32_t sntp_update_delay_MS_rfc_not_less_than_15000 ()
//{
// //info_sntp_update_delay_MS_rfc_not_less_than_15000_has_been_called = true;
// return 15000; // 15s
//}
The esp8266 internal RTC is software but works very well in my experience. You only need to add a handful of code lines to your sketch.
https://werner.rothschopf.net/202011_arduino_esp8266_ntp_en.htm
By default it syncs with the NTP server once every hour, which is ok for your application, I think.
as already mentioned, use the NTP functionality from the ESP (not from an external library).
The default interval for the NTP is 1h. The syncs with the NTP server is done in the background. You can modify these 1h interval but imho 1h / 24x per day is acceptable for a NTP request.
Thanks everyone. This helped clear things up for me.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.