SD filename as date?

ilioss
Posts: 17
Joined: Tue Sep 05, 2017 1:43 pm

SD filename as date?

Postby ilioss » Mon Apr 06, 2020 6:04 pm

Hello,
Esp82266 running with SD library it is posible to give files a date name like 2020-4-19.csv
With the ESP32 this is not working. Esp32 is using the me-no-dev github library.
Many attempts to solve this no succes.
Dus any one has a solution?
Any help is more then welcome.
Alternatively will the use of Esp idf will do the job. Arduino no succes until now.
Like to hear.
Kind regards
ilioSS
Ps Esp32 doit devkit

pipi61
Posts: 34
Joined: Fri Dec 23, 2016 10:58 pm

Re: SD filename as date?

Postby pipi61 » Mon Apr 06, 2020 6:17 pm

try underscore?

ilioss
Posts: 17
Joined: Tue Sep 05, 2017 1:43 pm

Re: SD filename as date?

Postby ilioss » Mon Apr 06, 2020 7:40 pm

Hello pipi61

Underscore already used no succes.
In script from me-no-dev file name is
Const char * path.
String filename;

path = filename.c_str();
Here I used the underscore. No succes.
Was this your ideer as wel?
Thanks for your reply.
Regards ilioSS

pipi61
Posts: 34
Joined: Fri Dec 23, 2016 10:58 pm

Re: SD filename as date?

Postby pipi61 » Mon Apr 06, 2020 9:31 pm

I check https://github.com/espressif/arduino-es ... SDMMC_Test
change hello.txt to 2020-4-19.txt
results ok:
...
Writing file: /2020-4-19.txt
File written

Appending to file: /2020-4-19.txt
Message appended

Reading file: /2020-4-19.txt
Read from file: 2020-4-19 World!
Deleting file: /foo.txt
File deleted

Renaming file /2020-4-19.txt to /foo.txt
File renamed
....
and try https://github.com/espressif/arduino-es ... D_Test.ino
then works:
...
Writing file: /2020-4-19.txt
File written
Appending to file: /2020-4-19.txt
Message appended
Reading file: /2020-4-19.txt
Read from file: 2020-4-19 World!
Deleting file: /foo.txt
File deleted
Renaming file /2020-4-19.txt to /foo.txt
File renamed
Reading file: /foo.txt
Read from file: 2020-4-19 World!
...

ilioss
Posts: 17
Joined: Tue Sep 05, 2017 1:43 pm

Re: SD filename as date?

Postby ilioss » Tue Apr 07, 2020 6:30 am

Hello pipi61

Thanks again.
I did just the same with same result.
The problem is writeFile(SD, "Hello.txt");
Howe to convert date into writeFile(SD,"2020-4-19"); ?

String handling didn't work by me.
Like to hear.
Regards ilioSS

ilioss
Posts: 17
Joined: Tue Sep 05, 2017 1:43 pm

Re: SD filename as date?

Postby ilioss » Tue Apr 07, 2020 6:56 am

Hello pipi61,

Here some program snippets which will explain hopefully,

Code: Select all

// Write the sensor readings on the SD card
void logSDCard() {
  dataPath = String(dayStamp);
String path = dataPath;
 // dataPath = String(dayStamp) +"," + String(timeStamp)+ "\r\r";

  dataMessage = String(readingID) + "," + String(dayStamp) + "," + String(timeStamp) + "," + 
                String(temperature) + "\r\n";
    writeFile(SD, dataPath.c_str(), dataMessage.c_str());             
  Serial.print("Save data: ");
  Serial.println(dataMessage);
//  appendFile(SD, "/data.txt", dataMessage.c_str());
  appendFile(SD, path.c_str(), dataMessage.c_str());
}
Writing file: 2020-04-07
Failed to open file for writing
Save data: 98,2020-04-07,07:52:05,17.50

Appending to file: 2020-04-07
Failed to open file for appending

My idee was to handle the path the same as the message
appendFile(SD, path.c_str(), dataMessage.c_str());

Message works but the file name not.
For analize puroses it is handy to have the file on SD as 2020-4-19.csv

The problem is to have the date into the " " from "Hello.txt" like "2020-4-19.csv" challanging.

Like to hear regards ilioSS

pipi61
Posts: 34
Joined: Fri Dec 23, 2016 10:58 pm

Re: SD filename as date?

Postby pipi61 » Tue Apr 07, 2020 11:54 am

origin: Writing file:/2020-4-19.txt
your without slash:
this where?: Writing file: 2020-04-07
where dayStamp?

ilioss
Posts: 17
Joined: Tue Sep 05, 2017 1:43 pm

Re: SD filename as date?

Postby ilioss » Tue Apr 07, 2020 2:44 pm

Hi pipi61,

I will test with slash as root.
Will come back with result.
Regards ilioSS

ilioss
Posts: 17
Joined: Tue Sep 05, 2017 1:43 pm

Re: SD filename as date?

Postby ilioss » Tue Apr 07, 2020 6:06 pm

Hello pipi61

I just tested the filename inlcuding the / slash and IT WORKS.
I,am realy exited.
See my program snippets;

[code// Write the sensor readings on the SD card
void logSDCard() {
dataPath = String(dayStamp);
String dataPatha = "/"+ dataPath + ".csv";
String path = dataPatha;
dataMessage = String(readingID) + "," + String(dayStamp) + "," + String(timeStamp) + "," +
String(temperature) + "\r\n";
writeFile(SD, dataPath.c_str(), dataMessage.c_str());
Serial.print("Save data: ");
Serial.println(dataMessage);
appendFile(SD, path.c_str(), dataMessage.c_str());
}][/code]

Serial print result;
Reading file: /2020-04-07.csv
Read from file: 0,2020-04-07,18:48:06,23.50
1,2020-04-07,18:48:13,23.50
2,2020-04-07,18:48:20,23.50
3,2020-04-07,18:48:27,23.50
4,2020-04-07,18:48:34,23.50
5,2020-04-07,18:48:42,23.50
6,2020-04-07,18:48:49,23.50
7,2020-04-07,18:48:56,23.50
8,2020-04-07,18:49:03,23.50
9,2020-04-07,18:49:10,23.50
10,2020-04-07,18:49:17,23.50

This means that String handling is the key to have this issue solved.
Many thanks to you to put me on the correcr track.
Kind regards,
ilioSS :D :D

Note: for me this issue can be closed.

pipi61
Posts: 34
Joined: Fri Dec 23, 2016 10:58 pm

Re: SD filename as date?

Postby pipi61 » Tue Apr 07, 2020 6:17 pm

:D

Who is online

Users browsing this forum: JimDrew and 9 guests