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
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
It works since the output is
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 data with the function (is it right?) but how I can pass it to the system? How I should manage this problem?
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);
}
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
...
Code: Select all
time_t
Code: Select all
mktime