Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By kydra1
#80269
btidey wrote:Also you should't be using a return statement in the void function getFileName . You are using a global for filename so the attempted return is not needed.

It makes it clearer if you name the functions according to their purpose so getFileName would be a String or char* function that did actually return the filename whereas makeFileName would be a void that did set up the name like your function does.


Thanks for the reply. I was not sure it was passing "filename" back out of the function, and the naming came out of the example so I just ran with it. :lol:

Any comments on how to name my log file with the contents of "filename"
User avatar
By kydra1
#80270 After some sleep I figured out an answer to my issue. I forced the "/" to be a part of the variable and just adjusted what bits to assign to the date stamp and call it like follows.
Code: Select allchar filename[] = "/00000000.txt";

void makeFileName(){
DateTime now = rtc.now();
filename[1] = (now.year()/1000)%10 + '0'; //To get 1st digit from year()

filename[2] = (now.year()/100)%10 + '0'; //To get 2nd digit from year()

filename[3] = (now.year()/10)%10 + '0'; //To get 3rd digit from year()

filename[4] = now.year()%10 + '0'; //To get 4th digit from year()

filename[5] = now.month()/10 + '0'; //To get 1st digit from month()

filename[6] = now.month()%10 + '0'; //To get 2nd digit from month()

filename[7] = now.day()/10 + '0'; //To get 1st digit from day()

filename[8] = now.day()%10 + '0'; //To get 2nd digit from day()


}

fs::File f = SPIFFS.open(filename, "a");


Thanks for the other suggestions.
If someone has a better way of doing this I'm open to suggestions