Skip to content

ESP32 filesystem error #3408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DmitryBorisenko33 opened this issue Oct 25, 2019 · 13 comments
Closed

ESP32 filesystem error #3408

DmitryBorisenko33 opened this issue Oct 25, 2019 · 13 comments

Comments

@DmitryBorisenko33
Copy link

DmitryBorisenko33 commented Oct 25, 2019

I have problem with spiffs file system. I am using standard example "FSBrowser"
But files in "data" folder (html, js, css) i am using not like in example. This is my files. This files perfectly running on esp8266 with the same sketch. But when i start using esp32 i have errors during web page refresh.

Here is a link to the file system that I use

Sometimes page stopped like this:

Screenshot_1

"File not Found" but this file exactly exist!!

Sometimes going less:

Screenshot_2

I have now big problem with this. My project is stopped... Please kindly help me. I have already read many information and forums but cant find how to resolve this problem. I found many people who have now same problem.

@lbernstone
Copy link
Contributor

You need to post logs from the esp32 side. Turn on verbose debug and upload your sketch again. Post the serial monitor logging during the file request. Also please include all the hardware information requested in the ISSUE_TEMPLATE.
File locations in esp32 must always start with a /

@DmitryBorisenko33
Copy link
Author

DmitryBorisenko33 commented Oct 26, 2019

I am author of ESP8266 + IOTmanager application modules firmware
This is my project
This is our application now we working on ver 2 this application
Now i trying to transfer my project from esp8266 to esp32
I am using arduino ide 1.8.9 and ESP32 arduino core 1.0.4


Hardware:
Board: TTGO MINI32 V2.0.13 ESP32 rev1 (this board)
Core Installation/update date: 1.0.4 / 02.10.2019
IDE name: Arduino IDE

Flash Frequency: 80Mhz
PSRAM enabled: no
Upload Speed: 921600

Computer OS: Windows 10

Description:
I have problem with spiffs file system. I am using standard example "FSBrowser"
But files in "data" folder (html, js, css) i am using not like in example. This is my files. This files perfectly running on esp8266 with the same sketch. But when i start using esp32 i have errors during web page refresh.

Debug Messages (enable verbose debug) during page refresh:

