This commit is contained in:
Yuri Trikoz
2020-12-20 01:24:08 +03:00
parent e60d5eb62f
commit 2aa3b56e85
13 changed files with 53 additions and 67 deletions

View File

@@ -4,7 +4,7 @@
#define FIRMWARE_VERSION 273 #define FIRMWARE_VERSION 273
#define FLASH_SIZE_1MB true #define FLASH_SIZE_1MB true
//===========FileSystem============================================================================================================================================== //===========FileSystem==============================================================================================================================================
#define USE_LITTLEFS true #define USE_LITTLEFS false
//================================================================================================================================================================== //==================================================================================================================================================================
#define NUM_BUTTONS 6 #define NUM_BUTTONS 6
#define LED_PIN LED_BUILTIN #define LED_PIN LED_BUILTIN

View File

@@ -5,7 +5,6 @@
#include <ESP8266httpUpdate.h> #include <ESP8266httpUpdate.h>
#include "ESPAsyncTCP.h" #include "ESPAsyncTCP.h"
#include "ESPAsyncWebServer.h" #include "ESPAsyncWebServer.h"
#include <LittleFS.h>
#include <SPIFFSEditor.h> #include <SPIFFSEditor.h>
#include <Servo.h> #include <Servo.h>
#include <WiFiUdp.h> #include <WiFiUdp.h>

View File

@@ -1,9 +1,7 @@
#pragma once #pragma once
#include <ESPAsyncWebServer.h> #include <ESPAsyncWebServer.h>
//#include <FS.h> #include "FileSystem.h"
#ifdef ESP8266
#include <LittleFS.h>
#endif
class FSEditor : public AsyncWebHandler { class FSEditor : public AsyncWebHandler {
private: private:
@@ -20,7 +18,7 @@ class FSEditor : public AsyncWebHandler {
#ifdef ESP32 #ifdef ESP32
FSEditor(const fs::FS& fs, const String& username = String(), const String& password = String()); FSEditor(const fs::FS& fs, const String& username = String(), const String& password = String());
#else #else
FSEditor(const String& username = String(), const String& password = String(), const fs::FS& fs = LittleFS); FSEditor(const String& username = String(), const String& password = String(), const fs::FS& fs = FileFS);
#endif #endif
virtual bool canHandle(AsyncWebServerRequest* request) override final; virtual bool canHandle(AsyncWebServerRequest* request) override final;
virtual void handleRequest(AsyncWebServerRequest* request) override final; virtual void handleRequest(AsyncWebServerRequest* request) override final;

View File

@@ -6,6 +6,8 @@
#define FILE_WRITE "w" #define FILE_WRITE "w"
#define FILE_APPEND "a" #define FILE_APPEND "a"
#include <FS.h>
#if USE_LITTLEFS #if USE_LITTLEFS
#include <LittleFS.h> #include <LittleFS.h>
extern FS LittleFS; extern FS LittleFS;

View File

@@ -1,13 +1,7 @@
#pragma once #pragma once
#include <Arduino.h> #include <Arduino.h>
//#include "FS.h"
#ifdef ESP32 #include "FileSystem.h"
#include "LITTLEFS.h"
#define LittleFS LITTLEFS
#endif
#ifdef ESP8266
#include <LittleFS.h>
#endif
class FileHelper { class FileHelper {
public: public:

View File

@@ -1,14 +1,7 @@
#pragma once #pragma once
#include <Arduino.h> #include <Arduino.h>
#include "Consts.h" #include "Consts.h"
//#include "FS.h" #include "FileSystem.h"
#ifdef ESP32
#include "LITTLEFS.h"
#define LittleFS LITTLEFS
#endif
#ifdef ESP8266
#include <LittleFS.h>
#endif
/* /*
* Инициализация ФС * Инициализация ФС

View File

@@ -1,17 +1,10 @@
#include "FSEditor.h" #include "FSEditor.h"
#ifdef ESP32 #include "FileSystem.h"
#include "LITTLEFS.h"
#define LittleFS LITTLEFS
#endif
#ifdef ESP8266
#include <LittleFS.h>
#endif
#define FS_MAXLENGTH_FILEPATH 32 #define FS_MAXLENGTH_FILEPATH 32
const char *excludeListFile = "/.exclude.files"; const char *excludeListFile = "/.exclude.files";
typedef struct ExcludeListS { typedef struct ExcludeListS {
char *item; char *item;
ExcludeListS *next; ExcludeListS *next;
@@ -239,7 +232,7 @@ void FSEditor::handleRequest(AsyncWebServerRequest *request) {
if (request->header("If-Modified-Since").equals(buildTime)) { if (request->header("If-Modified-Since").equals(buildTime)) {
request->send(304); request->send(304);
} else { } else {
AsyncWebServerResponse *response = request->beginResponse(LittleFS, "/edit.htm", "text/html"); AsyncWebServerResponse *response = request->beginResponse(FileFS, "/edit.htm", "text/html");
// response->addHeader("Content-Encoding", "gzip"); // response->addHeader("Content-Encoding", "gzip");
response->addHeader("Last-Modified", buildTime); response->addHeader("Last-Modified", buildTime);
request->send(response); request->send(response);

View File

@@ -1,5 +1,6 @@
#include "ItemsList.h" #include "ItemsList.h"
#include "FileSystem.h"
#include "Class/NotAsync.h" #include "Class/NotAsync.h"
#include "Init.h" #include "Init.h"
#include "Utils/StringUtils.h" #include "Utils/StringUtils.h"
@@ -25,7 +26,7 @@ void itemsListInit() {
void addItem2(String param) { void addItem2(String param) {
int num = selectToMarker(param, "-").toInt(); int num = selectToMarker(param, "-").toInt();
File configFile = LittleFS.open("/items/items.txt", "r"); File configFile = FileFS.open("/items/items.txt", "r");
if (!configFile) { if (!configFile) {
return; return;
} }
@@ -62,7 +63,7 @@ void addItem2(String param) {
void addPreset2(int num) { void addPreset2(int num) {
File configFile = LittleFS.open("/presets/presets.c.txt", "r"); File configFile = FileFS.open("/presets/presets.c.txt", "r");
if (!configFile) { if (!configFile) {
return; return;
} }
@@ -85,7 +86,7 @@ void addPreset2(int num) {
configFile.close(); configFile.close();
addFile(DEVICE_CONFIG_FILE, config); addFile(DEVICE_CONFIG_FILE, config);
File scenFile = LittleFS.open("/presets/presets.s.txt", "r"); File scenFile = FileFS.open("/presets/presets.s.txt", "r");
if (!scenFile) { if (!scenFile) {
return; return;
} }
@@ -160,7 +161,7 @@ uint8_t getFreePinAnalog() {
} }
void delChoosingItems() { void delChoosingItems() {
File configFile = LittleFS.open("/" + String(DEVICE_CONFIG_FILE), "r"); File configFile = FileFS.open("/" + String(DEVICE_CONFIG_FILE), "r");
if (!configFile) { if (!configFile) {
return; return;
} }

View File

@@ -1,6 +1,5 @@
#include "MqttClient.h" #include "MqttClient.h"
#include "BufferExecute.h" #include "BufferExecute.h"
#include <LittleFS.h>
#include "items/vLogging.h" #include "items/vLogging.h"
#include "Class/NotAsync.h" #include "Class/NotAsync.h"
#include "Global.h" #include "Global.h"
@@ -8,6 +7,7 @@
enum MqttBroker { MQTT_PRIMARY, enum MqttBroker { MQTT_PRIMARY,
MQTT_RESERVE }; MQTT_RESERVE };
MqttBroker activeBroker = MQTT_PRIMARY; MqttBroker activeBroker = MQTT_PRIMARY;
String mqttPrefix; String mqttPrefix;

View File

@@ -1,5 +1,7 @@
#include "Upgrade.h" #include "Upgrade.h"
#include "FileSystem.h"
#include "Class/NotAsync.h" #include "Class/NotAsync.h"
#ifdef ESP8266 #ifdef ESP8266
#include "ESP8266.h" #include "ESP8266.h"
@@ -92,16 +94,16 @@ void upgrade_firmware(int type) {
bool upgradeFS() { bool upgradeFS() {
WiFiClient wifiClient; WiFiClient wifiClient;
bool ret = false; bool ret = false;
Serial.println("Start upgrade LittleFS, please wait..."); Serial.printf("Start upgrade %s, please wait...", FS_NAME);
#ifdef ESP8266 #ifdef ESP8266
ESPhttpUpdate.rebootOnUpdate(false); ESPhttpUpdate.rebootOnUpdate(false);
t_httpUpdate_return retFS = ESPhttpUpdate.updateSpiffs(wifiClient, serverIP + F("/projects/iotmanager/esp8266/littlefs/littlefs.bin")); t_httpUpdate_return retFS = ESPhttpUpdate.updateSpiffs(wifiClient, serverIP + F("/projects/iotmanager/esp8266/") + FS_NAME + "/"+ FS_NAME+ ".bin");
#else #else
httpUpdate.rebootOnUpdate(false); httpUpdate.rebootOnUpdate(false);
HTTPUpdateResult retFS = httpUpdate.updateSpiffs(wifiClient, serverIP + F("/projects/iotmanager/esp32/littlefs/spiffs.bin")); HTTPUpdateResult retFS = httpUpdate.updateSpiffs(wifiClient, serverIP + F("/projects/iotmanager/esp32/littlefs/spiffs.bin"));
#endif #endif
if (retFS == HTTP_UPDATE_OK) { //если FS обновилась успешно if (retFS == HTTP_UPDATE_OK) { //если FS обновилась успешно
SerialPrint("I", "Update", "LittleFS upgrade done!"); SerialPrint("I", "Update", "FS upgrade done!");
ret = true; ret = true;
} }
return ret; return ret;

View File

@@ -1,15 +1,16 @@
#include "FileSystem.h"
#include "Utils/FileUtils.h" #include "Utils/FileUtils.h"
#include "Utils\SerialPrint.h" #include "Utils\SerialPrint.h"
#include "Utils/StringUtils.h" #include "Utils/StringUtils.h"
const String filepath(const String& filename) { const String filepath(const String& filename) {
return filename.startsWith("/") ? filename : "/" + filename; return filename.startsWith("/") ? filename : "/" + filename;
} }
bool fileSystemInit() { bool fileSystemInit() {
if (!LittleFS.begin()) { if (!FileFS.begin()) {
SerialPrint("E", F("FS"), F("FS Init ERROR, may be FS was not flashed")); SerialPrint("E", F("FS"), F("FS Init ERROR, may be FS was not flashed"));
return false; return false;
} }
@@ -19,8 +20,8 @@ bool fileSystemInit() {
void removeFile(const String& filename) { void removeFile(const String& filename) {
String path = filepath(filename); String path = filepath(filename);
if (LittleFS.exists(path)) { if (FileFS.exists(path)) {
if (!LittleFS.remove(path)) { if (!FileFS.remove(path)) {
SerialPrint("I","Files","remove " + path); SerialPrint("I","Files","remove " + path);
} }
} else { } else {
@@ -30,7 +31,7 @@ void removeFile(const String& filename) {
File seekFile(const String& filename, size_t position) { File seekFile(const String& filename, size_t position) {
String path = filepath(filename); String path = filepath(filename);
auto file = LittleFS.open(path, "r"); auto file = FileFS.open(path, "r");
if (!file) { if (!file) {
SerialPrint("[E]","Files","open " + path); SerialPrint("[E]","Files","open " + path);
} }
@@ -42,7 +43,7 @@ File seekFile(const String& filename, size_t position) {
const String readFileString(const String& filename, const String& to_find) { const String readFileString(const String& filename, const String& to_find) {
String path = filepath(filename); String path = filepath(filename);
String res = "failed"; String res = "failed";
auto file = LittleFS.open(path, "r"); auto file = FileFS.open(path, "r");
if (!file) { if (!file) {
return "failed"; return "failed";
} }
@@ -55,7 +56,7 @@ const String readFileString(const String& filename, const String& to_find) {
const String addFileLn(const String& filename, const String& str) { const String addFileLn(const String& filename, const String& str) {
String path = filepath(filename); String path = filepath(filename);
auto file = LittleFS.open(path, "a"); auto file = FileFS.open(path, "a");
if (!file) { if (!file) {
return "failed"; return "failed";
} }
@@ -66,7 +67,7 @@ const String addFileLn(const String& filename, const String& str) {
const String addFile(const String& filename, const String& str) { const String addFile(const String& filename, const String& str) {
String path = filepath(filename); String path = filepath(filename);
auto file = LittleFS.open(path, "a"); auto file = FileFS.open(path, "a");
if (!file) { if (!file) {
return "failed"; return "failed";
} }
@@ -79,19 +80,19 @@ bool copyFile(const String& src, const String& dst, bool overwrite) {
String srcPath = filepath(src); String srcPath = filepath(src);
String dstPath = filepath(dst); String dstPath = filepath(dst);
SerialPrint("I","Files","copy " + srcPath + " to " + dstPath); SerialPrint("I","Files","copy " + srcPath + " to " + dstPath);
if (!LittleFS.exists(srcPath)) { if (!FileFS.exists(srcPath)) {
SerialPrint("[E]","Files","not exist: " + srcPath); SerialPrint("[E]","Files","not exist: " + srcPath);
return false; return false;
} }
if (LittleFS.exists(dstPath)) { if (FileFS.exists(dstPath)) {
if (!overwrite) { if (!overwrite) {
SerialPrint("[E]","Files","already exist: " + dstPath); SerialPrint("[E]","Files","already exist: " + dstPath);
return false; return false;
} }
LittleFS.remove(dstPath); FileFS.remove(dstPath);
} }
auto srcFile = LittleFS.open(srcPath, "r"); auto srcFile = FileFS.open(srcPath, "r");
auto dstFile = LittleFS.open(dstPath, "w"); auto dstFile = FileFS.open(dstPath, "w");
uint8_t buf[512]; uint8_t buf[512];
while (srcFile.available()) { while (srcFile.available()) {
@@ -105,7 +106,7 @@ bool copyFile(const String& src, const String& dst, bool overwrite) {
const String writeFile(const String& filename, const String& str) { const String writeFile(const String& filename, const String& str) {
String path = filepath(filename); String path = filepath(filename);
auto file = LittleFS.open(path, "w"); auto file = FileFS.open(path, "w");
if (!file) { if (!file) {
return "failed"; return "failed";
} }
@@ -116,7 +117,7 @@ const String writeFile(const String& filename, const String& str) {
const String readFile(const String& filename, size_t max_size) { const String readFile(const String& filename, size_t max_size) {
String path = filepath(filename); String path = filepath(filename);
auto file = LittleFS.open(path, "r"); auto file = FileFS.open(path, "r");
if (!file) { if (!file) {
return "failed"; return "failed";
} }
@@ -132,7 +133,7 @@ const String readFile(const String& filename, size_t max_size) {
const String getFileSize(const String filename) { const String getFileSize(const String filename) {
String filepath(filename); String filepath(filename);
auto file = LittleFS.open(filepath, "r"); auto file = FileFS.open(filepath, "r");
if (!file) { if (!file) {
return "failed"; return "failed";
} }
@@ -145,13 +146,13 @@ const String getFSSizeInfo() {
String res; String res;
#ifdef ESP8266 #ifdef ESP8266
FSInfo info; FSInfo info;
if (LittleFS.info(info)) { if (FileFS.info(info)) {
res = prettyBytes(info.usedBytes) + " of " + prettyBytes(info.totalBytes); res = prettyBytes(info.usedBytes) + " of " + prettyBytes(info.totalBytes);
} else { } else {
res = "error"; res = "error";
} }
#else #else
res = prettyBytes(LittleFS.usedBytes()) + " of " + prettyBytes(LittleFS.totalBytes()); res = prettyBytes(FileFS.usedBytes()) + " of " + prettyBytes(FileFS.totalBytes());
#endif #endif
return res; return res;
} }

View File

@@ -16,18 +16,18 @@ void init() {
String login = jsonReadStr(configSetupJson, "weblogin"); String login = jsonReadStr(configSetupJson, "weblogin");
String pass = jsonReadStr(configSetupJson, "webpass"); String pass = jsonReadStr(configSetupJson, "webpass");
#ifdef ESP32 #ifdef ESP32
server.addHandler(new FSEditor(LittleFS, login, pass)); server.addHandler(new FSEditor(FileFS, login, pass));
#else #else
server.addHandler(new FSEditor(login, pass)); server.addHandler(new FSEditor(login, pass));
#endif #endif
server.serveStatic("/css/", LittleFS, "/css/").setCacheControl("max-age=600"); server.serveStatic("/css/", FileFS, "/css/").setCacheControl("max-age=600");
server.serveStatic("/js/", LittleFS, "/js/").setCacheControl("max-age=600"); server.serveStatic("/js/", FileFS, "/js/").setCacheControl("max-age=600");
server.serveStatic("/favicon.ico", LittleFS, "/favicon.ico").setCacheControl("max-age=600"); server.serveStatic("/favicon.ico", FileFS, "/favicon.ico").setCacheControl("max-age=600");
server.serveStatic("/icon.jpeg", LittleFS, "/icon.jpeg").setCacheControl("max-age=600"); server.serveStatic("/icon.jpeg", FileFS, "/icon.jpeg").setCacheControl("max-age=600");
server.serveStatic("/edit", LittleFS, "/edit").setCacheControl("max-age=600"); server.serveStatic("/edit", FileFS, "/edit").setCacheControl("max-age=600");
server.serveStatic("/", LittleFS, "/").setDefaultFile("index.htm").setAuthentication(login.c_str(), pass.c_str()); server.serveStatic("/", FileFS, "/").setDefaultFile("index.htm").setAuthentication(login.c_str(), pass.c_str());
server.onNotFound([](AsyncWebServerRequest *request) { server.onNotFound([](AsyncWebServerRequest *request) {
SerialPrint("[E]","WebServer","not found:\n" + getRequestInfo(request)); SerialPrint("[E]","WebServer","not found:\n" + getRequestInfo(request));

View File

@@ -2,6 +2,8 @@
#include <Arduino.h> #include <Arduino.h>
#include "FileSystem.h"
#include "Class/LineParsing.h" #include "Class/LineParsing.h"
#include "Global.h" #include "Global.h"
#include "BufferExecute.h" #include "BufferExecute.h"
@@ -146,8 +148,9 @@ void sendLogData(String file, String topic) {
} }
void cleanLogAndData() { void cleanLogAndData() {
#ifdef ESP8266 #ifdef ESP8266
auto dir = LittleFS.openDir("logs"); auto dir = FileFS.openDir("logs");
while (dir.next()) { while (dir.next()) {
String fname = dir.fileName(); String fname = dir.fileName();
SerialPrint("I", "System", fname); SerialPrint("I", "System", fname);