Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Error reading Spiffs (Read 4104 times)
Arnold
Junior Member
**
Offline


Posts: 17
Joined: Feb 6th, 2018
Error reading Spiffs
Feb 20th, 2018 at 10:56pm
Print Post  
Hello, 
i saved some html files to the data and used "Publish Server Data Files" to upload it. 

when  i try to open it i just get error when i try to open it. 

Do i need to format the filesystem or is this done with "Publish Server Data Files" ?

String fileRead(String name){
  //read file from SPIFFS and store it as a String variable
  String contents;
  File file = SPIFFS.open(name.c_str(), "r");
  if (!file) {
    String errorMessage = "Can't open '" + name + "' !\r\n";
    Serial.println(errorMessage);
    return "FILE ERROR";
  }
  else {
    
    // this is going to get the number of bytes in the file and give us the value in an integer
    int fileSize = file.size();
    int chunkSize=1024;
    //This is a character array to store a chunk of the file.
    //We'll store 1024 characters at a time
    char buf[chunkSize];
    int numberOfChunks=(fileSize/chunkSize)+1;
    
    int count=0;
    int remainingChunks=fileSize;
    for (int i=1; i <= numberOfChunks; i++){
      if (remainingChunks-chunkSize < 0){
        chunkSize=remainingChunks;
      }
      file.read((uint8_t *)buf, chunkSize-1);
      remainingChunks=remainingChunks-chunkSize;
      contents+=String(buf);
    }
    file.close();
    return contents;
  }
}


page = fileRead("/main.html");
Serial.println(page);


[SPIFFS] size   : 64
[SPIFFS] page   : 256
[SPIFFS] block  : 4096
/main.html
SPIFFS Uploading Image...
[SPIFFS] upload : 72fb5b4228ef5b8b3596a00d0/rollo.ino.spiffs.bin
[SPIFFS] address: 0xEB000
[SPIFFS] reset  : nodemcu
[SPIFFS] port   : COM6
[SPIFFS] speed  : 256000
Uploading 65536 bytes from 72fb5b4228ef5b8b3596a00d0/rollo.ino.spiffs.bin to flash at 0x000EB000
................................................................                 [ 100% ]
SPIFFS Image Uploaded

Thanks for help
« Last Edit: Feb 20th, 2018 at 10:59pm by Arnold »  
Back to top
 
IP Logged
 
Arnold
Junior Member
**
Offline


Posts: 17
Joined: Feb 6th, 2018
Re: Error reading Spiffs
Reply #1 - Feb 20th, 2018 at 11:38pm
Print Post  
After a few tries to upload i can read the file.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Error reading Spiffs
Reply #2 - Feb 21st, 2018 at 1:47pm
Print Post  
Great. Maybe related to how early in cpu startup you try to read the file but only a guess.

The esp can be a bit sensitive at startup. Let me know if you find anything useful about this.

Thanks
  
Back to top
WWW  
IP Logged
 
Arnold
Junior Member
**
Offline


Posts: 17
Joined: Feb 6th, 2018
Re: Error reading Spiffs
Reply #3 - Feb 21st, 2018 at 6:13pm
Print Post  
Hello, 

it looks like it is not stable. 
I recompile the source again and suddenly. i can´t load the file again. 

The fileloading happen only if a user access the webserver. It means it can be 5 minute after startup. 

ESP8266FSUpload.exe
C:\PrjArduino\Rollo\rollo\data\cf.html
C:\PrjArduino\Rollo\rollo\data\main.html
C:\PrjArduino\Rollo\rollo\data\mq.html
C:\PrjArduino\Rollo\rollo\data\ss.html
C:\PrjArduino\Rollo\rollo\data\style.css
C:\PrjArduino\Rollo\rollo\data\wf0.html
SPIFFS Creating Image...
[SPIFFS] data   : C:\PrjArduino\Rollo\rollo\data
[SPIFFS] size   : 64
[SPIFFS] page   : 256
[SPIFFS] block  : 4096
/cf.html
/main.html
/mq.html
/ss.html
/style.css
/wf0.html
SPIFFS Uploading Image...
[SPIFFS] upload : 72fb5b4228ef5b8b3596a00d0/rollo.ino.spiffs.bin
[SPIFFS] address: 0xEB000
[SPIFFS] reset  : nodemcu
[SPIFFS] port   : COM6
[SPIFFS] speed  : 256000
Uploading 65536 bytes from 72fb5b4228ef5b8b3596a00d0/rollo.ino.spiffs.bin to flash at 0x000EB000
................................................................                 [ 100% ]

