How set epoch on ESP32 and Arduino IDE to update the timedate without external RTC and Wifi?

thoraz
Posts: 27
Joined: Tue Jan 28, 2020 4:02 pm

How set epoch on ESP32 and Arduino IDE to update the timedate without external RTC and Wifi?

Postby thoraz » Fri May 22, 2020 10:21 am

On my ESP32 I want to have information about actual time without Wifi connection or an external RTC chip. I started with this simple code

Code: Select all

time_t now;
struct tm* timeinfo;

void Check_Time(void) {
  time(&now);
  timeinfo = localtime(&now);
  Serial.println(timeinfo);
}

void setup() {
  Serial.begin(115200);
}

void loop() {
  Check_Time();
  delay(1000);
}
It works since the output is

Code: Select all

Thu Jan  1 00:07:57 1970
Thu Jan  1 00:07:58 1970
Thu Jan  1 00:07:59 1970
Thu Jan  1 00:08:00 1970
...
and naturally it starts from 1 Jan 1970. Now I want to update this time to the actual one but I haven't found a direct solution. I know that I could convert a date to a

Code: Select all

time_t
data with the

Code: Select all

mktime
function (is it right?) but how I can pass it to the system? How I should manage this problem?

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: How set epoch on ESP32 and Arduino IDE to update the timedate without external RTC and Wifi?

Postby chegewara » Fri May 22, 2020 1:12 pm

https://github.com/espressif/esp-idf/tr ... em/console

If you want to use only internal RTC you have to remember it has a huge drift.


Who is online

Users browsing this forum: No registered users and 112 guests