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

Moderator: igrr

User avatar
By danbicks
#25978 Martin, Awesome works :)

Super cool mate.

How can I read and print the contents of a spiffs file to serial window, and search for a specific value?

Need some more examples of spiffs one thinks, not from an avid C background.

Thanks mate

Dans
User avatar
By martinayotte
#25982
danbicks wrote:How can I read and print the contents of a spiffs file to serial window, and search for a specific value?


That would be something like :
Code: Select all    if (!SPIFFS.begin()) {
      Serial.println("SPIFFS failed to mount !\r\n");                   
    }
    else {
      File f = SPIFFS.open("/Config.cfg", "r");
      if (!f) {
        Serial.println("Can't open Config.cfg !\r\n");         
      }
      else {
        char buf[1024];
        f.read((uint8_t *)buf, sizeof(buf));
        f.close();
        Serial.println(buf);
      }
    }


Beware that this small snippet doesn't handle reading of more than 1024, it is reading the whole file in single shot if shorter than 1024. It was only to give you a quick example ASAP.
But the FS.h provides available() method, so it is pretty easy to read file line by line until EOF instead of the previous block read example ...
User avatar
By danbicks
#25989 Martin,

Massive thanks for these snips, I am aware of the 1024 size limitations, Once I get a handle on file operations I will
add checking to all routines to ensure the file size falls within this region.

Thanks so much for all your time on this, much appreciated. I have my sketch already downloading files from a server in the cloud and creating local files on the ESP :)

Dans