String loadfile(String path)
{
     Serial.println("loadFile");
     Serial.println(path);

     String page = "";

     SPIFFS.begin();
     FSInfo fs_info;
     SPIFFS.info(fs_info);

     Serial.println(fs_info.totalBytes);
     Serial.println(fs_info.usedBytes);
     Serial.println(fs_info.blockSize);
     Serial.println(fs_info.maxOpenFiles);
     Serial.println(fs_info.maxPathLength);

     // page = fileRead("/main.html");


     File f = SPIFFS.open(path, "r");
     if (!f) {
           Serial.println("file creation failed");
           page = "Error loading File";
     }

     while (f.available()) {

           //Lets read line by line from the file
           char c = f.read();
           page += c;
           
     }
     //Serial.println(f.readStringUntil('\n'));

     //                        }

     f.close();
     Serial.println(page);


     SPIFFS.end();
     return page;
}

String loadfile(String path)
{
     Serial.println("loadFile");
     Serial.println(path);

     String page = "";

     SPIFFS.begin();
     FSInfo fs_info;
     SPIFFS.info(fs_info);

     Serial.println(fs_info.totalBytes);
     Serial.println(fs_info.usedBytes);
     Serial.println(fs_info.blockSize);
     Serial.println(fs_info.maxOpenFiles);
     Serial.println(fs_info.maxPathLength);

     // page = fileRead("/main.html");


     File f = SPIFFS.open(path, "r");
     if (!f) {
           Serial.println("file creation failed");
           page = "Error loading File";
     }

     while (f.available()) {

           //Lets read line by line from the file
           char c = f.read();
           page += c;
           
     }
     //Serial.println(f.readStringUntil('\n'));

     //                        }

     f.close();
     Serial.println(page);


     SPIFFS.end();
     return page;
}

page = loadfile("/main.html");
                 ShowPage(page);

result:
loadFile
/main.html
52961
0
4096
5
32
file creation failed
Error loading File
loadFile
/main.html
52961
0
4096
5
32
file creation failed
Error loading File Cry

  
Back to top
 
IP Logged
 
Arnold
Junior Member
**
Offline


Posts: 17
Joined: Feb 6th, 2018
Re: Error reading Spiffs
Reply #4 - Feb 21st, 2018 at 8:13pm
Print Post  
Sorry, 

i found the Problem. 

I used one unknow library and this wrote direcly into flash memory. 
every time this library destroyed my spiffs after reboot.
it was only writing when the config was changed. thats why it sometimes worked.
before i didn´t realize because i didnt use spiffs. Every config was directly in the flash.
  
Back to top
 
IP Logged
 
Arnold
Junior Member
**
Offline


Posts: 17
Joined: Feb 6th, 2018
Re: Error reading Spiffs
Reply #5 - Feb 26th, 2018 at 3:58pm
Print Post  
I regret to use Spiffs. 

1. The upload tool tell me the file system is full and if i check online there is still 20K from 64 free. 
2. As more full the filesystem as more errors i got during upload. It means the upload tool don´t show any error, but the file itself is corrupt. 
3. I have one file with 16KB. Its always corrupt after upload.
4. If i upload over Webpage then at least the file is ok.
« Last Edit: Feb 26th, 2018 at 4:01pm by Arnold »  
Back to top
 
IP Logged
 
Arnold
Junior Member
**
Offline


Posts: 17
Joined: Feb 6th, 2018
Re: Error reading Spiffs
Reply #6 - Feb 27th, 2018 at 2:32am
Print Post  
This time the problem was, that the memory in ESP for buffering was not enough. 
I´m not sure i just guess its like this. I didn´t get any error. 

I changed to ESP8266Webserver streaming and now big files also works. 
now its also much faster to open a file.
« Last Edit: Feb 27th, 2018 at 2:58am by Arnold »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Error reading Spiffs
Reply #7 - Feb 27th, 2018 at 8:19pm
Print Post  
Great thanks for the update
  
Back to top
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint