Tuesday, 24 August 2021

RTC in ESP8266

RTC in ESP8266


ESP8266 does not have an internal RTC.

You can either add an external one, or simply do an NTP Request at power-up and keep a software clock updated using Time library. Link from esp8266.com

Basic link that clears some other basics: instructables


1) Hardware timer - api & example included in esp sdk.

Official espressif link

Can interfere with other system things & cause crashes (as per the instructables link) hence less preferred.


2) Software timer – based on FreeRTOS
Review timer chapter from official freertos doc.

API provided in SDK is implementing FreeRTOS timer: esp_timer.h/.c

So:

1) get time from NTP server at regular intervals (say every 6 hours) plus at every restart. Timer interrupt may be used for this. InternetSynchTimer.

2) Then maintain the time for another 6 hours using say a MainTimeKeeper Timer (increments 1 every minute and takes care of hour/date/month/year too). Timer interrupt can be used for this.

3) Then there can be task(s) that make decisions based on the current date/time.


Another function noted in esp8266 sdk. May not be best but can consider in other similar requirements:

  • log related. esp_log_early_timestamp()

Link from espressif

 

No comments:

Post a Comment