mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 22:52:19 +03:00
попытка использовать альтнрнативный метод поиска
This commit is contained in:
@@ -36,7 +36,7 @@ void LoggingClass::execute(String keyOrValue) {
|
||||
} else {
|
||||
SerialPrint("E", "Logging", "This value not found on this device");
|
||||
}
|
||||
} else { //прилетело из события
|
||||
} else { //прилетело из события
|
||||
if (isDigitStr(keyOrValue) || keyOrValue.indexOf(".") != -1) { //если это число или дробное число
|
||||
loggingValue = keyOrValue;
|
||||
} else { //если это ключ
|
||||
@@ -49,22 +49,33 @@ void LoggingClass::execute(String keyOrValue) {
|
||||
}
|
||||
|
||||
String filename = "logs/" + _key + ".txt";
|
||||
String logData = readFile(filename, 5120);
|
||||
|
||||
size_t lines_cnt = itemsCount(logData, "\r\n");
|
||||
size_t sz = 0;
|
||||
|
||||
SerialPrint("I", "Logging", "http://" + WiFi.localIP().toString() + "/" + filename + " (" + String(lines_cnt, DEC) + ")");
|
||||
String logData = readFileSz(filename, 10240, sz);
|
||||
|
||||
size_t lines_cnt = itemsCount2(logData, "\r\n");
|
||||
|
||||
SerialPrint("I", "Logging", "http://" + WiFi.localIP().toString() + "/" + filename + " lines " + String(lines_cnt, DEC) + ", size " + String(sz) + ", heap " + ESP.getFreeHeap());
|
||||
|
||||
if (logData == "large") {
|
||||
SerialPrint("E", "Logging", "File is very large");
|
||||
}
|
||||
|
||||
if ((lines_cnt > _maxPoints + 1) || !lines_cnt) {
|
||||
removeFile(filename);
|
||||
lines_cnt = 0;
|
||||
SerialPrint("E", "Logging", "file been remooved: " + filename + " " + String(lines_cnt) + ">" + String(_maxPoints));
|
||||
}
|
||||
|
||||
if (loggingValue != "") {
|
||||
if (lines_cnt > _maxPoints) { //удаляем старую строку и добавляем новую
|
||||
//for (int i = 0; i < 5; i++) {
|
||||
logData = deleteBeforeDelimiter(logData, "\r\n");
|
||||
//}
|
||||
if (timeNow->hasTimeSynced()) {
|
||||
logData += timeNow->getTimeUnix() + " " + loggingValue + "\r\n";
|
||||
|
||||
writeFile(filename, logData);
|
||||
}
|
||||
} else { //просто добавляем новую строку
|
||||
@@ -73,6 +84,7 @@ void LoggingClass::execute(String keyOrValue) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String buf = "{}";
|
||||
jsonWriteInt(buf, "x", timeNow->getTimeUnix().toInt());
|
||||
jsonWriteFloat(buf, "y1", loggingValue.toFloat());
|
||||
@@ -123,7 +135,7 @@ void choose_log_date_and_send() {
|
||||
}
|
||||
}
|
||||
|
||||
void sendLogData(String file, String topic) {
|
||||
void sendLogData2(String file, String topic) {
|
||||
String log_date = readFile(file, 5120);
|
||||
if (log_date != "failed") {
|
||||
log_date.replace("\r\n", "\n");
|
||||
@@ -156,6 +168,46 @@ void sendLogData(String file, String topic) {
|
||||
}
|
||||
}
|
||||
|
||||
void sendLogData(String file, String topic) {
|
||||
File configFile = FileFS.open(file, "r");
|
||||
if (!configFile) {
|
||||
return;
|
||||
}
|
||||
configFile.seek(0, SeekSet);
|
||||
int i = 0;
|
||||
String buf = "{}";
|
||||
String json_array;
|
||||
String unix_time;
|
||||
String value;
|
||||
unsigned int psn;
|
||||
unsigned int sz = configFile.size();
|
||||
do {
|
||||
i++;
|
||||
psn = configFile.position();
|
||||
String line = configFile.readStringUntil('\n');
|
||||
unix_time = selectToMarker(line, " ");
|
||||
jsonWriteInt(buf, "x", unix_time.toInt());
|
||||
value = deleteBeforeDelimiter(line, " ");
|
||||
jsonWriteFloat(buf, "y1", value.toFloat());
|
||||
if (unix_time != "" || value != "") {
|
||||
json_array += buf + ",";
|
||||
}
|
||||
if (i >= 100) {
|
||||
json_array = "{\"status\":[" + json_array + "]}";
|
||||
json_array.replace("},]}", "}]}");
|
||||
publishChart(topic, json_array);
|
||||
json_array = "";
|
||||
i = 0;
|
||||
}
|
||||
} while (psn < sz);
|
||||
|
||||
configFile.close();
|
||||
|
||||
json_array = "{\"status\":[" + json_array + "]}";
|
||||
json_array.replace("},]}", "}]}");
|
||||
publishChart(topic, json_array);
|
||||
}
|
||||
|
||||
void cleanLogAndData() {
|
||||
#ifdef ESP8266
|
||||
auto dir = FileFS.openDir("logs");
|
||||
|
||||
Reference in New Issue
Block a user