mirror of
https://github.com/0xFEEDC0DE64/arduino-esp32.git
synced 2025-07-29 18:27:15 +02:00
FAT on SPI Flash Library (#1809)
* First commit of FFat library * Fixed reboot loops if no fat present. Added CMakeLists * Functionalize the partition checks * Cleanup, especially in format * Dont format if mounted. More wording cleanup * 16M ffat should only be on 16M board * Fix some casting issues that trip up the compiler when building as ESP-IDF component
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
/*
|
||||
FSWebServer - Example WebServer with SPIFFS backend for esp8266
|
||||
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.
|
||||
|
||||
@ -26,14 +26,21 @@
|
||||
#include <WiFiClient.h>
|
||||
#include <WebServer.h>
|
||||
#include <ESPmDNS.h>
|
||||
#include <SPIFFS.h>
|
||||
|
||||
#define FILESYSTEM SPIFFS
|
||||
#define FORMAT_FILESYSTEM true
|
||||
#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;
|
||||
@ -84,7 +91,7 @@ String getContentType(String filename) {
|
||||
|
||||
bool exists(String path){
|
||||
bool yes = false;
|
||||
File file = SPIFFS.open(path, "r");
|
||||
File file = FILESYSTEM.open(path, "r");
|
||||
if(!file.isDirectory()){
|
||||
yes = true;
|
||||
}
|
||||
@ -103,7 +110,7 @@ bool handleFileRead(String path) {
|
||||
if (exists(pathWithGz)) {
|
||||
path += ".gz";
|
||||
}
|
||||
File file = SPIFFS.open(path, "r");
|
||||
File file = FILESYSTEM.open(path, "r");
|
||||
server.streamFile(file, contentType);
|
||||
file.close();
|
||||
return true;
|
||||
@ -122,7 +129,7 @@ void handleFileUpload() {
|
||||
filename = "/" + filename;
|
||||
}
|
||||
DBG_OUTPUT_PORT.print("handleFileUpload Name: "); DBG_OUTPUT_PORT.println(filename);
|
||||
fsUploadFile = SPIFFS.open(filename, "w");
|
||||
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);
|
||||
@ -149,7 +156,7 @@ void handleFileDelete() {
|
||||
if (!exists(path)) {
|
||||
return server.send(404, "text/plain", "FileNotFound");
|
||||
}
|
||||
SPIFFS.remove(path);
|
||||
FILESYSTEM.remove(path);
|
||||
server.send(200, "text/plain", "");
|
||||
path = String();
|
||||
}
|
||||
@ -166,7 +173,7 @@ void handleFileCreate() {
|
||||
if (exists(path)) {
|
||||
return server.send(500, "text/plain", "FILE EXISTS");
|
||||
}
|
||||
File file = SPIFFS.open(path, "w");
|
||||
File file = FILESYSTEM.open(path, "w");
|
||||
if (file) {
|
||||
file.close();
|
||||
} else {
|
||||
@ -186,7 +193,7 @@ void handleFileList() {
|
||||
DBG_OUTPUT_PORT.println("handleFileList: " + path);
|
||||
|
||||
|
||||
File root = SPIFFS.open(path);
|
||||
File root = FILESYSTEM.open(path);
|
||||
path = String();
|
||||
|
||||
String output = "[";
|
||||
@ -212,9 +219,10 @@ void setup(void) {
|
||||
DBG_OUTPUT_PORT.begin(115200);
|
||||
DBG_OUTPUT_PORT.print("\n");
|
||||
DBG_OUTPUT_PORT.setDebugOutput(true);
|
||||
SPIFFS.begin();
|
||||
if (FORMAT_FILESYSTEM) FILESYSTEM.format();
|
||||
FILESYSTEM.begin();
|
||||
{
|
||||
File root = SPIFFS.open("/");
|
||||
File root = FILESYSTEM.open("/");
|
||||
File file = root.openNextFile();
|
||||
while(file){
|
||||
String fileName = file.name();
|
||||
@ -267,7 +275,7 @@ void setup(void) {
|
||||
}, handleFileUpload);
|
||||
|
||||
//called when the url is not defined here
|
||||
//use it to load content from SPIFFS
|
||||
//use it to load content from FILESYSTEM
|
||||
server.onNotFound([]() {
|
||||
if (!handleFileRead(server.uri())) {
|
||||
server.send(404, "text/plain", "FileNotFound");
|
||||
|
Reference in New Issue
Block a user