settimeofday() not working

dandydan51
Posts: 5
Joined: Sat Aug 26, 2023 9:34 pm

settimeofday() not working

Postby dandydan51 » Wed Feb 28, 2024 2:04 am

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?

ESP_Sprite
Posts: 9727
Joined: Thu Nov 26, 2015 4:08 am

Re: settimeofday() not working

Postby ESP_Sprite » Wed Feb 28, 2024 5:23 am

Did you

Code: Select all

#include <sys/time.h>
?

dandydan51
Posts: 5
Joined: Sat Aug 26, 2023 9:34 pm

Re: settimeofday() not working

Postby dandydan51 » Wed Feb 28, 2024 3:23 pm

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?

MicroController
Posts: 1701
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: settimeofday() not working

Postby MicroController » Wed Feb 28, 2024 6:53 pm

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/)

Who is online

Users browsing this forum: Bing [Bot] and 125 guests