SD Card example with filename in variable

Hello, i want to use the SD_Test.ino example
( arduino-esp32/SD_Test.ino at master · espressif/arduino-esp32 · GitHub )
but the filename should be saved in a variable.
So instead of

    appendFile(SD, "/helloworld.txt", "Hello World!\n");

i want to use some kind of

    appendFile(SD, filename, "Hello World!\n");

and the variable 'filename' is declared as

const char* filename = "/file.txt";

With this scenario, i'll get this message:
[E][vfs_api.cpp:265] VFSFileImpl(): fopen(/sd/capturing.cap) failed

Is it possible to use a variable instead of a static filename? I want to use a timestamp as filename.

Yes. You can use a variable. The only requirement is that it is a string and the string must be no longer than 8 chars.

The file names I use are made up if two four digit numbers that I generate using a calculation. In my case, since I am using bytes to generate the number, I have to convert the string of numbers to a string before sending it to the SD.


char Files[5];
int Current_Long, Current_Lat;
string Infile, EXT;

EXT = "BIN";

itoa(Current_Long,Files,10);
Infile = Files;
itoa(Current_Lat,Files,10);
Infile = Infile + Files + "." + EXT;
[/code]

In the section of code above, "Infile" is the file name that will be sent to the SD.

"Files" is a 4 member array of chars containing four numbers.

"EXT" is a string containing the extension for the file name.

The function "itoa" only works with arrays of chars. The first variable is the input variable, the second is the output variable and the "10" is the numbering system. The numbering system could be binary, HEX, Octal or decimal. In this case I used base 10.

Have fun

[E][vfs_api.cpp:265] VFSFileImpl(): fopen(/sd/capturing.cap) failed

This is in the arduino-esp32 libraries: arduino-esp32/vfs_api.cpp at master · espressif/arduino-esp32 · GitHub

Were you passing a filename of "/capturing.cap"? It looks like the library was unable to create that file. Could there be some permission problem?

In any case you are encountering an ESP32 problem so you will probably get better support in the arduino-esp32 forums.

""Capturing" contains nine (9) letters. With the ADA library you are only allowed eight.

You might look for that in your review of the library requirements