[V][WebServer.cpp:286] handleClient(): New client
[V][Parsing.cpp:113] _parseRequest(): method: GET url: / search: 
[V][Parsing.cpp:219] _parseRequest(): headerName: Host
[V][Parsing.cpp:220] _parseRequest(): headerValue: 192.168.1.5
[V][Parsing.cpp:219] _parseRequest(): headerName: Connection
[V][Parsing.cpp:220] _parseRequest(): headerValue: keep-alive
[V][Parsing.cpp:219] _parseRequest(): headerName: Cache-Control
[V][Parsing.cpp:220] _parseRequest(): headerValue: max-age=0
[V][Parsing.cpp:219] _parseRequest(): headerName: Upgrade-Insecure-Requests
[V][Parsing.cpp:220] _parseRequest(): headerValue: 1
[V][Parsing.cpp:219] _parseRequest(): headerName: User-Agent
[V][Parsing.cpp:220] _parseRequest(): headerValue: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36
[V][Parsing.cpp:219] _parseRequest(): headerName: Accept
[V][Parsing.cpp:220] _parseRequest(): headerValue: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
[V][Parsing.cpp:219] _parseRequest(): headerName: Accept-Encoding
[V][Parsing.cpp:220] _parseRequest(): headerValue: gzip, deflate
[V][Parsing.cpp:219] _parseRequest(): headerName: Accept-Language
[V][Parsing.cpp:220] _parseRequest(): headerValue: en-US,en;q=0.9,ru;q=0.8,mt;q=0.7
[V][Parsing.cpp:247] _parseArguments(): args: 
[V][Parsing.cpp:230] _parseRequest(): Request: /
[V][Parsing.cpp:231] _parseRequest():  Arguments: 
[E][WebServer.cpp:617] _handleRequest(): request handler not found
[D][WiFiClient.cpp:509] connected(): Disconnected: RES: 0, ERR: 128
[V][WebServer.cpp:286] handleClient(): New client
[V][Parsing.cpp:113] _parseRequest(): method: GET url: /js/build.chart.js search: v07.04.2018
[V][Parsing.cpp:219] _parseRequest(): headerName: Host
[V][Parsing.cpp:220] _parseRequest(): headerValue: 192.168.1.5
[V][Parsing.cpp:219] _parseRequest(): headerName: Connection
[V][Parsing.cpp:220] _parseRequest(): headerValue: keep-alive
[V][Parsing.cpp:219] _parseRequest(): headerName: User-Agent
[V][Parsing.cpp:220] _parseRequest(): headerValue: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36
[V][Parsing.cpp:219] _parseRequest(): headerName: Accept
[V][Parsing.cpp:220] _parseRequest(): headerValue: */*
[V][Parsing.cpp:219] _parseRequest(): headerName: Referer
[V][Parsing.cpp:220] _parseRequest(): headerValue: http://192.168.1.5/
[V][Parsing.cpp:219] _parseRequest(): headerName: Accept-Encoding
[V][Parsing.cpp:220] _parseRequest(): headerValue: gzip, deflate
[V][Parsing.cpp:219] _parseRequest(): headerName: Accept-Language
[V][Parsing.cpp:220] _parseRequest(): headerValue: en-US,en;q=0.9,ru;q=0.8,mt;q=0.7
[V][Parsing.cpp:247] _parseArguments(): args: v07.04.2018
[V][Parsing.cpp:265] _parseArguments(): args count: 1
[V][Parsing.cpp:273] _parseArguments(): pos 0 =@-1 &@-1
[E][Parsing.cpp:275] _parseArguments(): arg missing value: 0
[V][Parsing.cpp:291] _parseArguments(): args count: 0
[V][Parsing.cpp:230] _parseRequest(): Request: /js/build.chart.js
[V][Parsing.cpp:231] _parseRequest():  Arguments: v07.04.2018
[E][WebServer.cpp:617] _handleRequest(): request handler not found
handleFileRead: /js/build.chart.js
[D][WiFiClient.cpp:509] connected(): Disconnected: RES: 0, ERR: 128
[D][WiFiClient.cpp:509] connected(): Disconnected: RES: 0, ERR: 128
[D][WiFiClient.cpp:509] connected(): Disconnected: RES: 0, ERR: 128
[V][WebServer.cpp:286] handleClient(): New client
[V][Parsing.cpp:113] _parseRequest(): method: GET url: /favicon.ico search: 
[V][Parsing.cpp:219] _parseRequest(): headerName: Host
[V][Parsing.cpp:220] _parseRequest(): headerValue: 192.168.1.5
[V][Parsing.cpp:219] _parseRequest(): headerName: Connection
[V][Parsing.cpp:220] _parseRequest(): headerValue: keep-alive
[V][Parsing.cpp:219] _parseRequest(): headerName: Pragma
[V][Parsing.cpp:220] _parseRequest(): headerValue: no-cache
[V][Parsing.cpp:219] _parseRequest(): headerName: Cache-Control
[V][Parsing.cpp:220] _parseRequest(): headerValue: no-cache
[V][Parsing.cpp:219] _parseRequest(): headerName: User-Agent
[V][Parsing.cpp:220] _parseRequest(): headerValue: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36
[V][Parsing.cpp:219] _parseRequest(): headerName: Accept
[V][Parsing.cpp:220] _parseRequest(): headerValue: image/webp,image/apng,image/*,*/*;q=0.8
[V][Parsing.cpp:219] _parseRequest(): headerName: Referer
[V][Parsing.cpp:220] _parseRequest(): headerValue: http://192.168.1.5/
[V][Parsing.cpp:219] _parseRequest(): headerName: Accept-Encoding
[V][Parsing.cpp:220] _parseRequest(): headerValue: gzip, deflate
[V][Parsing.cpp:219] _parseRequest(): headerName: Accept-Language
[V][Parsing.cpp:220] _parseRequest(): headerValue: en-US,en;q=0.9,ru;q=0.8,mt;q=0.7
[V][Parsing.cpp:247] _parseArguments(): args: 
[V][Parsing.cpp:230] _parseRequest(): Request: /favicon.ico
[V][Parsing.cpp:231] _parseRequest():  Arguments: 
[E][WebServer.cpp:617] _handleRequest(): request handler not found

[D][WiFiClient.cpp:509] connected(): Disconnected: RES: 0, ERR: 128

For your information my file system is here and i have some folders in it: css, js, lang

This is screenshot of my file system:
Screenshot_3

@DmitryBorisenko33
Copy link
Author

@DmitryBorisenko33
Copy link
Author

Please look at my issue. Im sorry, i really need your help!

@stickbreaker
Copy link
Contributor

stickbreaker commented Oct 27, 2019

@DmitryBorisenko33

  • you haven't posted your code
    How do you expect up to identify problems in your code if we can't see it?
  • you have not registered any request handlers: server.on()
    The error log you posted show:

[E][WebServer.cpp:617] _handleRequest(): request handler not found
handleFileRead: /js/build.chart.js
[V][Parsing.cpp:230] _parseRequest(): Request: /
[V][Parsing.cpp:231] _parseRequest(): Arguments:
[E][WebServer.cpp:617] _handleRequest(): request handler not found

Chuck.

@lbernstone
Copy link
Contributor

The WebServer is unpacking the index.htm.gz properly. The contents of that html/js are not correct. The server has no handler for the parameters that are going along with the GET requests for those files (css/build.js?v07.04.2018 vs css/build.js) so it fails. Either set up a handler for them in the esp32 code, or request without the parameter.

@DmitryBorisenko33
Copy link
Author

DmitryBorisenko33 commented Oct 27, 2019

@DmitryBorisenko33

  • you haven't posted your code
    How do you expect up to identify problems in your code if we can't see it?
  • you have not registered any request handlers: server.on()
    The error log you posted show:

[E][WebServer.cpp:617] _handleRequest(): request handler not found
handleFileRead: /js/build.chart.js
[V][Parsing.cpp:230] _parseRequest(): Request: /
[V][Parsing.cpp:231] _parseRequest(): Arguments:
[E][WebServer.cpp:617] _handleRequest(): request handler not found

Chuck.

Hi thanks for reply.
Im sorry, but my code is standard example for esp 32 web server: examples/web server/FSBrowser

code:

/*
  FSWebServer - Example WebServer with FS backend for esp8266/esp32
  Copyright (c) 2015 Hristo Gochkov. All rights reserved.
  This file is part of the WebServer library for Arduino environment.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.
  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.
  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

  upload the contents of the data folder with MkSPIFFS Tool ("ESP32 Sketch Data Upload" in Tools menu in Arduino IDE)
  or you can upload the contents of a folder if you CD in that folder and run the following command:
  for file in `ls -A1`; do curl -F "file=@$PWD/$file" esp32fs.local/edit; done

  access the sample web page at http://esp32fs.local
  edit the page by going to http://esp32fs.local/edit
*/
#include <WiFi.h>
#include <WiFiClient.h>
#include <WebServer.h>
#include <ESPmDNS.h>

#define FILESYSTEM SPIFFS
// You only need to format the filesystem once
#define FORMAT_FILESYSTEM false
#define DBG_OUTPUT_PORT Serial

#if FILESYSTEM == FFat
#include <FFat.h>
#endif
#if FILESYSTEM == SPIFFS
#include <SPIFFS.h>
#endif

const char* ssid = "wifi-ssid";
const char* password = "wifi-password";
const char* host = "esp32fs";
WebServer server(80);
//holds the current upload
File fsUploadFile;

//format bytes
String formatBytes(size_t bytes) {
  if (bytes < 1024) {
    return String(bytes) + "B";
  } else if (bytes < (1024 * 1024)) {
    return String(bytes / 1024.0) + "KB";
  } else if (bytes < (1024 * 1024 * 1024)) {
    return String(bytes / 1024.0 / 1024.0) + "MB";
  } else {
    return String(bytes / 1024.0 / 1024.0 / 1024.0) + "GB";
  }
}

String getContentType(String filename) {
  if (server.hasArg("download")) {
    return "application/octet-stream";
  } else if (filename.endsWith(".htm")) {
    return "text/html";
  } else if (filename.endsWith(".html")) {
    return "text/html";
  } else if (filename.endsWith(".css")) {
    return "text/css";
  } else if (filename.endsWith(".js")) {
    return "application/javascript";
  } else if (filename.endsWith(".png")) {
    return "image/png";
  } else if (filename.endsWith(".gif")) {
    return "image/gif";
  } else if (filename.endsWith(".jpg")) {
    return "image/jpeg";
  } else if (filename.endsWith(".ico")) {
    return "image/x-icon";
  } else if (filename.endsWith(".xml")) {
    return "text/xml";
  } else if (filename.endsWith(".pdf")) {
    return "application/x-pdf";
  } else if (filename.endsWith(".zip")) {
    return "application/x-zip";
  } else if (filename.endsWith(".gz")) {
    return "application/x-gzip";
  }
  return "text/plain";
}

bool exists(String path){
  bool yes = false;
  File file = FILESYSTEM.open(path, "r");
  if(!file.isDirectory()){
    yes = true;
  }
  file.close();
  return yes;
}

bool handleFileRead(String path) {
  DBG_OUTPUT_PORT.println("handleFileRead: " + path);
  if (path.endsWith("/")) {
    path += "index.htm";
  }
  String contentType = getContentType(path);
  String pathWithGz = path + ".gz";
  if (exists(pathWithGz) || exists(path)) {
    if (exists(pathWithGz)) {
      path += ".gz";
    }
    File file = FILESYSTEM.open(path, "r");
    server.streamFile(file, contentType);
    file.close();
    return true;
  }
  return false;
}

