mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
график финальная версия без даты
This commit is contained in:
@@ -11,7 +11,7 @@
|
|||||||
"webpass": "admin",
|
"webpass": "admin",
|
||||||
"mqttServer": "m2.wqtt.ru",
|
"mqttServer": "m2.wqtt.ru",
|
||||||
"mqttPort": 8021,
|
"mqttPort": 8021,
|
||||||
"mqttPrefix": "/rise",
|
"mqttPrefix": "/risenew",
|
||||||
"mqttUser": "rise",
|
"mqttUser": "rise",
|
||||||
"mqttPass": "3hostel3",
|
"mqttPass": "3hostel3",
|
||||||
"serverip": "http://157.245.22.57:8081",
|
"serverip": "http://157.245.22.57:8081",
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
"webpass": "admin",
|
"webpass": "admin",
|
||||||
"mqttServer": "m2.wqtt.ru",
|
"mqttServer": "m2.wqtt.ru",
|
||||||
"mqttPort": 8021,
|
"mqttPort": 8021,
|
||||||
"mqttPrefix": "/rise",
|
"mqttPrefix": "/risenew",
|
||||||
"mqttUser": "rise",
|
"mqttUser": "rise",
|
||||||
"mqttPass": "3hostel3",
|
"mqttPass": "3hostel3",
|
||||||
"serverip": "http://157.245.22.57:8081",
|
"serverip": "http://157.245.22.57:8081",
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
#include "classes/IoTItem.h"
|
#include "classes/IoTItem.h"
|
||||||
#include "NTP.h"
|
#include "NTP.h"
|
||||||
|
|
||||||
#define SOLID_UPLOADING
|
//раскомментировать если нужна цельная выгрузка графиков
|
||||||
|
//#define SOLID_UPLOADING
|
||||||
|
|
||||||
class Loging : public IoTItem {
|
class Loging : public IoTItem {
|
||||||
private:
|
private:
|
||||||
@@ -10,12 +11,14 @@ class Loging : public IoTItem {
|
|||||||
String id;
|
String id;
|
||||||
int points;
|
int points;
|
||||||
String fileName = "";
|
String fileName = "";
|
||||||
|
int interval;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Loging(String parameters) : IoTItem(parameters) {
|
Loging(String parameters) : IoTItem(parameters) {
|
||||||
jsonRead(parameters, F("logid"), logval);
|
jsonRead(parameters, F("logid"), logval);
|
||||||
jsonRead(parameters, F("id"), id);
|
jsonRead(parameters, F("id"), id);
|
||||||
jsonRead(parameters, F("points"), points);
|
jsonRead(parameters, F("points"), points);
|
||||||
|
jsonRead(parameters, F("int"), interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setValue(IoTValue Value) {
|
void setValue(IoTValue Value) {
|
||||||
@@ -30,7 +33,7 @@ class Loging : public IoTItem {
|
|||||||
|
|
||||||
void doByInterval() {
|
void doByInterval() {
|
||||||
String value = getItemValue(logval);
|
String value = getItemValue(logval);
|
||||||
size_t lines = 0;
|
int lines = 0;
|
||||||
//если задано не правильное logid величины для логгирования
|
//если задано не правильное logid величины для логгирования
|
||||||
if (value == "") {
|
if (value == "") {
|
||||||
SerialPrint("E", F("Loging"), F("no value set"));
|
SerialPrint("E", F("Loging"), F("no value set"));
|
||||||
@@ -48,7 +51,7 @@ class Loging : public IoTItem {
|
|||||||
//если 2 ой раз и последующие разы
|
//если 2 ой раз и последующие разы
|
||||||
} else {
|
} else {
|
||||||
lines = countLines(fileName);
|
lines = countLines(fileName);
|
||||||
if (lines <= 100) {
|
if (lines <= points) {
|
||||||
addFileLn(fileName, logData);
|
addFileLn(fileName, logData);
|
||||||
} else {
|
} else {
|
||||||
createFileWithIdDatatimeName(logData);
|
createFileWithIdDatatimeName(logData);
|
||||||
@@ -77,22 +80,23 @@ class Loging : public IoTItem {
|
|||||||
auto dir = FileFS.openDir(directory);
|
auto dir = FileFS.openDir(directory);
|
||||||
String oneSingleJson;
|
String oneSingleJson;
|
||||||
int maxCount = 0;
|
int maxCount = 0;
|
||||||
|
int i;
|
||||||
|
|
||||||
while (dir.next()) {
|
while (dir.next()) {
|
||||||
String fname = dir.fileName();
|
String fname = dir.fileName();
|
||||||
String id = selectToMarker(fname, "-");
|
String id = selectToMarker(fname, "-");
|
||||||
unsigned long fileUnixTime = deleteBeforeDelimiter(deleteToMarkerLast(fname, "."), "-").toInt() + START_DATETIME;
|
unsigned long fileUnixTime = deleteBeforeDelimiter(deleteToMarkerLast(fname, "."), "-").toInt() + START_DATETIME;
|
||||||
|
|
||||||
SerialPrint("I", "Loging", "found file '" + fname + "'");
|
|
||||||
|
|
||||||
if (isItemExist(id)) {
|
if (isItemExist(id)) {
|
||||||
//выбираем только те файлы которые входят в выбранные сутки
|
//выбираем только те файлы которые входят в выбранные сутки
|
||||||
if (fileUnixTime > reqUnixTime && fileUnixTime < reqUnixTime + 86400) {
|
if (fileUnixTime > reqUnixTime && fileUnixTime < reqUnixTime + 86400) {
|
||||||
Serial.println("matched!");
|
SerialPrint("I", "Loging", "matching file found '" + fname + "'");
|
||||||
#ifdef SOLID_UPLOADING
|
#ifdef SOLID_UPLOADING
|
||||||
createOneSingleJson(oneSingleJson, "/logs/" + fname, maxCount);
|
//если активированна выгрузка целеком
|
||||||
|
createOneSingleJson(oneSingleJson, "/logs/" + fname, maxCount, i);
|
||||||
#else
|
#else
|
||||||
|
//выгрузка по частям, по одному файлу
|
||||||
|
publishJsonPartly("/logs/" + fname, calculateMaxCount(), i);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -101,11 +105,12 @@ class Loging : public IoTItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef SOLID_UPLOADING
|
#ifdef SOLID_UPLOADING
|
||||||
sendJson(oneSingleJson, maxCount);
|
publishJson(oneSingleJson, maxCount);
|
||||||
#endif
|
#endif
|
||||||
|
SerialPrint("I", "Loging", "---------'" + String(i) + "'---------");
|
||||||
}
|
}
|
||||||
|
|
||||||
void createOneSingleJson(String &oneSingleJson, String file, int &maxCount) {
|
void createOneSingleJson(String &oneSingleJson, String file, int &maxCount, int &i) {
|
||||||
File configFile = FileFS.open(file, "r");
|
File configFile = FileFS.open(file, "r");
|
||||||
if (!configFile) {
|
if (!configFile) {
|
||||||
return;
|
return;
|
||||||
@@ -118,6 +123,7 @@ class Loging : public IoTItem {
|
|||||||
unsigned int sz = configFile.size();
|
unsigned int sz = configFile.size();
|
||||||
do {
|
do {
|
||||||
maxCount++;
|
maxCount++;
|
||||||
|
i++;
|
||||||
psn = configFile.position();
|
psn = configFile.position();
|
||||||
String line = configFile.readStringUntil('\n');
|
String line = configFile.readStringUntil('\n');
|
||||||
unix_time = selectToMarker(line, " ");
|
unix_time = selectToMarker(line, " ");
|
||||||
@@ -133,11 +139,40 @@ class Loging : public IoTItem {
|
|||||||
configFile.close();
|
configFile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendJson(String &oneSingleJson, int &maxCount) {
|
void publishJsonPartly(String file, int maxCount, int &i) {
|
||||||
|
File configFile = FileFS.open(file, "r");
|
||||||
|
if (!configFile) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
configFile.seek(0, SeekSet);
|
||||||
|
String buf = "{}";
|
||||||
|
String dividedJson;
|
||||||
|
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() + START_DATETIME);
|
||||||
|
value = deleteBeforeDelimiter(line, " ");
|
||||||
|
jsonWriteFloat(buf, "y1", value.toFloat());
|
||||||
|
if (unix_time != "" || value != "") {
|
||||||
|
dividedJson += buf + ",";
|
||||||
|
}
|
||||||
|
} while (psn < sz);
|
||||||
|
|
||||||
|
configFile.close();
|
||||||
|
|
||||||
|
publishJson(dividedJson, maxCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
void publishJson(String &oneSingleJson, int &maxCount) {
|
||||||
oneSingleJson = "{\"maxCount\":" + String(maxCount) + ",\"status\":[" + oneSingleJson + "]}";
|
oneSingleJson = "{\"maxCount\":" + String(maxCount) + ",\"status\":[" + oneSingleJson + "]}";
|
||||||
oneSingleJson.replace("},]}", "}]}");
|
oneSingleJson.replace("},]}", "}]}");
|
||||||
Serial.println("final: ");
|
// SerialPrint("i", "Loging", "publish chart, maxCount: '" + String(maxCount) + "'");
|
||||||
Serial.println(oneSingleJson);
|
|
||||||
publishChart(id, oneSingleJson);
|
publishChart(id, oneSingleJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,6 +185,10 @@ class Loging : public IoTItem {
|
|||||||
SerialPrint("I", "Loging", fname + " deleted");
|
SerialPrint("I", "Loging", fname + " deleted");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int calculateMaxCount() {
|
||||||
|
return 86400 / interval;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void *getAPI_Loging(String subtype, String param) {
|
void *getAPI_Loging(String subtype, String param) {
|
||||||
|
|||||||
Reference in New Issue
Block a user