diff --git a/include/Consts.h b/include/Consts.h index 1a37c29b..1805957a 100644 --- a/include/Consts.h +++ b/include/Consts.h @@ -4,7 +4,7 @@ #define FIRMWARE_VERSION 273 #define FLASH_SIZE_1MB true //===========FileSystem============================================================================================================================================== -#define USE_LITTLEFS true +#define USE_LITTLEFS false //================================================================================================================================================================== #define NUM_BUTTONS 6 #define LED_PIN LED_BUILTIN diff --git a/include/ESP8266.h b/include/ESP8266.h index 6296fc81..76abdc10 100644 --- a/include/ESP8266.h +++ b/include/ESP8266.h @@ -5,7 +5,6 @@ #include #include "ESPAsyncTCP.h" #include "ESPAsyncWebServer.h" -#include #include #include #include diff --git a/include/FSEditor.h b/include/FSEditor.h index c037d008..4fcdef02 100644 --- a/include/FSEditor.h +++ b/include/FSEditor.h @@ -1,9 +1,7 @@ #pragma once + #include -//#include -#ifdef ESP8266 -#include -#endif +#include "FileSystem.h" class FSEditor : public AsyncWebHandler { private: @@ -20,7 +18,7 @@ class FSEditor : public AsyncWebHandler { #ifdef ESP32 FSEditor(const fs::FS& fs, const String& username = String(), const String& password = String()); #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 virtual bool canHandle(AsyncWebServerRequest* request) override final; virtual void handleRequest(AsyncWebServerRequest* request) override final; diff --git a/include/FileSystem.h b/include/FileSystem.h index 813569f7..48706d84 100644 --- a/include/FileSystem.h +++ b/include/FileSystem.h @@ -6,6 +6,8 @@ #define FILE_WRITE "w" #define FILE_APPEND "a" +#include + #if USE_LITTLEFS #include extern FS LittleFS; diff --git a/include/Utils/FileHelper.h b/include/Utils/FileHelper.h index d2691706..b5ba764c 100644 --- a/include/Utils/FileHelper.h +++ b/include/Utils/FileHelper.h @@ -1,13 +1,7 @@ #pragma once #include -//#include "FS.h" -#ifdef ESP32 -#include "LITTLEFS.h" -#define LittleFS LITTLEFS -#endif -#ifdef ESP8266 -#include -#endif + +#include "FileSystem.h" class FileHelper { public: diff --git a/include/Utils/FileUtils.h b/include/Utils/FileUtils.h index cd51532f..3c33557e 100644 --- a/include/Utils/FileUtils.h +++ b/include/Utils/FileUtils.h @@ -1,14 +1,7 @@ #pragma once #include #include "Consts.h" -//#include "FS.h" -#ifdef ESP32 -#include "LITTLEFS.h" -#define LittleFS LITTLEFS -#endif -#ifdef ESP8266 -#include -#endif +#include "FileSystem.h" /* * Инициализация ФС diff --git a/src/FSEditor.cpp b/src/FSEditor.cpp index 5f33d075..98be53cd 100644 --- a/src/FSEditor.cpp +++ b/src/FSEditor.cpp @@ -1,17 +1,10 @@ #include "FSEditor.h" -#ifdef ESP32 -#include "LITTLEFS.h" -#define LittleFS LITTLEFS -#endif -#ifdef ESP8266 -#include -#endif +#include "FileSystem.h" #define FS_MAXLENGTH_FILEPATH 32 const char *excludeListFile = "/.exclude.files"; - typedef struct ExcludeListS { char *item; ExcludeListS *next; @@ -239,7 +232,7 @@ void FSEditor::handleRequest(AsyncWebServerRequest *request) { if (request->header("If-Modified-Since").equals(buildTime)) { request->send(304); } 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("Last-Modified", buildTime); request->send(response); diff --git a/src/ItemsList.cpp b/src/ItemsList.cpp index aa83a65d..a2f99028 100644 --- a/src/ItemsList.cpp +++ b/src/ItemsList.cpp @@ -1,5 +1,6 @@ #include "ItemsList.h" +#include "FileSystem.h" #include "Class/NotAsync.h" #include "Init.h" #include "Utils/StringUtils.h" @@ -25,7 +26,7 @@ void itemsListInit() { void addItem2(String param) { int num = selectToMarker(param, "-").toInt(); - File configFile = LittleFS.open("/items/items.txt", "r"); + File configFile = FileFS.open("/items/items.txt", "r"); if (!configFile) { return; } @@ -62,7 +63,7 @@ void addItem2(String param) { void addPreset2(int num) { - File configFile = LittleFS.open("/presets/presets.c.txt", "r"); + File configFile = FileFS.open("/presets/presets.c.txt", "r"); if (!configFile) { return; } @@ -85,7 +86,7 @@ void addPreset2(int num) { configFile.close(); 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) { return; } @@ -160,7 +161,7 @@ uint8_t getFreePinAnalog() { } void delChoosingItems() { - File configFile = LittleFS.open("/" + String(DEVICE_CONFIG_FILE), "r"); + File configFile = FileFS.open("/" + String(DEVICE_CONFIG_FILE), "r"); if (!configFile) { return; } diff --git a/src/MqttClient.cpp b/src/MqttClient.cpp index f76ff552..610957f1 100644 --- a/src/MqttClient.cpp +++ b/src/MqttClient.cpp @@ -1,6 +1,5 @@ #include "MqttClient.h" #include "BufferExecute.h" -#include #include "items/vLogging.h" #include "Class/NotAsync.h" #include "Global.h" @@ -8,7 +7,8 @@ enum MqttBroker { MQTT_PRIMARY, MQTT_RESERVE }; -MqttBroker activeBroker = MQTT_PRIMARY; + +MqttBroker activeBroker = MQTT_PRIMARY; String mqttPrefix; String mqttRootDevice; diff --git a/src/UpgradeFirm.cpp b/src/UpgradeFirm.cpp index 21e835eb..b3f57051 100644 --- a/src/UpgradeFirm.cpp +++ b/src/UpgradeFirm.cpp @@ -1,5 +1,7 @@ #include "Upgrade.h" +#include "FileSystem.h" + #include "Class/NotAsync.h" #ifdef ESP8266 #include "ESP8266.h" @@ -92,16 +94,16 @@ void upgrade_firmware(int type) { bool upgradeFS() { WiFiClient wifiClient; bool ret = false; - Serial.println("Start upgrade LittleFS, please wait..."); + Serial.printf("Start upgrade %s, please wait...", FS_NAME); #ifdef ESP8266 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 httpUpdate.rebootOnUpdate(false); HTTPUpdateResult retFS = httpUpdate.updateSpiffs(wifiClient, serverIP + F("/projects/iotmanager/esp32/littlefs/spiffs.bin")); #endif if (retFS == HTTP_UPDATE_OK) { //если FS обновилась успешно - SerialPrint("I", "Update", "LittleFS upgrade done!"); + SerialPrint("I", "Update", "FS upgrade done!"); ret = true; } return ret; diff --git a/src/Utils/FileUtils.cpp b/src/Utils/FileUtils.cpp index 31927eed..dd8b8a0e 100644 --- a/src/Utils/FileUtils.cpp +++ b/src/Utils/FileUtils.cpp @@ -1,15 +1,16 @@ +#include "FileSystem.h" + #include "Utils/FileUtils.h" #include "Utils\SerialPrint.h" #include "Utils/StringUtils.h" - const String filepath(const String& filename) { return filename.startsWith("/") ? filename : "/" + filename; } bool fileSystemInit() { - if (!LittleFS.begin()) { + if (!FileFS.begin()) { SerialPrint("E", F("FS"), F("FS Init ERROR, may be FS was not flashed")); return false; } @@ -19,8 +20,8 @@ bool fileSystemInit() { void removeFile(const String& filename) { String path = filepath(filename); - if (LittleFS.exists(path)) { - if (!LittleFS.remove(path)) { + if (FileFS.exists(path)) { + if (!FileFS.remove(path)) { SerialPrint("I","Files","remove " + path); } } else { @@ -30,7 +31,7 @@ void removeFile(const String& filename) { File seekFile(const String& filename, size_t position) { String path = filepath(filename); - auto file = LittleFS.open(path, "r"); + auto file = FileFS.open(path, "r"); if (!file) { 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) { String path = filepath(filename); String res = "failed"; - auto file = LittleFS.open(path, "r"); + auto file = FileFS.open(path, "r"); if (!file) { 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) { String path = filepath(filename); - auto file = LittleFS.open(path, "a"); + auto file = FileFS.open(path, "a"); if (!file) { return "failed"; } @@ -66,7 +67,7 @@ const String addFileLn(const String& filename, const String& str) { const String addFile(const String& filename, const String& str) { String path = filepath(filename); - auto file = LittleFS.open(path, "a"); + auto file = FileFS.open(path, "a"); if (!file) { return "failed"; } @@ -79,19 +80,19 @@ bool copyFile(const String& src, const String& dst, bool overwrite) { String srcPath = filepath(src); String dstPath = filepath(dst); SerialPrint("I","Files","copy " + srcPath + " to " + dstPath); - if (!LittleFS.exists(srcPath)) { + if (!FileFS.exists(srcPath)) { SerialPrint("[E]","Files","not exist: " + srcPath); return false; } - if (LittleFS.exists(dstPath)) { + if (FileFS.exists(dstPath)) { if (!overwrite) { SerialPrint("[E]","Files","already exist: " + dstPath); return false; } - LittleFS.remove(dstPath); + FileFS.remove(dstPath); } - auto srcFile = LittleFS.open(srcPath, "r"); - auto dstFile = LittleFS.open(dstPath, "w"); + auto srcFile = FileFS.open(srcPath, "r"); + auto dstFile = FileFS.open(dstPath, "w"); uint8_t buf[512]; 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) { String path = filepath(filename); - auto file = LittleFS.open(path, "w"); + auto file = FileFS.open(path, "w"); if (!file) { 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) { String path = filepath(filename); - auto file = LittleFS.open(path, "r"); + auto file = FileFS.open(path, "r"); if (!file) { return "failed"; } @@ -132,7 +133,7 @@ const String readFile(const String& filename, size_t max_size) { const String getFileSize(const String filename) { String filepath(filename); - auto file = LittleFS.open(filepath, "r"); + auto file = FileFS.open(filepath, "r"); if (!file) { return "failed"; } @@ -145,13 +146,13 @@ const String getFSSizeInfo() { String res; #ifdef ESP8266 FSInfo info; - if (LittleFS.info(info)) { + if (FileFS.info(info)) { res = prettyBytes(info.usedBytes) + " of " + prettyBytes(info.totalBytes); } else { res = "error"; } #else - res = prettyBytes(LittleFS.usedBytes()) + " of " + prettyBytes(LittleFS.totalBytes()); + res = prettyBytes(FileFS.usedBytes()) + " of " + prettyBytes(FileFS.totalBytes()); #endif return res; } diff --git a/src/WebServer.cpp b/src/WebServer.cpp index c955e9a2..b6db2e19 100644 --- a/src/WebServer.cpp +++ b/src/WebServer.cpp @@ -16,18 +16,18 @@ void init() { String login = jsonReadStr(configSetupJson, "weblogin"); String pass = jsonReadStr(configSetupJson, "webpass"); #ifdef ESP32 - server.addHandler(new FSEditor(LittleFS, login, pass)); + server.addHandler(new FSEditor(FileFS, login, pass)); #else server.addHandler(new FSEditor(login, pass)); #endif - server.serveStatic("/css/", LittleFS, "/css/").setCacheControl("max-age=600"); - server.serveStatic("/js/", LittleFS, "/js/").setCacheControl("max-age=600"); - server.serveStatic("/favicon.ico", LittleFS, "/favicon.ico").setCacheControl("max-age=600"); - server.serveStatic("/icon.jpeg", LittleFS, "/icon.jpeg").setCacheControl("max-age=600"); - server.serveStatic("/edit", LittleFS, "/edit").setCacheControl("max-age=600"); + server.serveStatic("/css/", FileFS, "/css/").setCacheControl("max-age=600"); + server.serveStatic("/js/", FileFS, "/js/").setCacheControl("max-age=600"); + server.serveStatic("/favicon.ico", FileFS, "/favicon.ico").setCacheControl("max-age=600"); + server.serveStatic("/icon.jpeg", FileFS, "/icon.jpeg").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) { SerialPrint("[E]","WebServer","not found:\n" + getRequestInfo(request)); diff --git a/src/items/vLogging.cpp b/src/items/vLogging.cpp index b4cbc6d2..66f71094 100644 --- a/src/items/vLogging.cpp +++ b/src/items/vLogging.cpp @@ -2,6 +2,8 @@ #include +#include "FileSystem.h" + #include "Class/LineParsing.h" #include "Global.h" #include "BufferExecute.h" @@ -146,8 +148,9 @@ void sendLogData(String file, String topic) { } void cleanLogAndData() { + #ifdef ESP8266 - auto dir = LittleFS.openDir("logs"); + auto dir = FileFS.openDir("logs"); while (dir.next()) { String fname = dir.fileName(); SerialPrint("I", "System", fname);