void handleFileUpload() {
  if (server.uri() != "/edit") {
    return;
  }
  HTTPUpload& upload = server.upload();
  if (upload.status == UPLOAD_FILE_START) {
    String filename = upload.filename;
    if (!filename.startsWith("/")) {
      filename = "/" + filename;
    }
    DBG_OUTPUT_PORT.print("handleFileUpload Name: "); DBG_OUTPUT_PORT.println(filename);
    fsUploadFile = FILESYSTEM.open(filename, "w");
    filename = String();
  } else if (upload.status == UPLOAD_FILE_WRITE) {
    //DBG_OUTPUT_PORT.print("handleFileUpload Data: "); DBG_OUTPUT_PORT.println(upload.currentSize);
    if (fsUploadFile) {
      fsUploadFile.write(upload.buf, upload.currentSize);
    }
  } else if (upload.status == UPLOAD_FILE_END) {
    if (fsUploadFile) {
      fsUploadFile.close();
    }
    DBG_OUTPUT_PORT.print("handleFileUpload Size: "); DBG_OUTPUT_PORT.println(upload.totalSize);
  }
}

void handleFileDelete() {
  if (server.args() == 0) {
    return server.send(500, "text/plain", "BAD ARGS");
  }
  String path = server.arg(0);
  DBG_OUTPUT_PORT.println("handleFileDelete: " + path);
  if (path == "/") {
    return server.send(500, "text/plain", "BAD PATH");
  }
  if (!exists(path)) {
    return server.send(404, "text/plain", "FileNotFound");
  }
  FILESYSTEM.remove(path);
  server.send(200, "text/plain", "");
  path = String();
}

void handleFileCreate() {
  if (server.args() == 0) {
    return server.send(500, "text/plain", "BAD ARGS");
  }
  String path = server.arg(0);
  DBG_OUTPUT_PORT.println("handleFileCreate: " + path);
  if (path == "/") {
    return server.send(500, "text/plain", "BAD PATH");
  }
  if (exists(path)) {
    return server.send(500, "text/plain", "FILE EXISTS");
  }
  File file = FILESYSTEM.open(path, "w");
  if (file) {
    file.close();
  } else {
    return server.send(500, "text/plain", "CREATE FAILED");
  }
  server.send(200, "text/plain", "");
  path = String();
}

void handleFileList() {
  if (!server.hasArg("dir")) {
    server.send(500, "text/plain", "BAD ARGS");
    return;
  }

  String path = server.arg("dir");
  DBG_OUTPUT_PORT.println("handleFileList: " + path);


  File root = FILESYSTEM.open(path);
  path = String();

  String output = "[";
  if(root.isDirectory()){
      File file = root.openNextFile();
      while(file){
          if (output != "[") {
            output += ',';
          }
          output += "{\"type\":\"";
          output += (file.isDirectory()) ? "dir" : "file";
          output += "\",\"name\":\"";
          output += String(file.name()).substring(1);
          output += "\"}";
          file = root.openNextFile();
      }
  }
  output += "]";
  server.send(200, "text/json", output);
}

void setup(void) {
  DBG_OUTPUT_PORT.begin(115200);
  DBG_OUTPUT_PORT.print("\n");
  DBG_OUTPUT_PORT.setDebugOutput(true);
  if (FORMAT_FILESYSTEM) FILESYSTEM.format();
  FILESYSTEM.begin();
  {
      File root = FILESYSTEM.open("/");
      File file = root.openNextFile();
      while(file){
          String fileName = file.name();
          size_t fileSize = file.size();
          DBG_OUTPUT_PORT.printf("FS File: %s, size: %s\n", fileName.c_str(), formatBytes(fileSize).c_str());
          file = root.openNextFile();
      }
      DBG_OUTPUT_PORT.printf("\n");
  }


  //WIFI INIT
  DBG_OUTPUT_PORT.printf("Connecting to %s\n", ssid);
  if (String(WiFi.SSID()) != String(ssid)) {
    WiFi.mode(WIFI_STA);
    WiFi.begin(ssid, password);
  }

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    DBG_OUTPUT_PORT.print(".");
  }
  DBG_OUTPUT_PORT.println("");
  DBG_OUTPUT_PORT.print("Connected! IP address: ");
  DBG_OUTPUT_PORT.println(WiFi.localIP());

  MDNS.begin(host);
  DBG_OUTPUT_PORT.print("Open http://");
  DBG_OUTPUT_PORT.print(host);
  DBG_OUTPUT_PORT.println(".local/edit to see the file browser");


  //SERVER INIT
  //list directory
  server.on("/list", HTTP_GET, handleFileList);
  //load editor
  server.on("/edit", HTTP_GET, []() {
    if (!handleFileRead("/edit.htm")) {
      server.send(404, "text/plain", "FileNotFound");
    }
  });
  //create file
  server.on("/edit", HTTP_PUT, handleFileCreate);
  //delete file
  server.on("/edit", HTTP_DELETE, handleFileDelete);
  //first callback is called after the request has ended with all parsed arguments
  //second callback handles file uploads at that location
  server.on("/edit", HTTP_POST, []() {
    server.send(200, "text/plain", "");
  }, handleFileUpload);

  //called when the url is not defined here
  //use it to load content from FILESYSTEM
  server.onNotFound([]() {
    if (!handleFileRead(server.uri())) {
      server.send(404, "text/plain", "FileNotFound");
    }
  });

  //get heap status, analog input value and all GPIO statuses in one json call
  server.on("/all", HTTP_GET, []() {
    String json = "{";
    json += "\"heap\":" + String(ESP.getFreeHeap());
    json += ", \"analog\":" + String(analogRead(A0));
    json += ", \"gpio\":" + String((uint32_t)(0));
    json += "}";
    server.send(200, "text/json", json);
    json = String();
  });
  server.begin();
  DBG_OUTPUT_PORT.println("HTTP server started");

}

void loop(void) {
  server.handleClient();
}

When i use this the same code with the same file system on esp8266 everything working well.
But with esp32 i have problems.

@lbernstone
Copy link
Contributor

esp32 != esp8266. If you want to ensure compatibility, I would recommend using https://github.com/me-no-dev/ESPAsyncWebServer/blob/master/examples/ESP_AsyncFSBrowser/ESP_AsyncFSBrowser.ino, which is supported from the same code base on both platforms.

@DmitryBorisenko33
Copy link
Author

DmitryBorisenko33 commented Oct 27, 2019

I understood your recommendation about ESP_AsyncFSBrowser. It is really good and i will try it. But anyway i want to resolve this problem. I make new code and video for you.

This is my new code:

// Инициализация FFS
void FS_init(void) {
  if (FORMAT_FILESYSTEM) FILESYSTEM.format();
  FILESYSTEM.begin();
  {
      File root = FILESYSTEM.open("/");
      File file = root.openNextFile();
      while(file){
          String fileName = file.name();
          size_t fileSize = file.size();
          file = root.openNextFile();
      }
  }



  //SERVER INIT
  //list directory
  HTTP.on("/list", HTTP_GET, handleFileList);
  //load editor
  HTTP.on("/edit", HTTP_GET, []() {
    if (!handleFileRead("/edit.htm")) {
      HTTP.send(404, "text/plain", "FileNotFound");
    }
  });
  //create file
  HTTP.on("/edit", HTTP_PUT, handleFileCreate);
  //delete file
  HTTP.on("/edit", HTTP_DELETE, handleFileDelete);
  //first callback is called after the request has ended with all parsed arguments
  //second callback handles file uploads at that location
  HTTP.on("/edit", HTTP_POST, []() {
    HTTP.send(200, "text/plain", "");
  }, handleFileUpload);

  //called when the url is not defined here
  //use it to load content from FILESYSTEM
  HTTP.onNotFound([]() {
    if (!handleFileRead(HTTP.uri())) {
      HTTP.send(404, "text/plain", "FileNotFound");
    }
  });

  //get heap status, analog input value and all GPIO statuses in one json call
  HTTP.on("/all", HTTP_GET, []() {
    String json = "{";
    json += "\"heap\":" + String(ESP.getFreeHeap());
    json += ", \"analog\":" + String(analogRead(A0));
    json += ", \"gpio\":" + String((uint32_t)(0));
    json += "}";
    HTTP.send(200, "text/json", json);
    json = String();
  });


}
//format bytes
String formatBytes(size_t bytes) {
  if (bytes < 1024) {
    return String(bytes) + "B";
  } else if (bytes < (1024 * 1024)) {
    return String(bytes / 1024.0) + "KB";
  } else if (bytes < (1024 * 1024 * 1024)) {
    return String(bytes / 1024.0 / 1024.0) + "MB";
  } else {
    return String(bytes / 1024.0 / 1024.0 / 1024.0) + "GB";
  }
}

String getContentType(String filename) {
  if (HTTP.hasArg("download")) {
    return "application/octet-stream";
  } else if (filename.endsWith(".htm")) {
    return "text/html";
  } else if (filename.endsWith(".html")) {
    return "text/html";
  } else if (filename.endsWith(".css")) {
    return "text/css";
  } else if (filename.endsWith(".js")) {
    return "application/javascript";
  } else if (filename.endsWith(".png")) {
    return "image/png";
  } else if (filename.endsWith(".gif")) {
    return "image/gif";
  } else if (filename.endsWith(".jpg")) {
    return "image/jpeg";
  } else if (filename.endsWith(".ico")) {
    return "image/x-icon";
  } else if (filename.endsWith(".xml")) {
    return "text/xml";
  } else if (filename.endsWith(".pdf")) {
    return "application/x-pdf";
  } else if (filename.endsWith(".zip")) {
    return "application/x-zip";
  } else if (filename.endsWith(".gz")) {
    return "application/x-gzip";
  }
  return "text/plain";
}

bool exists(String path){
  bool yes = false;
  File file = FILESYSTEM.open(path, "r");
  if(!file.isDirectory()){
    yes = true;
  }
  file.close();
  return yes;
}

bool handleFileRead(String path) {

  if (path.endsWith("/")) {
    path += "index.htm";
  }
  String contentType = getContentType(path);
  String pathWithGz = path + ".gz";
  if (exists(pathWithGz) || exists(path)) {
    if (exists(pathWithGz)) {
      path += ".gz";
    }
    File file = FILESYSTEM.open(path, "r");
    HTTP.streamFile(file, contentType);
    file.close();
    return true;
  }
  return false;
}

void handleFileUpload() {
  if (HTTP.uri() != "/edit") {
    return;
  }
  HTTPUpload& upload = HTTP.upload();
  if (upload.status == UPLOAD_FILE_START) {
    String filename = upload.filename;
    if (!filename.startsWith("/")) {
      filename = "/" + filename;
    }
    fsUploadFile = FILESYSTEM.open(filename, "w");
    filename = String();
  } else if (upload.status == UPLOAD_FILE_WRITE) {
    if (fsUploadFile) {
      fsUploadFile.write(upload.buf, upload.currentSize);
    }
  } else if (upload.status == UPLOAD_FILE_END) {
    if (fsUploadFile) {
      fsUploadFile.close();
    }

  }
}

void handleFileDelete() {
  if (HTTP.args() == 0) {
    return HTTP.send(500, "text/plain", "BAD ARGS");
  }
  String path = HTTP.arg(0);

  if (path == "/") {
    return HTTP.send(500, "text/plain", "BAD PATH");
  }
  if (!exists(path)) {
    return HTTP.send(404, "text/plain", "FileNotFound");
  }
  FILESYSTEM.remove(path);
  HTTP.send(200, "text/plain", "");
  path = String();
}

void handleFileCreate() {
  if (HTTP.args() == 0) {
    return HTTP.send(500, "text/plain", "BAD ARGS");
  }
  String path = HTTP.arg(0);

  if (path == "/") {
    return HTTP.send(500, "text/plain", "BAD PATH");
  }
  if (exists(path)) {
    return HTTP.send(500, "text/plain", "FILE EXISTS");
  }
  File file = FILESYSTEM.open(path, "w");
  if (file) {
    file.close();
  } else {
    return HTTP.send(500, "text/plain", "CREATE FAILED");
  }
  HTTP.send(200, "text/plain", "");
  path = String();
}

void handleFileList() {
  if (!HTTP.hasArg("dir")) {
    HTTP.send(500, "text/plain", "BAD ARGS");
    return;
  }

  String path = HTTP.arg("dir");



  File root = FILESYSTEM.open(path);
  path = String();

  String output = "[";
  if(root.isDirectory()){
      File file = root.openNextFile();
      while(file){
          if (output != "[") {
            output += ',';
          }
          output += "{\"type\":\"";
          output += (file.isDirectory()) ? "dir" : "file";
          output += "\",\"name\":\"";
          output += String(file.name()).substring(1);
          output += "\"}";
          file = root.openNextFile();
      }
  }
  output += "]";
  HTTP.send(200, "text/json", output);
}

To understood my problem please look this video:

Youtube link

This is debug messege (with using of browser arrow):
(all working good)

[V][WebServer.cpp:286] handleClient(): New client
[V][Parsing.cpp:113] _parseRequest(): method: GET url: /config.live.json search: 
[V][Parsing.cpp:219] _parseRequest(): headerName: Host
[V][Parsing.cpp:220] _parseRequest(): headerValue: 192.168.1.5
[V][Parsing.cpp:219] _parseRequest(): headerName: Connection
[V][Parsing.cpp:220] _parseRequest(): headerValue: keep-alive
[V][Parsing.cpp:219] _parseRequest(): headerName: User-Agent
[V][Parsing.cpp:220] _parseRequest(): headerValue: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36
[V][Parsing.cpp:219] _parseRequest(): headerName: Accept
[V][Parsing.cpp:220] _parseRequest(): headerValue: */*
[V][Parsing.cpp:219] _parseRequest(): headerName: Referer
[V][Parsing.cpp:220] _parseRequest(): headerValue: http://192.168.1.5/
[V][Parsing.cpp:219] _parseRequest(): headerName: Accept-Encoding
[V][Parsing.cpp:220] _parseRequest(): headerValue: gzip, deflate
[V][Parsing.cpp:219] _parseRequest(): headerName: Accept-Language
[V][Parsing.cpp:220] _parseRequest(): headerValue: en-US,en;q=0.9,ru;q=0.8,mt;q=0.7
[V][Parsing.cpp:247] _parseArguments(): args: 
[V][Parsing.cpp:230] _parseRequest(): Request: /config.live.json
[V][Parsing.cpp:231] _parseRequest():  Arguments: 
[D][WiFiClient.cpp:509] connected(): Disconnected: RES: 0, ERR: 128
[V][WebServer.cpp:286] handleClient(): New client
[V][Parsing.cpp:113] _parseRequest(): method: GET url: /lang/lang.ru.json search: 
[V][Parsing.cpp:219] _parseRequest(): headerName: Host
[V][Parsing.cpp:220] _parseRequest(): headerValue: 192.168.1.5
[V][Parsing.cpp:219] _parseRequest(): headerName: Connection
[V][Parsing.cpp:220] _parseRequest(): headerValue: keep-alive
[V][Parsing.cpp:219] _parseRequest(): headerName: User-Agent
[V][Parsing.cpp:220] _parseRequest(): headerValue: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36
[V][Parsing.cpp:219] _parseRequest(): headerName: Accept
[V][Parsing.cpp:220] _parseRequest(): headerValue: */*
[V][Parsing.cpp:219] _parseRequest(): headerName: Referer
[V][Parsing.cpp:220] _parseRequest(): headerValue: http://192.168.1.5/
[V][Parsing.cpp:219] _parseRequest(): headerName: Accept-Encoding
[V][Parsing.cpp:220] _parseRequest(): headerValue: gzip, deflate
[V][Parsing.cpp:219] _parseRequest(): headerName: Accept-Language
[V][Parsing.cpp:220] _parseRequest(): headerValue: en-US,en;q=0.9,ru;q=0.8,mt;q=0.7
[V][Parsing.cpp:247] _parseArguments(): args: 
[V][Parsing.cpp:230] _parseRequest(): Request: /lang/lang.ru.json
[V][Parsing.cpp:231] _parseRequest():  Arguments: 
[E][WebServer.cpp:617] _handleRequest(): request handler not found
[D][WiFiClient.cpp:509] connected(): Disconnected: RES: 0, ERR: 128

