-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Csv-Parser Reading FFat file instead SD card #14
Comments
Hello, the library is mostly independent of underlying file storage. As long as you can read the file into a string (as a whole, or in parts), then you can supply it to CSV_Parser (either in constructor as a whole, or by using I never worked with FFat using esp32 but the following article looks straightforward: You could combine it with existing examples of CSV_Parser, so the return of the These examples could be helpful: |
Hello dear developer. I have implemented a A.I neural cell on the esp32 wroom using AVR 8.1.5 and Arduino IDE 1.8.19. USING THE SD CARD IT WORKED LIKE A CHARM (NO PROBLEM AT ALL) SO to go straight to the point : Now I want to use the same CSV-Parser to parse the same file, BUT NOW from my FILESYSTEM FFat where Denis.csv is uploaded and perfectly READ by the next code
SO I HAVE A String ai_wheights Containing all the data I need to parse. BUT I have not been able to correctly code CSV-Parser to read My String ai_wheights to be parsed. I Tried your proposal as like this But does not compile So I am kind of desperate Now, if you could help me out I will much appreciate please let me know as it looks you have more knowledge than I do. Ing Denis Thornhill |
Hello, here's a small example. First it creates a file using "writeFile". Then it reads it character by character and supplies it to the CSV_Parser object using #include "FS.h"
#include "FFat.h"
#include <CSV_Parser.h>
void writeFile(fs::FS &fs, const char * path, const char * message){
Serial.printf("Writing file: %s\r\n", path);
File file = fs.open(path, FILE_WRITE);
if(!file){
Serial.println("- failed to open file for writing");
return;
}
if(file.print(message)){
Serial.println("- file written");
} else {
Serial.println("- write failed");
}
file.close();
}
const char *denis_csv = "WW1,WW2,WW3,WW4,WW5,WW6,WW7,WW8,VV1,VV2,VV3,VV4,VV5,VV6,VV7,VV8,UU1,UU2,UU3,UU4,UU5,UU6,UU7,UU8\n"
"1.529006002,0.253733553,0,0,0,0,0,0,1.284589032,-0.16966153,0.061992747,-0.446341058,-0.453974486,0.293160251,-0.174254381,1.332099744,6.326600076,1.477596343,-1.496865036,9.003172761,-1.129388801,-2.241994092,-0.106482536,0.333588426\n"
"-0.217656669,0.496886743,0,0,0,0,0,0,-2.521074192,-0.248332009,2.304620566,3.063565941,-0.084831135,-1.245491029,1.169079723,-2.772691784,15.6392119,-6.559343484,-0.76593996,16.95741907,-0.229103923,-2.174205059,-2.783387003,-4.153871339\n"
"-0.685878196,-1.69774026,0,0,0,0,0,0,0.75732003,-0.191953244,2.284465675,0.504071024,-0.457960533,-0.689415175,-0.432202133,-0.505708842,5.091135436,0.857673313,2.886192935,1.381541316,0.413169009,2.899088995,-0.156824798,0.450908032"
"-1.56897012,-0.582719571,0,0,0,0,0,0,0.756744231,0.020471757,-0.605422857,-0.580923655,-0.292100131,0.654582639,-0.195243403,1.491637782,0,0,0,0,0,0,0,0\n"
"-0.600424066,0.294622049,0,0,0,0,0,0,0.156895215,-0.376825887,0.834245199,0.470031922,-0.25945908,-0.135387552,-0.316315596,0.130135589,0,0,0,0,0,0,0,0\n"
"0.75991028,0.84727152,0,0,0,0,0,0,0.021394153,-0.539207383,3.405282902,0.530846276,0.258361585,-0.799486165,0.28407691,-1.038734802,0,0,0,0,0,0,0,0\n"
"-1.221449941,-0.028690932,0,0,0,0,0,0,-2.046529053,0.334116574,0.79527923,1.594805338,0.808990216,-0.38662376,1.547053763,-1.93526403,0,0,0,0,0,0,0,0\n"
"1.524834584,0.646203694,0,0,0,0,0,0,-1.670471979,0.298746015,1.407371203,2.497918847,0.234797764,-0.900750431,1.002674102,-2.564860142,0,0,0,0,0,0,0,0";
void setup(){
Serial.begin(115200);
if(!FFat.begin()){
Serial.println("FFat Mount Failed");
return;
}
writeFile(FFat, "/Denis.csv", denis_csv);
CSV_Parser cp(/*format*/ "ffffffffffffffffffffffff");
File file = FFat.open("/Denis.csv");
if(!file || file.isDirectory()){
Serial.println("- failed to open file for reading");
return;
}
while(file.available()){
cp << (char)file.read();
}
file.close();
cp.parseLeftover(); // needed after reading the whole file when the last line of the file doesn't end with "\n"
cp.print(); // prints all parsed contents
Serial.println("\nVV1 column:");
float *VV1 = (float*)cp["VV1"];
for(int i = 0; i < cp.getRowsCount(); i++) {
Serial.println(VV1[i]);
}
}
void loop(){
} It outputs:
The "writeFile" function I used is copied from |
Hello, just wanted to let you know that since version 1.0.0 (released today), it is necessary to cast the return of while(file.available()){
cp << (char)file.read(); // (char) is needed because file.read() returns integer
} So I edited the example from my previous post. I added a note in README.md explaining why:
|
hello dear developer.
i need to Parse a txt and or CSV comma-separated file, I have been searching for an example code of this CSV-Parser to read file from FILESYSTEM FFat on my esp32 for the last 3 days with no success .
Is CSV-Parser only for Sd ?
any reference for using the library from FFAt will be much appreciated.
Thanks, in advance for your time .
Ing Denis Thornhill
The text was updated successfully, but these errors were encountered: