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)
}
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?
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.
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.
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.
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.
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:
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 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 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)