This is debug message when i use browser refresh button:
(refresh stopped)

[V][WebServer.cpp:286] handleClient(): New client
[V][Parsing.cpp:113] _parseRequest(): method: GET url: / search: 
[V][Parsing.cpp:219] _parseRequest(): headerName: Host
[V][Parsing.cpp:220] _parseRequest(): headerValue: 192.168.1.5
[V][Parsing.cpp:219] _parseRequest(): headerName: Connection
[V][Parsing.cpp:220] _parseRequest(): headerValue: keep-alive
[V][Parsing.cpp:219] _parseRequest(): headerName: Cache-Control
[V][Parsing.cpp:220] _parseRequest(): headerValue: max-age=0
[V][Parsing.cpp:219] _parseRequest(): headerName: Upgrade-Insecure-Requests
[V][Parsing.cpp:220] _parseRequest(): headerValue: 1
[V][Parsing.cpp:219] _parseRequest(): headerName: User-Agent
[V][Parsing.cpp:220] _parseRequest(): headerValue: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36
[V][Parsing.cpp:219] _parseRequest(): headerName: Accept
[V][Parsing.cpp:220] _parseRequest(): headerValue: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
[V][Parsing.cpp:219] _parseRequest(): headerName: Accept-Encoding
[V][Parsing.cpp:220] _parseRequest(): headerValue: gzip, deflate
[V][Parsing.cpp:219] _parseRequest(): headerName: Accept-Language
[V][Parsing.cpp:220] _parseRequest(): headerValue: en-US,en;q=0.9,ru;q=0.8,mt;q=0.7
[V][Parsing.cpp:247] _parseArguments(): args: 
[V][Parsing.cpp:230] _parseRequest(): Request: /
[V][Parsing.cpp:231] _parseRequest():  Arguments: 
  
[E][WebServer.cpp:617] _handleRequest(): request handler not found
  
