0

I have a simple HTML file that I have uploaded as sketch data using the ESP8266 sketch data upload tool in arduino IDE. The file is 7k in size.

In the set up, I refer to the following function to read the file:

String readTemplatefile(){
  String retval ="";
  File fr = SPIFFS.open("/templatecfg.htm", "r"); 

  if(!SPIFFS.exists("/templatecfg.htm")){

    Serial.println("Template file not available ");  
    }
    while (fr.available()){
        retval += char(fr.read());
      }

fr.close();
Serial.println("Template file = ");    
Serial.println(retval);
return retval;
}

I always get 'Template file not found'. I have

SPIFFS.begin(); 

at the beginning of the setup function

My board is an ESP8266EX. I have wondered if it the flash size settings in the IDE that could cause this not to be found. Can anyone offer any advice on this issue. I have tried lots of different combinations of Flash size and SPIFF sizes without any luck.

Thanks in advance to any help.

  • Is the file there? Is the media formatted in the right format (FAT? rather than NTFS which Windows will default to) – Code Gorilla Jan 12 '18 at 13:21
  • Did you mount the filesystem with SPIFFS.begin()? Have you tried opening the "/" directory and listing the files, so you can confirm what your sketch sees as the available files? – jose can u c Jan 12 '18 at 13:32
  • @CodeGorilla: SPIFFS, not SD ;) – dandavis Jan 12 '18 at 20:47
  • run the included FS browser example sketch and see how it works. yes, your flash settings can affect SPIFFS, if they are wrong. make sure the IDE size (ESP.getFlashChipSize()) and the physical sizes (ESP.getFlashChipRealSize()) match up. google the esp lib functions for docs – dandavis Jan 12 '18 at 20:50
0

SPIFFS will always claim to successfully open a file that begins with a slash even if that file does not exist. Remove the leading slash.

-1

@dandavis Yes, I had SPIFFS.begin() in my setup routine.

I ran a sample sketch and was able to see the a file on the device, so I routed round the code some more and found than an included library was ending SPIFFS after it had performed a file read. This was the issue. Thanks all for your consideration, but the code I had was fine, just the included library was mis-behaving.

  • what library? so we learn – Juraj Apr 13 '18 at 14:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.