I’m working with code from the Web Servers course 3.4 – Web Server: Display Sensor Readings from File (Charts). I have converted it to store readings on an SD card and now wish to rename the resulting file with the week number and year. I can print out the week number but can’t find out how to assign it to a string, so that I can concatenate it with the year. The code that prints the week number is below (see bold type), but I need to assign the (&timeinfo, “%V”) part to a string literal.
Any ideas?
// Function that gets current epoch time
unsigned long getTime() {
time_t now;
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
Serial.println(“Failed to obtain time”);
return(0);
}
time(&now);
currentTime = (time(&now) + gmtOffset_sec + daylightOffset_sec);
Serial.print(“Week No. = “);
Serial.println(&timeinfo, “%V”);
return currentTime;
}
Hi Tony.
See the example in this tutorial: https://randomnerdtutorials.com/esp32-date-time-ntp-client-server-arduino/ See the last part of the example code. It shows how to do that.
Let me know if you need further help.
Regards,
Sara