espressif / arduino-esp32

Arduino core for the ESP32
GNU Lesser General Public License v2.1
13.34k stars 7.36k forks source link

FSBrowser /edit returns FileNotFound #2424

Closed GeorgeFlorian closed 5 years ago

GeorgeFlorian commented 5 years ago

Hello there ! I've been tinkering with the Arduino IDE + ESP32 for the past week.

I tried the FSBrowser + AutoConnect from here but with no luck.

Hardware:

Board: ESP32 DEVKIT1

Core Installation version: 1.0.1-git this one

IDE name: Arduino IDE

Flash Frequency: 80Mhz

PSRAM enabled: no

Upload Speed: 115200

Computer OS: Linux Mint 19.1 Mate

This is my sketch:

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

#include <FS.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <WebServer.h>
#include <ESPmDNS.h>
#include <SPIFFS.h>
#include <AutoConnect.h>

#define DBG_OUTPUT_PORT Serial
#define LED 2

const char* ssid = "wifi-ssid";
const char* password = "wifi-password";
const char* host = "esp32fs";

WebServer server(80);

AutoConnect portal(server);
//holds the current upload
File fsUploadFile;

bool startCP(IPAddress ip) {
    digitalWrite(LED, HIGH);
    DBG_OUTPUT_PORT.println("Captive Portal started ! IP: " + WiFi.localIP().toString());
    return true;
  }

//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 handleFileRead(String path){
  DBG_OUTPUT_PORT.println("handleFileRead: " + path);
  if(path.endsWith("/")) path += "index.htm";
  String contentType = getContentType(path);
  String pathWithGz = path + ".gz";
  if(SPIFFS.exists(pathWithGz) || SPIFFS.exists(path)){
    if(SPIFFS.exists(pathWithGz))
      path += ".gz";
    File file = SPIFFS.open(path, "r");
    size_t sent = 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 = SPIFFS.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(!SPIFFS.exists(path))
    return server.send(404, "text/plain", "FileNotFound");
  SPIFFS.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(SPIFFS.exists(path))
    return server.send(500, "text/plain", "FILE EXISTS");
  File file = SPIFFS.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 = SPIFFS.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){
  delay(1000);
  DBG_OUTPUT_PORT.begin(115200);
  DBG_OUTPUT_PORT.print("\n");
  DBG_OUTPUT_PORT.setDebugOutput(true);

  SPIFFS.begin();
  {
    File root = SPIFFS.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);

  //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 SPIFFS
  portal.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();
  });

  pinMode(LED,OUTPUT);
  digitalWrite(LED, LOW);
  portal.onDetect(startCP);

  if (portal.begin()) {
    digitalWrite(LED, LOW);
  }

  DBG_OUTPUT_PORT.println("HTTP server started");

  //Relocation as follows to make AutoConnect recognition.
  DBG_OUTPUT_PORT.println("");
  DBG_OUTPUT_PORT.print("Connected! IP address: ");
  DBG_OUTPUT_PORT.println(WiFi.localIP());

  //Relocation as follows to make AutoConnect recognition.
  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");
}

void loop(void){

  portal.handleClient();
}

My http://192.168.1.103/edit returns FileNotFound.

/list doesn't work like that. It works like this: http://192.168.1.103/list?dir=/ and it returns:

[{"type":"file","name":"login.css"},{"type":"file","name":"index.html"},{"type":"file","name":"logo.png"},{"type":"file","name":"back-image.jpg"}]

Here is a Serial Monitor output:

10:26:01.651 -> 10:26:01.651 -> rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) 10:26:01.651 -> configsip: 0, SPIWP:0xee 10:26:01.651 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 10:26:01.685 -> mode:DIO, clock div:1 10:26:01.685 -> load:0x3fff0018,len:4 10:26:01.685 -> load:0x3fff001c,len:1100 10:26:01.685 -> load:0x40078000,len:10088 10:26:01.685 -> load:0x40080400,len:6380 10:26:01.685 -> entry 0x400806a4 10:26:02.979 -> 10:26:03.145 -> FS File: /logo.png, size: 3.80KB 10:26:03.145 -> FS File: /login.css, size: 1.62KB 10:26:03.145 -> FS File: /index.html, size: 880B 10:26:03.178 -> FS File: /back-image.jpg, size: 146.42KB 10:26:03.212 -> 10:26:03.378 -> [D][WiFiGeneric.cpp:342] _eventCallback(): Event: 0 - WIFI_READY 10:26:03.378 -> [D][WiFiGeneric.cpp:342] _eventCallback(): Event: 2 - STA_START 10:26:03.477 -> [AC] WiFi.config(IP=0.0.0.0, Gateway=0.0.0.0, Subnetmask=0.0.0.0, DNS1=0.0.0.0, DNS2=0.0.0.0) [AC] WiFi.begin() 10:26:03.510 -> [AC] Connecting....[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 4 - STA_CONNECTED 10:26:04.440 -> [D][WiFiGeneric.cpp:342] _eventCallback(): Event: 7 - STA_GOT_IP 10:26:04.440 -> [D][WiFiGeneric.cpp:385] _eventCallback(): STA IP: 192.168.1.103, MASK: 255.255.255.0, GW: 192.168.1.1 10:26:04.706 -> [AC] established IP:192.168.1.103 10:26:04.706 -> [AC] http server started 10:26:04.706 -> HTTP server started 10:26:04.706 -> 10:26:04.706 -> Connected! IP address: 192.168.1.103 10:26:04.706 -> Open http://esp32fs.local/edit to see the file browser 10:26:22.267 -> [AC] /_ac 10:26:22.267 -> [AC] Page[/_ac] allocated 10:26:22.267 -> [AC] 192.168.1.103/_ac 10:26:22.267 -> [PB] at leaving build: 260260 free 10:26:22.267 -> [PB] Res:200, Chunked:0 10:26:22.267 -> [PB] Free heap:262948, content len.:6643 10:26:22.300 -> [PB] Transfer-Encoding:chunked 10:26:22.300 -> [D][WiFiClient.cpp:463] connected(): Disconnected: RES: 0, ERR: 128 10:26:45.707 -> handleFileRead: /edit.htm 10:26:45.872 -> [D][WiFiClient.cpp:463] connected(): Disconnected: RES: 0, ERR: 128 10:26:46.106 -> [AC] esp32fs.local/favicon.ico 10:26:46.106 -> [AC] Page[] allocated 10:26:46.106 -> [E][WebServer.cpp:602] _handleRequest(): request handler not found 10:26:46.106 -> [D][WiFiClient.cpp:463] connected(): Disconnected: RES: 0, ERR: 128 10:26:46.106 -> [AC] esp32fs.local/_ac 10:26:46.139 -> [AC] Page[/_ac] allocated 10:26:46.139 -> [AC] 192.168.1.103/_ac 10:26:46.139 -> [PB] at leaving build: 259968 free 10:26:46.139 -> [PB] Res:200, Chunked:0 10:26:46.139 -> [PB] Free heap:262736, content len.:6643 10:26:46.139 -> [PB] Transfer-Encoding:chunked 10:26:46.172 -> [E][WiFiClient.cpp:346] write(): 104 10:27:08.145 -> handleFileRead: /edit.htm 10:27:08.311 -> [D][WiFiClient.cpp:463] connected(): Disconnected: RES: 0, ERR: 128 10:27:08.410 -> [AC] esp32fs.local/favicon.ico 10:27:08.444 -> [AC] Page[] allocated 10:27:08.444 -> [E][WebServer.cpp:602] _handleRequest(): request handler not found 10:27:08.444 -> [D][WiFiClient.cpp:463] connected(): Disconnected: RES: 0, ERR: 128 10:27:08.444 -> [AC] esp32fs.local/_ac 10:27:08.444 -> [AC] Page[/_ac] allocated 10:27:08.444 -> [AC] 192.168.1.103/_ac 10:27:08.477 -> [PB] at leaving build: 259664 free 10:27:08.477 -> [PB] Res:200, Chunked:0 10:27:08.477 -> [PB] Free heap:262440, content len.:6643 10:27:08.477 -> [PB] Transfer-Encoding:chunked 10:27:08.477 -> [E][WiFiClient.cpp:346] write(): 104 10:27:13.455 -> [D][WiFiClient.cpp:463] connected(): Disconnected: RES: 0, ERR: 128 10:27:13.854 -> [AC] esp32fs.local/favicon.ico 10:27:13.854 -> [AC] Page[] allocated 10:27:13.854 -> [E][WebServer.cpp:602] _handleRequest(): request handler not found 10:27:13.854 -> [D][WiFiClient.cpp:463] connected(): Disconnected: RES: 0, ERR: 128 10:27:18.866 -> [AC] esp32fs.local/_ac 10:27:18.866 -> [AC] Page[/_ac] allocated 10:27:18.866 -> [AC] 192.168.1.103/_ac 10:27:18.899 -> [PB] at leaving build: 259372 free 10:27:18.899 -> [PB] Res:200, Chunked:0 10:27:18.899 -> [PB] Free heap:262132, content len.:6643 10:27:18.899 -> [PB] Transfer-Encoding:chunked 10:27:18.899 -> [E][WiFiClient.cpp:346] write(): 104

As you can see I've uploaded 4 files into the ESP32's FlashMemory. I would like to "edit" them. Maybe delete one of them, or create a new file. I can't do that since /edit does nothing.

Do you have any idea ? Thank you !

lbernstone commented 5 years ago

There is a version included in the core distribution. Give that a try.

GeorgeFlorian commented 5 years ago

There is a version included in the core distribution. Give that a try.

There wasn't much to modify. But it broke everything. It can't read from the Flash Memory. It's like I have nothing in memory. But I have 8 files. I've uploaded them twice.

I'm using ESP32 Sketch Data Upload. And it always worked.

The only thing that works is http://192.168.1.103/_ac from the AutoConnect API.

/edit returns FileNotFound /list?dir= returns [ ]

With the code from the first post I was able to enter the edit menu (finally!) but it didn't work. I couldn't download, or delete, or create, or upload. It only looked the part, but it didn't work.

/*
  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 <FS.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <WebServer.h>
#include <ESPmDNS.h>
#include <AutoConnect.h>

#define FILESYSTEM SPIFFS
#define FORMAT_FILESYSTEM true
#define DBG_OUTPUT_PORT Serial

#define LED 2

#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);
AutoConnect portal(server);

//holds the current upload
File fsUploadFile;

bool startCP(IPAddress ip) {
    digitalWrite(LED, HIGH);
    DBG_OUTPUT_PORT.println("Captive Portal started ! IP: " + WiFi.localIP().toString());
    return true;
  }

//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(".");
//  }

  //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();
  });

  pinMode(LED,OUTPUT);
  digitalWrite(LED, LOW);
  portal.onDetect(startCP);

  if (portal.begin()) {
    digitalWrite(LED, LOW);
  }

  DBG_OUTPUT_PORT.println("HTTP server started");

  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");

}

void loop(void) {
  portal.handleClient();
}
MarkusAD commented 5 years ago

In the version you posted just above, its setting #define FORMAT_FILESYSTEM true so its formatting your filesystem every time it runs.

GeorgeFlorian commented 5 years ago

Why is #define FORMAT_FILESYSTEM true there then ? Should I only use it once then comment the line ?

MarkusAD commented 5 years ago

Set it to false, reflash sketch, re-run sketch data upload.

GeorgeFlorian commented 5 years ago

reflash sketch

I've set #define FORMAT_FILESYSTEM to false , I've uploaded the data, uploaded the sketch and nothing happened. It doesn't work.

EDIT: I've uploaded the data again, uploaded the sketch again and this is what I get. It just looks the part, but it doesn't work.

When you say 'reflash sketch" you mean to upload the sketch using the Upload (CTRL + U) in the Arduino IDE, right ? Because if it's another reflashing that you have in mind I have no idea how to do that and I couldn't find anything useful online. I don't have a board or wires. I only have a DOIT Esp32 DevKit v1 connected to the PC via a USB cable.

GeorgeFlorian commented 5 years ago

Set it to false, reflash sketch, re-run sketch data upload.

It still doesn't work ! I don't know why you tried closing this issue !

MarkusAD commented 5 years ago

Dude, no one is closing any issues. @lbernstone simply put up a pull request that fixes the issue with it formatting the filesystem.

mattncsu commented 4 years ago

In the version you posted just above, its setting #define FORMAT_FILESYSTEM true so its formatting your filesystem every time it runs.

That got me too on this example