-->
Page 1 of 1

SPIFFS files return empty

PostPosted: Thu Mar 03, 2022 4:15 pm
by Stickybit
Hi all

Returning to an older project - I suddenly got the stangest behavior: Files on SPIFFS filesystem reads empty - as in no output from files. :-o

I guess that all libraries has been updated since i last worked on the project, so some error has been introduced. A simple sketch for testing:

Code: Select all#include <FS.h>

void setup() {
  Serial.begin(9600);
  if (!SPIFFS.begin()) {
    Serial.println("SPIFFS failed to mount !\r\n");
  }

}

void loop() {

  Dir dir = SPIFFS.openDir("/");
  while (dir.next()) {
    Serial.print(dir.fileName());
    Serial.print(" - ");
    Serial.println(dir.fileSize());
  }

  delay(1000);

  File f = SPIFFS.open("/index.html", "r");
  if (!f) {
    Serial.println("file open failed");
  }

  for (int i = 1; i <= 10; i++) {
    String s = f.readStringUntil('\n');
    Serial.print(i);
    Serial.print(":");
    Serial.println(s);
  }

  delay(3000);
}


This sketch returns the list of files .. but reading a file returns nothing:

Code: Select all/configuration.js - 810
/index.html - 4010
/jquery-3.3.1.min.js - 86927
/jquery-confirm.min.css - 22581
/jquery-confirm.min.js - 27734
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:


SPIFFS filesystem is created like this:

Code: Select all"%LOCALAPPDATA%\Arduino15\packages\esp8266\tools\mkspiffs\3.0.4-gcc10.3-1757bed\mkspiffs.exe" --create website --block 8192 --page 256 --debug 5 --size 1048576 SPIFFS.bin


Any thoughs on this one?

Best regards, Stickybit

Re: SPIFFS files return empty

PostPosted: Sat Mar 05, 2022 6:23 am
by rpiloverbd
As you're facing problems with SPIFFS, you can take a look at this tutorial. This is about controlling an AC bulb through a web server. This tutorial is based on ESP8266. It shows in detail how to create a web server with ESP8266 using SPIFFS. The 'Files on webserver' part may help you.
https://www.theengineeringprojects.com/ ... piffs.html