Page 1 of 1

settimeofday() not working

Posted: Wed Feb 28, 2024 2:04 am
by dandydan51
ESP-IDF documentation says use settimeofday() to set the RTC.

"To stop smooth time adjustment and update the current time immediately, use the POSIX function settimeofday()."

When I compile IDE (VSC) says settimeofday() not declared. Is there a library I need?

Re: settimeofday() not working

Posted: Wed Feb 28, 2024 5:23 am
by ESP_Sprite
Did you

Code: Select all

#include <sys/time.h>
?

Re: settimeofday() not working

Posted: Wed Feb 28, 2024 3:23 pm
by dandydan51
Thank you. #include <sys/time.h> worked.

I have found no mention of sys/time.h anywhere in ESP-IDF documentation or examples. Where should I have found this information?

Re: settimeofday() not working

Posted: Wed Feb 28, 2024 6:53 pm
by MicroController
https://docs.espressif.com/projects/esp ... rrent-time:
use the POSIX function settimeofday().
i.e. it's not an IDF function; that's why it's not specifically documented with the IDF.
The settimeofday () function is a standard function whose definition is mentioned in a header file in the C library named sys/time.h
(https://linuxhint.com/gettimeofday-settimeofday-c/)