ESP8266 - is there an alternate to ESPAsyncWebSrv?

I ran into an issue with the ESPAsyncWebSrv library regarding SPIFFS, which is no
longer actively supported by the author. So when you compile a deprecated error message is generated under version 1.2.8 (newest) due to the SPIFFS terminology being used in the library files.

The forum members pointed me to a workaround which is to simply revert to the prior library 1.2.7 version. It then compiles w/ no errors.

But as they warned me it is not advisable to continue using a deprecated library version. So I wanted to use a different library package to access the LittleFS file. Something that will allow the 8266 to take a browser request and return the contents of the LittleFS file.

I realize I can set up an array struct instead to record the data and use standard client/server software like I am already using on other ESPs.

But if there is something else that will allow me to make a read file request that would probably be much easier.

This LittleFS_Timestamp example from the IDE Examples works just fine but it has
no way to take a WiFi read file request:

edit - the advantage of the LittleFS file is it is not volatile and will remain even if power is lost.


```cpp
/* Example showing timestamp support in LittleFS */
/* Released into the public domain. */
/* Earle F. Philhower, III <earlephilhower@yahoo.com> */

#include <FS.h>
#include <LittleFS.h>
#include <time.h>
#include <ESP8266WiFi.h>

#ifndef STASSID
#define STASSID "Homestead-LAN_EXT"
#define STAPSK "********"
#endif

const char *ssid = STASSID;
const char *pass = STAPSK;

long timezone = 2;
byte daysavetime = 1;


void listDir(const char *dirname) {
  Serial.printf("Listing directory: %s\n", dirname);

  Dir root = LittleFS.openDir(dirname);

  while (root.next()) {
    File file = root.openFile("r");
    Serial.print("  FILE: ");
    Serial.print(root.fileName());
    Serial.print("  SIZE: ");
    Serial.print(file.size());
    time_t cr = file.getCreationTime();
    time_t lw = file.getLastWrite();
    file.close();
    struct tm *tmstruct = localtime(&cr);
    Serial.printf("    CREATION: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
    tmstruct = localtime(&lw);
    Serial.printf("  LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
  }
}


void readFile(const char *path) {
  Serial.printf("Reading file: %s\n", path);

  File file = LittleFS.open(path, "r");
  if (!file) {
    Serial.println("Failed to open file for reading");
    return;
  }

  Serial.print("Read from file: ");
  while (file.available()) { Serial.write(file.read()); }
  file.close();
}

void writeFile(const char *path, const char *message) {
  Serial.printf("Writing file: %s\n", path);

  File file = LittleFS.open(path, "w");
  if (!file) {
    Serial.println("Failed to open file for writing");
    return;
  }
  if (file.print(message)) {
    Serial.println("File written");
  } else {
    Serial.println("Write failed");
  }
  delay(2000);  // Make sure the CREATE and LASTWRITE times are different
  file.close();
}

void appendFile(const char *path, const char *message) {
  Serial.printf("Appending to file: %s\n", path);

  File file = LittleFS.open(path, "a");
  if (!file) {
    Serial.println("Failed to open file for appending");
    return;
  }
  if (file.print(message)) {
    Serial.println("Message appended");
  } else {
    Serial.println("Append failed");
  }
  file.close();
}

void renameFile(const char *path1, const char *path2) {
  Serial.printf("Renaming file %s to %s\n", path1, path2);
  if (LittleFS.rename(path1, path2)) {
    Serial.println("File renamed");
  } else {
    Serial.println("Rename failed");
  }
}

void deleteFile(const char *path) {
  Serial.printf("Deleting file: %s\n", path);
  if (LittleFS.remove(path)) {
    Serial.println("File deleted");
  } else {
    Serial.println("Delete failed");
  }
}

void setup() {
  Serial.begin(115200);
  // We start by connecting to a WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, pass);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  Serial.println("Contacting Time Server");
  configTime(3600 * timezone, daysavetime * 3600, "time.nist.gov", "0.pool.ntp.org", "1.pool.ntp.org");
  struct tm tmstruct;
  delay(2000);
  tmstruct.tm_year = 0;
  getLocalTime(&tmstruct, 5000);
  Serial.printf("\nNow is : %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct.tm_year) + 1900, (tmstruct.tm_mon) + 1, tmstruct.tm_mday, tmstruct.tm_hour, tmstruct.tm_min, tmstruct.tm_sec);
  Serial.println("");
  Serial.println("Formatting LittleFS filesystem");
  LittleFS.format();
  Serial.println("Mount LittleFS");
  if (!LittleFS.begin()) {
    Serial.println("LittleFS mount failed");
    return;
  }
  listDir("/");
  deleteFile("/hello.txt");
  writeFile("/hello.txt", "Hello ");
  appendFile("/hello.txt", "World!\n");
  listDir("/");

  Serial.println("The timestamp should be valid above");

  Serial.println("Now unmount and remount and perform the same operation.");
  Serial.println("Timestamp should be valid, data should be good.");
  LittleFS.end();
  Serial.println("Now mount it");
  if (!LittleFS.begin()) {
    Serial.println("LittleFS mount failed");
    return;
  }
  readFile("/hello.txt");
  listDir("/");
}

void loop() {}

Probably a dozen or more, you will need to try each one making changes to your code so that it works. I would try AsyncEspFsWebserver first.

I think the deprecated msg can be safely ignored, the WiFi library is not the one being deprecated, it's just the SPIFFS. You might want to check with the WIFI library if there are plans to replace SPIFFS with LittleFS.

1 Like

Thanks. If the processor starts to get wonky I may try a different library but if it keeps humming along I am assuming the "if it ain't broke don't fix it" approach....lol

I'm afraid I don't understand the problem. ESPAsyncWebServer works fine with LittleFS ... at least on ESP32. What are you finding doesn't work with ESP8266?
Please post your existing code that uses SPIFFS and better explain what your problem is converting it to use LittleFS instead.

You need to read the entire thread, it's not his code, it's the library code.

1 Like

Which library code, exactly?

ESPAsyncWebSrv. It does have spiffs internally, but the current version fails on a bad V3 macro. Setting the ver back from 1.2.8 to 1.2.7 fixes the macro issue so he can continue. I have attempted to get the attention of one of the Arduino support people to address the macro issue.

Nonsense. Again, I'm only talking about ESP32 here, so I may be wrong about ESP8266. But, either of these two functions from that library can serve a LittleFS file:

    void send(Stream &stream, const String& contentType, size_t len, AwsTemplateProcessor callback=nullptr);
    void send(File content, const String& path, const String& contentType=String(), bool download=false, AwsTemplateProcessor callback=nullptr);

EXCUSE ME, I am the person who helped the OP get up and running after identifying and fixing a V3 associated error. READ the entire thread .

This has nothing to do with serving any files, it's about fixing a compile error.

@sonofcy
@gfvalvo

Keep it civilised please.

Thank you.

First, what is V3?
And I did read the thread. This:

I take that to mean OP wants to read a file and send it (i.e. serve it) via ESPAsyncWebSrv. If I'm wrong, what DOES it mean and what is ESPAsyncWebSrv supposed to do with the file?

No, two unrelated messages

  • a deprecation warning about SPIFFS
  • an error due to code added to detect, when compiled for ESP32, whether it is version 3 or later
    • that detection code does not compile correctly on ESP8266

Normally, warnings will not break a compile. Some code archaeology reveals the deprecation was four years ago in the ESP8266 core. You've been getting that deprecation warning since then, but just haven't noticed.

Even if you're using LittleFS, seven years ago, a few small changes were made to allow other file systems, but SPIFFS was made the default, changing

    SPIFFSEditor(const String& username=String(), const String& password=String());

to (scroll to the right)

    SPIFFSEditor(const String& username=String(), const String& password=String(), const fs::FS& fs=SPIFFS);

adding a new argument with the default value SPIFFS for ESP8266. Again, that was fine until SPIFFS was deprecated three years after that.

If you're actually specifying LittleFS, you can ignore it.

1 Like

V3 is https://docs.espressif.com/projects/arduino-esp32/en/latest/migration_guides/2.x_to_3.0.html
The library file recently added a macro to test for V3 compatibility or something, in any case it was coded wrong and failed the compiler. That is what I addressed.
What you are talking about is some other way to do what the OP wants, but if that means changing a library module he is not likely to do that. Once again, please read and understand what is happening.

Mod edit, comment removed.

So instead of "V3" what you meant to say is "ESP32 Arduino Core 3.x".

I am trying to understand what OP is trying to do, and obviously failing. So, perhaps either you or he could just post the code that doesn't work (or compiles with deprecation warnings or whatever it does). Then I might understand. I've run across no problems (again with ESP32 Arduino Core 3.x) using LittleFS with ESPAsyncWebSrv. That's why I want to understand OP's problem.

Mod edit, comment removed.

If you read the thread you saw the code in post#1
Again, I am not trying to fix the application, I am simply fixing the compiler error. As @kenb4 just pointed out, the library has a bug when used for an 8266. That is news to me.

The only thing holding me back from a short suspension is that I can see everyone is trying to help the OP.

So please, continue with the help, stop the attacks.

More attacks and I'll stop being restrained.

This may help, the code is old and he got this new error (from original OP)


I did try to check issues but there was no issues button to push (NOTE: I am not trained on GIT, just an 82 yo autistic tube guy having fun with all this solid state stuff. I don't have any education in OOP, and transistors etc)
I 'fixed' his compile error by dropping the ESPAsyncWebSrv library from 1.2.8 to 1.2.7.

It was the SPIFFS error in ESPAsyncWebServ library file version 1.2.8.
I reverted to 1.2.7 and it compiled fine. I guess the latest version was flagging any SPIFFS
reference since the author is no longer actively supporting it.

The reversion is just fine for me and the 8266 seems to be happy that way.

I probably need to just close this thread since there has been confusion about things,
especially with my limited understanding. But after getting updated about the situation just using 1.2.7 for now is a good approach.

edit - to be clear, no one is being intentionally malicious about all this. Everyone has been helpful and gfvalvo came to the party a little late and I probably unwittingly created some of the confusion. I am going to mark this thread solved and we can all just "mellow out" to coin a 70's phrase.