diff --git a/data_svelte/items.json b/data_svelte/items.json index a01f9fc6..f78855e6 100644 --- a/data_svelte/items.json +++ b/data_svelte/items.json @@ -398,7 +398,7 @@ "execLevel": "1", "pinMode": "INPUT", "debounceDelay": 50, - "fixState": 1, + "fixState": 0, "num": 30 }, { @@ -455,18 +455,16 @@ "num": 34 }, { - "name": "35. PWM ESP32", + "name": "35. PWM ESP8266", "type": "Writing", - "subtype": "Pwm32", + "subtype": "Pwm8266", "id": "pwm", "widget": "range", "page": "Кнопки", "descr": "PWM", "int": 0, - "pin": 2, + "pin": 15, "freq": 5000, - "ledChannel": 2, - "PWM_resolution": 10, "val": 0, "apin": -1, "num": 35 diff --git a/include/Const.h b/include/Const.h index 5fc1ca5c..19e16915 100644 --- a/include/Const.h +++ b/include/Const.h @@ -34,7 +34,7 @@ #endif #ifdef esp32_4mb -#define USE_LITTLEFS false +#define USE_LITTLEFS true #endif #define START_DATETIME 1661990400 // 01.09.2022 00:00:00 константа для сокращения unix time diff --git a/include/utils/FileUtils.h b/include/utils/FileUtils.h index 4c512559..b50953a5 100644 --- a/include/utils/FileUtils.h +++ b/include/utils/FileUtils.h @@ -12,14 +12,17 @@ extern const String filepath(const String& filename); extern bool cutFile(const String& src, const String& dst); extern size_t countLines(const String filename); void removeFile(const String& filename); +void removeDirectory(const String& dir); void cleanDirectory(String path); -void cleanLogs(); +void cleanLogs1(); +void cleanLogs2(); void saveDataDB(String id, String data); String readDataDB(String id); extern void onFlashWrite(); -String FileList(String path); - +String getFilesList8266(String& directory); +String getFilesList32(String& directory); +String getFilesList(String& directory); extern void getFSInfo(); #ifdef ESP8266 extern bool getInfo(FSInfo& info); diff --git a/myProfile.json b/myProfile.json index 5b57857e..b807c1e6 100644 --- a/myProfile.json +++ b/myProfile.json @@ -21,7 +21,7 @@ }, "projectProp": { "platformio": { - "default_envs": "esp32_4mb", + "default_envs": "esp8266_4mb", "data_dir": "data_svelte" } }, diff --git a/platformio.ini b/platformio.ini index 0f24d297..e49cd758 100644 --- a/platformio.ini +++ b/platformio.ini @@ -32,6 +32,7 @@ monitor_filters = esp32_exception_decoder upload_speed = 921600 monitor_speed = 115200 debug_tool = esp-prog +board_build.filesystem = littlefs build_src_filter = +<*.cpp> + @@ -40,7 +41,7 @@ build_src_filter = ${env:esp32_4mb_fromitems.build_src_filter} [platformio] -default_envs = esp32_4mb +default_envs = esp8266_4mb data_dir = data_svelte [common_env_data] diff --git a/src/WsServer.cpp b/src/WsServer.cpp index bd36c44b..fb549f6c 100644 --- a/src/WsServer.cpp +++ b/src/WsServer.cpp @@ -196,8 +196,12 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length) } //команда очистки всех логов esp - if (headerStr == "/clean|") { - cleanLogs(); + if (headerStr == "/clean1|") { + cleanLogs1(); + } + + if (headerStr == "/clean2|") { + cleanLogs2(); } //команда обновления прошивки esp diff --git a/src/modules/API.cpp b/src/modules/API.cpp index b2f9af1f..9ee02105 100644 --- a/src/modules/API.cpp +++ b/src/modules/API.cpp @@ -22,7 +22,7 @@ void* getAPI_ButtonOut(String subtype, String params); void* getAPI_IoTServo(String subtype, String params); void* getAPI_Mcp23017(String subtype, String params); void* getAPI_Mp3(String subtype, String params); -void* getAPI_Pwm32(String subtype, String params); +void* getAPI_Pwm8266(String subtype, String params); void* getAPI_TelegramLT(String subtype, String params); void* getAPI_Lcd2004(String subtype, String params); @@ -50,7 +50,7 @@ if ((tmpAPI = getAPI_ButtonOut(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_IoTServo(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Mcp23017(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Mp3(subtype, params)) != nullptr) return tmpAPI; -if ((tmpAPI = getAPI_Pwm32(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_Pwm8266(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_TelegramLT(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Lcd2004(subtype, params)) != nullptr) return tmpAPI; return nullptr; diff --git a/src/modules/virtual/Logging/Loging.cpp b/src/modules/virtual/Logging/Loging.cpp index 1a5f3f95..a5c84fe2 100644 --- a/src/modules/virtual/Logging/Loging.cpp +++ b/src/modules/virtual/Logging/Loging.cpp @@ -119,46 +119,9 @@ class Loging : public IoTItem { return changed; } -#if defined(ESP8266) - void getFilesList8266() { - filesList = ""; - String directory = "lg/" + id; - auto dir = FileFS.openDir(directory); - while (dir.next()) { - String fname = dir.fileName(); - if (fname != "") filesList += directory + "/" + fname + ";"; - } - } -#endif - -#if defined(ESP32) - void getFilesList32() { - filesList = ""; - String directory = "/lg/" + id; - File root = FileFS.open(directory); - directory = String(); - if (root.isDirectory()) { - File file = root.openNextFile(); - while (file) { - String fname = file.name(); - if (fname != "") filesList += fname + ";"; - file = root.openNextFile(); - } - } - } -#endif - - void getFilesList() { -#if defined(ESP8266) - getFilesList8266(); -#endif -#if defined(ESP32) - getFilesList32(); -#endif - } - void sendChart() { - getFilesList(); + String dir = "lg/" + id; + filesList = getFilesList(dir); int f = 0; bool noData = true; @@ -202,7 +165,8 @@ class Loging : public IoTItem { } void cleanData() { - getFilesList(); + String dir = "lg/" + id; + filesList = getFilesList(dir); int i = 0; while (filesList.length()) { String buf = selectToMarker(filesList, ";"); diff --git a/src/utils/FileUtils.cpp b/src/utils/FileUtils.cpp index 8d3adbde..66f33ba1 100644 --- a/src/utils/FileUtils.cpp +++ b/src/utils/FileUtils.cpp @@ -183,42 +183,37 @@ void removeFile(const String& filename) { String path = filepath(filename); if (FileFS.exists(path)) { if (!FileFS.remove(path)) { - // SerialPrint("i", "Files", "remove " + path); + SerialPrint("i", "Files", "remove file" + path); } } else { - SerialPrint("E", "Files", "not exist " + path); + SerialPrint("E", "Files", "file not exist " + path); + } +} + +void removeDirectory(const String& dir) { + String path = filepath(dir); + if (FileFS.exists(path)) { + if (!FileFS.rmdir(path)) { + SerialPrint("i", "Files", "remove dir" + path); + } + } else { + SerialPrint("E", "Files", "dir not exist " + path); } } //очищаем директорию с файлами void cleanDirectory(String path) { -#if defined(ESP8266) - auto dir = FileFS.openDir(path); - while (dir.next()) { - String fname = dir.fileName(); - removeFile(path + "/" + fname); - SerialPrint("i", "Files", path + "/" + fname + " => deleted"); + String filesList = getFilesList(path); + int i = 0; + while (filesList.length()) { + String buf = selectToMarker(filesList, ";"); + + i++; + removeFile(buf); + SerialPrint("i", "Files", String(i) + ") " + buf + " => deleted"); + + filesList = deleteBeforeDelimiter(filesList, ";"); } - onFlashWrite(); -#endif -#if defined(ESP32) - path = "/" + path; - File root = FileFS.open(path); - path = String(); - if (!root) { - SerialPrint("E", "Files", "nothing to delete"); - return; - } - if (root.isDirectory()) { - File file = root.openNextFile(); - while (file) { - String fname = file.name(); - removeFile(fname); - SerialPrint("i", "Files", fname + " => deleted"); - file = root.openNextFile(); - } - } -#endif } void saveDataDB(String id, String data) { @@ -231,7 +226,8 @@ String readDataDB(String id) { return readFile(path, 2000); } -void cleanLogs() { +void cleanLogs1() { + SerialPrint("i", "Files", "cleanLogs1"); cleanDirectory("db"); //очистка данных всех экземпляров графиков for (std::list::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) { @@ -241,6 +237,20 @@ void cleanLogs() { } } +void cleanLogs2() { + SerialPrint("i", "Files", "cleanLogs2"); + + String dir1 = "db"; + SerialPrint("i", "", getFilesList(dir1)); + removeDirectory(dir1); + SerialPrint("i", "", getFilesList(dir1)); + + String dir2 = "lg"; + SerialPrint("i", "", getFilesList(dir2)); + removeDirectory(dir2); + SerialPrint("i", "", getFilesList(dir2)); +} + //счетчик количества записей на флешь за сеанс void onFlashWrite() { flashWriteNumber++; @@ -249,49 +259,44 @@ void onFlashWrite() { // Создаем список файлов каталога, функции от Сергея Третьякова #if defined(ESP8266) -String FileList(String path) { - Dir dir = FileFS.openDir(path); - path = String(); - String output = "["; +String getFilesList8266(String& directory) { + String filesList = ""; + auto dir = FileFS.openDir(directory); while (dir.next()) { - File entry = dir.openFile("r"); - if (output != "[") output += ','; - bool isDir = false; - output += "{\"type\":\""; - output += (isDir) ? "dir" : "file"; - output += "\",\"name\":\""; - output += String(entry.name()).substring(1); - output += "\"}"; - entry.close(); + String fname = dir.fileName(); + if (fname != "") filesList += directory + "/" + fname + ";"; } - output += "]"; - return output; + return filesList; } -#else -String FileList(String path) { - File root = FileFS.open(path); - path = String(); +#endif - String output = "["; +#if defined(ESP32) +String getFilesList32(String& directory) { + String filesList = ""; + String directory = "/" + directory; + File root = FileFS.open(directory); + directory = String(); if (root.isDirectory()) { File file = root.openNextFile(); while (file) { - if (output != "[") { - output += ','; - } - output += "{\"type\":\""; - output += (file.isDirectory()) ? "dir" : "file"; - output += "\",\"name\":\""; - // output += String(file.path()).substring(1); - output += "\"}"; + String fname = file.name(); + if (fname != "") filesList += fname + ";"; file = root.openNextFile(); } } - output += "]"; - return output; + return filesList; } #endif +String getFilesList(String& directory) { +#if defined(ESP8266) + return getFilesList8266(directory); +#endif +#if defined(ESP32) + return getFilesList32(directory); +#endif +} + #if defined(ESP8266) bool getInfo(FSInfo& info) { return FileFS.info(info);