Page 1 of 1

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

Posted: Fri May 22, 2020 10:21 am
by thoraz
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?

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

Posted: Fri May 22, 2020 1:12 pm
by chegewara
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.

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

Posted: Fri May 22, 2020 3:17 pm
by lbernstone