ESP32S2 store rtc time when reboot

huybk213
Posts: 13
Joined: Tue Jan 01, 2019 9:13 am

ESP32S2 store rtc time when reboot

Postby huybk213 » Sat May 01, 2021 8:12 am

Dear everyone,

I have a question about ESP32 RTC clock.
As Espressif documents said "RTC timer: Allows keeping the system time during any resets and sleep mode" in documents
https://docs.espressif.com/projects/esp ... _time.html

Every time device reset (software reset), i readback rtc time, but it's seem rtc time not stored when device soft reset.

Could you please give me your suggestion, how to keep rtc timer when device reboot?

Thanks.

My code to read timer every device software reset.

Code: Select all

	struct timeval current_time;
	gettimeofday(&current_time, NULL);
	ESP_LOGW(TAG, "seconds : %ld\nmicro seconds : %ld",
    		current_time.tv_sec, current_time.tv_usec);

rfleming
Posts: 62
Joined: Tue Oct 09, 2018 12:30 am

Re: ESP32S2 store rtc time when reboot

Postby rfleming » Tue May 04, 2021 12:44 am

Starting with the "examples/get-started/hellow_world" I added in

Code: Select all

        
        #include <time.h>
	#include <sys/time.h>
	...
        struct timespec tp;
	clock_gettime(CLOCK_REALTIME, &tp);
	int hours = tp.tv_sec / 3600 % 24;
	int minutes = tp.tv_sec / 60 % 60;
	int seconds = tp.tv_sec % 60;
And after each restart, the time value keeps increasing just fine. A hard restart will obviously reset this value.

Who is online

Users browsing this forum: Heggico and 93 guests