LittleFS malfunction

Please, I am new on this forum and I am trying to host a simple site on my esp32 using LittleFS. LittleFS mounts successfully but the site returns a 'page can't be found' error. Below is the sketch I used:

#include <WiFi.h>
#include <ESPAsyncWebSrv.h>
#include "LittleFS.h"

// Replace with your WiFi credentials
const char* ssid = "Hail";
const char* password = "Hail Hydra";

// Create web server on port 80
AsyncWebServer server(80);

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

  delay(2000);

  // 1. Mount LittleFS (flash storage)
  if (!LittleFS.begin(true)) {
    Serial.println("LittleFS Mount Failed");
    return;
  }
  Serial.println("LittleFS Mounted Successfully");

  // 2. Connect to WiFi
  WiFi.begin(ssid, password);
  Serial.print("Connecting to WiFi");

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("\nWiFi Connected!");
  Serial.print("ESP32 IP Address: ");
  Serial.println(WiFi.localIP());

  // 3. Serve index.html at root "/"
  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
    request->send(LittleFS, "/index.html", "text/html");
  });

  // 4. Serve ALL static files automatically (CSS, JS, images)
  server.serveStatic("/", LittleFS, "/");

  // 5. Start server
  server.begin();
  Serial.println("Web Server Started");
}

void loop() {
  // Nothing needed here (Async server handles everything)
}

Welcome to the forum

You started a topic in the Uncategorised category of the forum when its description explicitly tells you not to

Your topic has been moved to a relevant category. Please be careful in future when deciding where to start new topics

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

In my experience the easiest way to tidy up the code and add the code tags is as follows

Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

Once the code in your post has been tidied up, could you also explain a little about how you went about uploading the index.html file to the LittleFS partition on the ESP32?

What version of the Arduino IDE are you using, and what is the link to the LittleFS.h library?

It seems that this library is for the ESP8266, but I need to confirm the source link.

the latest version

Your other topic on the same subject deleted.

Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.

Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.

Repeated duplicate posting could result in a temporary or permanent ban from the forum.

Could you take a few moments to Learn How To Use The Forum

It will help you get the best out of the forum in the future.

Thank you.

I created a folder called date inside the folder containing my sketch. The data folder then contains the files making up my site in the normal order

You will still need to do Tools->ESP32 Sketch Data Upload.
Python needs to be installed and the board needs to be in 'flash' - boot mode to do this.

In an application of mine where I use the LittleFS file system, in setup() I print out the names of the files in the root directory to check that these are there. Maybe you could do something similar. I seem to remember I avoided long (more than 3 character) file extensions and kept the filenames to an 8.3 format and maybe ".html" is too long.

  // open LittleFS file system
  if (!LittleFS.begin(false)) {  // don't attempt to create if FS not found
    log_e("LittleFS.begin() fail - we can't proceed ");
    while (1) { ; }
  } else log_i("LittleFS.begin() ok");


  // let's see what is in the root directory
  File root = LittleFS.open("/");
  File file = root.openNextFile();
  while (file) {
    String fn = String("/") + String(file.name());
    log_i("%s", fn.c_str());
    file = root.openNextFile();
  }

I tested your code with my IDE (2.3.3) and it worked correctly.
I've had problems naming an .html file before; I used just htm, which is correct, but in my sketch I used html, and the ESP didn't recognize it.

lemme try that

I am curious whether you got the LittleFS Upload tool working?

This post has prompted me to get it set up on my laptop because I am going to need it soon but I can't get it to show up within the command list (Ctrl-Shift-P) in IDE 2.3.7.

Did you do something like what is described here to install the uploader tool ?

I was following the instructions on the Github:

https://github.com/earlephilhower/arduino-littlefs-upload

However, that Tutorial is showing essentially the same thing just with screenshots to illustrate. Following that tutorial, the point where I get stuck is here:

5) Restart or open the Arduino IDE 2. To check if the plugin was successfully installed, press [⌘] + [Shift] + [P] to open the command palette. An instruction called ‘Upload LittleFS to Pico/ESP8266/ESP32‘ should be there (just scroll down or search for the name of the instruction).

The "instruction" is not present in the list.

I am working on Linux, so could be a Windows vs Linux thing. Not sure at this point.
Op so far hasn't mentioned whether they have installed it or followed post #8 yet, so I was curious whether they had, and if so whether they could see the plugin in the list.

UPDATE:
This is now solved in my case. The problem was an open IDE window hiding behind the open browser, so the IDE did not get properly shut down and restarted. Once ALL windows were closed and the IDE restarted, the tool appeared in the list.

I prints on the serial monitor that littlefs was mounted successfully but the web pages do not show at all

Its good that LittleFS is mounted successfully. You have also copied files into a 'data' folder in your sketch folder. However, there are steps required to actually upload the .html or .htm files to the ESP32. To do that you first need to download the Arduino LittleFS Upload tool from:

https://github.com/earlephilhower/arduino-littlefs-upload/releases/tag/1.6.3

The .vsix file is the copied to the .ArduinoIDE/plugins folder.

If the plugins folder does not exist, you simply create it.

I wondered whether you have managed to complete that step?

wow, never heard of this.
Lemme try that now
Thanks by the way.

BTW, could you please confirm which operating system you are using?
Once the tool is installed in the correct folder, you open the IDE again, and use the [⌘] + [Shift] + [P], [Win] + [Shift] + P or [Ctrl] + [Shift] + [P] depending on the OS you are using, to open the command palette. Either search or scroll down for the `Upload LittleFS to Pico/ESP8266/ESP32' command.

post 1 still looks ugly. Help us keep the forum an interesting place to visit, do you part please.

➜ Please correct your post and add code tags around your code.

There is a small pencil image below your existing posts.

  • click on this pencil ➜ that will let you edit your post.
  • Select the part of the text that corresponds to the code
  • Click on the <code/> icon in the toolbar to indicate that it is code
  • make sure the 3 back-ticks at the start and end of the code part are on a line by themselves
  • click image Save Edit

(Also make sure to properly indent the code in the IDE before copying and pasting it here. This can be done by pressing ctrlT on a PC or cmdT on a Mac)

ok, I use windows 11