Hi all! I'm working on a simple standalone datalogger for a programable ECU.
My project is almost done except for one thing: the filename. How can I add a simple index to my filename? See, if I make a datalog now, with the name datalog1.log, the next time that file will be rewritten, so I'm looking to add an auto-updateable index, then if I make a new datalog the filename will be datalog2.log, then datalog3.log. I think I need to check my last file in the SD card and add one more to the filename.
I use date as filename. This is changed at midnight. I guess you could adapt it in may ways to what you want, even to stamp down to the second whenever you start logging.
I once made a very simple logger, where I used a file called numname to holde the last file number used.
Everytime the logger was started this file would be increased by 1.
I the used sprintf() to make the new filename.
The names would be:
sens1.txt
sens2.txt and so on
file.open(root, numname,O_READ); //Read the number in the file
char num=file.read();
Serial.println(num); //just for debugging
file.close();
num++;
file.open(root, numname,O_WRITE); //save new number
file.print(num);
file.close();
Serial.println("Number:"); //just for debugging
Serial.println(num);
//Create new filename and file
num=num-'0';
sprintf(newfile, "sens%02d.txt", num);