запуск little fs на esp32

This commit is contained in:
Dmitry Borisenko
2022-09-15 14:02:24 +02:00
parent d78e03176f
commit aae21f4a78
15 changed files with 87 additions and 74 deletions

View File

@@ -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_Pwm8266(String subtype, String params);
void* getAPI_Pwm32(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_Pwm8266(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Pwm32(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;

View File

@@ -38,7 +38,7 @@ class Loging : public IoTItem {
jsonRead(parameters, F("keepdays"), keepdays);
//создадим экземпляр класса даты
dateIoTItem = (IoTItem *)getAPI_Date("{\"id\": \"" + id + "-date\",\"int\":\"20\"}");
dateIoTItem = (IoTItem *)getAPI_Date("{\"id\": \"" + id + "-date\",\"int\":\"20\",\"subtype\":\"date\"}");
IoTItems.push_back(dateIoTItem);
SerialPrint("E", F("Loging"), "created date instance " + id);
}
@@ -75,8 +75,6 @@ class Loging : public IoTItem {
SerialPrint("E", F("Loging"), "'" + id + "' file path not found");
createNewFileWithData(logData);
return;
} else {
// SerialPrint("i", F("Loging"), "'" + id + "' file path found " + filePath);
}
//считаем количество строк
@@ -91,6 +89,8 @@ class Loging : public IoTItem {
} else {
createNewFileWithData(logData);
}
//запускаем процедуру удаления старых файлов если память переполняется
deleteLastFile();
}
void createNewFileWithData(String &logData) {
@@ -135,11 +135,6 @@ class Loging : public IoTItem {
unsigned long fileUnixTimeGMT = selectToMarkerLast(deleteToMarkerLast(buf, "."), "/").toInt() + START_DATETIME;
unsigned long fileUnixTimeLocal = gmtTimeToLocal(fileUnixTimeGMT);
//удаление старых файлов
// if ((fileUnixTimeLocal + (points * (interval / 1000))) < (unixTime - (keepdays * 86400))) {
// SerialPrint("i", F("Loging"), "file '" + buf + "' too old, deleted");
// removeFile(buf);
//} else {
unsigned long reqUnixTime = strDateToUnix(getItemValue(id + "-date"));
if (fileUnixTimeLocal > reqUnixTime && fileUnixTimeLocal < reqUnixTime + 86400) {
noData = false;
@@ -148,7 +143,6 @@ class Loging : public IoTItem {
} else {
SerialPrint("i", F("Loging"), String(f) + ") " + buf + ", nil, " + getDateTimeDotFormatedFromUnix(fileUnixTimeLocal) + ", skipped");
}
//}
filesList = deleteBeforeDelimiter(filesList, ";");
}
@@ -179,6 +173,28 @@ class Loging : public IoTItem {
}
}
void deleteLastFile() {
IoTFSInfo tmp = getFSInfo();
SerialPrint("i", "Loging", String(tmp.freePer) + " % free flash remaining");
if (tmp.freePer <= 10.00) {
String dir = "lg/" + id;
filesList = getFilesList(dir);
int i = 0;
while (filesList.length()) {
String buf = selectToMarker(filesList, ";");
i++;
if (i == 1) {
removeFile(buf);
SerialPrint("!", "Loging", String(i) + ") " + buf + " => oldest files been deleted");
return;
}
filesList = deleteBeforeDelimiter(filesList, ";");
}
}
}
void createJson(String file, int &i) {
File configFile = FileFS.open(file, "r");
if (!configFile) {