I an moving some code from an ESP8266 to an ESP32.
I am using the Arduino IDE
I wish to set an arbitrary date and time
In the ESP8266 code I can use a library function called setTime(). However this doesn't exist in the ESP32 version of the libraries.
There is an example in the Expressif code that uses the Unix-y settimeofday(&tv, &tz) function. However this example requires a header file called coredecls.h that does not appear on the code base I installed with the ESP32 Arduino environment.
What do you do to set the time without using NTP?
with thanks!
How can I set the date / time?
-
- Posts: 7
- Joined: Tue Apr 17, 2018 2:24 pm
Re: How can I set the date / time?
I would like to join this question.What do you do to set the time without using NTP?
Re: How can I set the date / time?
Did you try
Code: Select all
#include <time.h>
#include <sys/time.h>
-
- Posts: 7
- Joined: Tue Apr 17, 2018 2:24 pm
Re: How can I set the date / time?
Yes, but I couldn't figure out what the time val that I should put in settimeofday?
Let's assume I want to update it to 18 June 2018 (now it is on his release data - default), How should I make it?
Let's assume I want to update it to 18 June 2018 (now it is on his release data - default), How should I make it?
Re: How can I set the date / time?
Once you set date and time using
settimeofday
How I can add seconds since boot up get from esp_timer_get_time in seconds.
I guess once you bootup. you lost your date and time. you need to save into nvs or file and on bootup. I need to set it again
using settimeofday and add boot time seconds to it before creation new files to get almost accurate time stamp for files.
I don't have access to internet to get clock time. I pass data time via HTTP when ever I upgrade my firmware.
Some logs files get created while firmware is running.
I set my my current system date/time on startup
then I obtain later . which is fine. but file gets created with time stamp of 1980. any idea?
settimeofday
How I can add seconds since boot up get from esp_timer_get_time in seconds.
I guess once you bootup. you lost your date and time. you need to save into nvs or file and on bootup. I need to set it again
using settimeofday and add boot time seconds to it before creation new files to get almost accurate time stamp for files.
I don't have access to internet to get clock time. I pass data time via HTTP when ever I upgrade my firmware.
Some logs files get created while firmware is running.
I set my my current system date/time on startup
Code: Select all
struct tm tm;
tm.tm_year = 2018 - 1900;
tm.tm_mon = 10;
tm.tm_mday = 15;
tm.tm_hour = 14;
tm.tm_min = 10;
tm.tm_sec = 10;
time_t t = mktime(&tm);
printf("Setting time: %s", asctime(&tm));
struct timeval now = { .tv_sec = t };
settimeofday(&now, NULL);
Code: Select all
time_t now = time(0);
// Convert now to tm struct for local timezone
tm* localtm = localtime(&now);
printf("The local date and time is: %s", asctime(localtm));
Who is online
Users browsing this forum: P Garcia and 6 guests