[D][WiFiClient.cpp:509] connected(): Disconnected: RES: 0, ERR: 128
[V][WebServer.cpp:286] handleClient(): New client
[V][Parsing.cpp:113] _parseRequest(): method: GET url: /js/build.chart.js search: v22.10.2017
[V][Parsing.cpp:219] _parseRequest(): headerName: Host
[V][Parsing.cpp:220] _parseRequest(): headerValue: 192.168.1.5
[V][Parsing.cpp:219] _parseRequest(): headerName: Connection
[V][Parsing.cpp:220] _parseRequest(): headerValue: keep-alive
[V][Parsing.cpp:219] _parseRequest(): headerName: User-Agent
[V][Parsing.cpp:220] _parseRequest(): headerValue: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36
[V][Parsing.cpp:219] _parseRequest(): headerName: Accept
[V][Parsing.cpp:220] _parseRequest(): headerValue: */*
[V][Parsing.cpp:219] _parseRequest(): headerName: Referer
[V][Parsing.cpp:220] _parseRequest(): headerValue: http://192.168.1.5/
[V][Parsing.cpp:219] _parseRequest(): headerName: Accept-Encoding
[V][Parsing.cpp:220] _parseRequest(): headerValue: gzip, deflate
[V][Parsing.cpp:219] _parseRequest(): headerName: Accept-Language
[V][Parsing.cpp:220] _parseRequest(): headerValue: en-US,en;q=0.9,ru;q=0.8,mt;q=0.7
[V][Parsing.cpp:247] _parseArguments(): args: v22.10.2017
[V][Parsing.cpp:265] _parseArguments(): args count: 1
[V][Parsing.cpp:273] _parseArguments(): pos 0 =@-1 &@-1
[E][Parsing.cpp:275] _parseArguments(): arg missing value: 0
[V][Parsing.cpp:291] _parseArguments(): args count: 0
[V][Parsing.cpp:230] _parseRequest(): Request: /js/build.chart.js
[V][Parsing.cpp:231] _parseRequest():  Arguments: v22.10.2017
[E][WebServer.cpp:617] _handleRequest(): request handler not found
[D][WiFiClient.cpp:509] connected(): Disconnected: RES: 0, ERR: 128
[D][WiFiClient.cpp:509] connected(): Disconnected: RES: 0, ERR: 128
[D][WiFiClient.cpp:509] connected(): Disconnected: RES: 0, ERR: 128
[V][WebServer.cpp:286] handleClient(): New client
[V][Parsing.cpp:113] _parseRequest(): method: GET url: /favicon.ico search: 
[V][Parsing.cpp:219] _parseRequest(): headerName: Host
[V][Parsing.cpp:220] _parseRequest(): headerValue: 192.168.1.5
[V][Parsing.cpp:219] _parseRequest(): headerName: Connection
[V][Parsing.cpp:220] _parseRequest(): headerValue: keep-alive
[V][Parsing.cpp:219] _parseRequest(): headerName: Pragma
[V][Parsing.cpp:220] _parseRequest(): headerValue: no-cache
[V][Parsing.cpp:219] _parseRequest(): headerName: Cache-Control
[V][Parsing.cpp:220] _parseRequest(): headerValue: no-cache
[V][Parsing.cpp:219] _parseRequest(): headerName: User-Agent
[V][Parsing.cpp:220] _parseRequest(): headerValue: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36
[V][Parsing.cpp:219] _parseRequest(): headerName: Accept
[V][Parsing.cpp:220] _parseRequest(): headerValue: image/webp,image/apng,image/*,*/*;q=0.8
[V][Parsing.cpp:219] _parseRequest(): headerName: Referer
[V][Parsing.cpp:220] _parseRequest(): headerValue: http://192.168.1.5/
[V][Parsing.cpp:219] _parseRequest(): headerName: Accept-Encoding
[V][Parsing.cpp:220] _parseRequest(): headerValue: gzip, deflate
[V][Parsing.cpp:219] _parseRequest(): headerName: Accept-Language
[V][Parsing.cpp:220] _parseRequest(): headerValue: en-US,en;q=0.9,ru;q=0.8,mt;q=0.7
[V][Parsing.cpp:247] _parseArguments(): args: 
[V][Parsing.cpp:230] _parseRequest(): Request: /favicon.ico
[V][Parsing.cpp:231] _parseRequest():  Arguments: 
[E][WebServer.cpp:617] _handleRequest(): request handler not found
[D][WiFiClient.cpp:509] connected(): Disconnected: RES: 0, ERR: 128

Two case.

one - refresh page by arrow - file system working fully
two - refresh page by refresh button or first start - file system not working

@DmitryBorisenko33
Copy link
Author

Please dont forget look my video! its very important to understand.
link to youtube

@DmitryBorisenko33
Copy link
Author

Some people here had a same problem. But they were not resolve it.

@me-no-dev
Copy link
Member

in your code you do not have handlers for those files. it's quite simple :) pasting your setup() would be enough in that case. how you expect the server to find your files? because the FSBrowser does?
there is plenty info in the readme of the async web server for you to solve this :)

@DmitryBorisenko33
Copy link
Author

I have handlers for this file in my code:

 void handleFileList() {
  if (!HTTP.hasArg("dir")) {
    HTTP.send(500, "text/plain", "BAD ARGS");
    return;
  }

  String path = HTTP.arg("dir");

  File root = FILESYSTEM.open(path);
  path = String();

  String output = "[";
  if(root.isDirectory()){
      File file = root.openNextFile();
      while(file){
          if (output != "[") {
            output += ',';
          }
          output += "{\"type\":\"";
          output += (file.isDirectory()) ? "dir" : "file";
          output += "\",\"name\":\"";
          output += String(file.name()).substring(1);
          output += "\"}";
          file = root.openNextFile();
      }
  }
  output += "]";
  HTTP.send(200, "text/json", output);
}

But anyway as per recommendation above, i already start AsyncWebServer. And my file system working properly and fully. Thank you so match for this recommendation.

AsyncWebServer more good and have login and password identification.

@DmitryBorisenko33 DmitryBorisenko33 changed the title ESP32 filesystem error (PLEASE KINDLY HELP ME!) ESP32 filesystem error Oct 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants