Logging in progress

This commit is contained in:
Dmitry Borisenko
2020-11-01 00:03:08 +03:00
parent b7a98e19d2
commit 8445dd3b0c
3 changed files with 36 additions and 12 deletions

View File

@@ -13,12 +13,33 @@ void LoggingClass::loop() {
unsigned long difference = currentMillis - prevMillis;
if (difference >= _period) {
prevMillis = millis();
writeDate();
addNewDelOldData("log." + _key + ".txt", _maxPoints, jsonReadStr(configLiveJson, _key));
}
}
void LoggingClass::writeDate() {
SerialPrint("I", "Logging", _key);
void LoggingClass::addNewDelOldData(const String filename, size_t maxPoints, String payload) {
String logData = readFile(filename, 5120);
size_t lines_cnt = itemsCount(logData, "\r\n");
SerialPrint("I", "Logging", "http://" + WiFi.localIP().toString() + "/" + filename + " (" + String(lines_cnt, DEC) + ")");
if ((lines_cnt > maxPoints + 1) || !lines_cnt) {
removeFile(filename);
lines_cnt = 0;
}
if (lines_cnt > maxPoints) {
logData = deleteBeforeDelimiter(logData, "\r\n");
if (timeNow->hasTimeSynced()) {
logData += timeNow->getTimeUnix() + " " + payload + "\r\n";
writeFile(filename, logData);
}
} else {
if (timeNow->hasTimeSynced()) {
addFileLn(filename, timeNow->getTimeUnix() + " " + payload);
}
}
}
MyLoggingVector* myLogging= nullptr;
MyLoggingVector* myLogging = nullptr;