-->
Page 1 of 2

Esp8266 Spiffs File System Uploading and Reading A File

PostPosted: Sat May 21, 2016 8:07 am
by ajaybnl
Esp8266 have a very good file system. But it is hard for newbies. ;)

So i discovered a way to read files From Spiffs Filesystem.

Esp8266 Repo Did not included the Spiffs Upload Tool which is required for making and uploading Files to Esp8266 FileSystem.

To Upload Files to Spiffs (Esp8266 File System) you need esp8266fs.jar Placed like:

Program files/Arduino/tools/ESP8266FS/tool/esp8266fs.jar

Download: https://github.com/esp8266/arduino-esp8266fs-plugin/releases/download/0.2.0/ESP8266FS-0.2.0.zip

Check Updates: https://github.com/esp8266/arduino-esp8266fs-plugin/releases


Image

Next you need to Make New Sketch to test Spiffs:

Code: Select all
#include"FS.h"

void setup() {
  Serial.begin(115200);

  bool ok = SPIFFS.begin();
  if (ok) {
    Serial.println("ok");
    boolexist = SPIFFS.exists("/index.html");

    if (exist) {
      Serial.println("The file exists!");

      File f = SPIFFS.open("/index.html", "r");
      if (!f) {
        Serial.println("Some thing went wrong trying to open the file...");
      }
      else {
        int s = f.size();
        Serial.printf("Size=%d\r\n", s);


// USE THIS DATA VARIABLE

        String data = f.readString();
        Serial.println(data);

        f.close();
      }
    }
    else {
      Serial.println("No such file found.");
    }
  }
}


void loop() {
  // put your main code here, to run repeatedly:

}



Now Save your sketch, Go to Sketch Data Folder By Pressing Sketch > Show Sketch Folder

Now add a folder name it "data" without quotes.

Image

add some text files in it or make a new one.

(Keep your Baudrate to Highest 921600 if works)

In Arduino Press Tools > Esp8266 Sketch Data Upload

It should upload Spiff files to your esp8266.

It should take some time.

After it completes, Open Arduino Serial Window and then , Upload code to arduino.

Arduino will automatically switch com port to Serial Display when done.

Check your file Contents and Errors.

You can check This inbuilt Sketch too :

Image



I have Sucessfully Loaded Data from SPIFFS to OLED using i2c port.

See This :
Image

Loading Screen:

Image


Documents on SPIFFS: https://github.com/esp8266/Arduino/blob/master/doc/filesystem.md

Making another post for showing complete code. :D

Re: Esp8266 Spiffs File System Uploading and Reading A File

PostPosted: Sun May 22, 2016 11:17 am
by idolpx
PlatformIO makes it really easy to upload your data as well. I'm really loving this IDE.

Image

Image

Re: Esp8266 Spiffs File System Uploading and Reading A File

PostPosted: Wed Jun 29, 2016 1:13 am
by Manti
[quote="idolpx"]PlatformIO makes it really easy to upload your data as well. I'm really loving this IDE.

It looks awesome, but got one question.

When I upload my html files, it seems that the arrive but when I open them its just jiberish.

For example my index.html looks like this:

âí/1.1 200 OK Content-Type: text/html Content-Length: 872 Connection: close Access-Control-Allow-Origin: * À¨hÝâ–;ÿ?ªªintÀ ,¸îe"‚½þ4Öþ4Ö ªªEœ’ÿ1À¨À¨dPÈa!ÒççÝDPK„3HTTP/1.1 200 OK Content-Type: text/html Content-Length: 872 Connection: close Access-Control-Allow-Origin: * ¸îe"‚½þ4ÖESÿ1ËÀ¨À¨d5Ψ?ÍÈÓÁ ymufcvszqkoppertintÀ ,À¨hëÿíh³ôâh`ýPhwf>ÿ?66

Is it possible to upload the files at once, instead of combining them into a *.bin and flashing them?

Re: Esp8266 Spiffs File System Uploading and Reading A File

PostPosted: Thu Jul 14, 2016 11:04 am
by idolpx
How are you reading the files back?

That bin file it creates is the SPIFFS file system.
They have to be arranged into that format for the SPIFFS libraries to be able to access them.