mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 14:12:16 +03:00
fix chart 2x 3x
This commit is contained in:
@@ -5,8 +5,9 @@
|
|||||||
|
|
||||||
void *getAPI_Date2(String params);
|
void *getAPI_Date2(String params);
|
||||||
|
|
||||||
class Loging2 : public IoTItem {
|
class Loging2 : public IoTItem
|
||||||
private:
|
{
|
||||||
|
private:
|
||||||
String logid1;
|
String logid1;
|
||||||
String logid2;
|
String logid2;
|
||||||
String id;
|
String id;
|
||||||
@@ -17,7 +18,7 @@ class Loging2 : public IoTItem {
|
|||||||
int _wsNum = -1;
|
int _wsNum = -1;
|
||||||
|
|
||||||
int points;
|
int points;
|
||||||
//int keepdays;
|
// int keepdays;
|
||||||
|
|
||||||
IoTItem *dateIoTItem;
|
IoTItem *dateIoTItem;
|
||||||
|
|
||||||
@@ -26,20 +27,22 @@ class Loging2 : public IoTItem {
|
|||||||
|
|
||||||
// long interval;
|
// long interval;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Loging2(String parameters) : IoTItem(parameters) {
|
Loging2(String parameters) : IoTItem(parameters)
|
||||||
|
{
|
||||||
jsonRead(parameters, F("logid1"), logid1);
|
jsonRead(parameters, F("logid1"), logid1);
|
||||||
jsonRead(parameters, F("logid2"), logid2);
|
jsonRead(parameters, F("logid2"), logid2);
|
||||||
jsonRead(parameters, F("id"), id);
|
jsonRead(parameters, F("id"), id);
|
||||||
jsonRead(parameters, F("points"), points);
|
jsonRead(parameters, F("points"), points);
|
||||||
if (points > 300) {
|
if (points > 300)
|
||||||
|
{
|
||||||
points = 300;
|
points = 300;
|
||||||
SerialPrint("E", F("Loging2"), "'" + id + "' user set more points than allowed, value reset to 300");
|
SerialPrint("E", F("Loging2"), "'" + id + "' user set more points than allowed, value reset to 300");
|
||||||
}
|
}
|
||||||
long interval;
|
long interval;
|
||||||
jsonRead(parameters, F("int"), interval);
|
jsonRead(parameters, F("int"), interval); // в минутах
|
||||||
interval = interval * 60; // приводим к милисекундам
|
setInterval(interval * 60);
|
||||||
//jsonRead(parameters, F("keepdays"), keepdays, false);
|
// jsonRead(parameters, F("keepdays"), keepdays, false);
|
||||||
|
|
||||||
// создадим экземпляр класса даты
|
// создадим экземпляр класса даты
|
||||||
dateIoTItem = (IoTItem *)getAPI_Date2("{\"id\": \"" + id + "-date\",\"int\":\"20\",\"subtype\":\"date\"}");
|
dateIoTItem = (IoTItem *)getAPI_Date2("{\"id\": \"" + id + "-date\",\"int\":\"20\",\"subtype\":\"date\"}");
|
||||||
@@ -47,28 +50,33 @@ class Loging2 : public IoTItem {
|
|||||||
SerialPrint("I", F("Loging2"), "created date instance " + id);
|
SerialPrint("I", F("Loging2"), "created date instance " + id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void doByInterval() {
|
void doByInterval()
|
||||||
|
{
|
||||||
// если объект логгирования не был создан
|
// если объект логгирования не был создан
|
||||||
if (!isItemExist(logid1)) {
|
if (!isItemExist(logid1))
|
||||||
|
{
|
||||||
SerialPrint("E", F("Loging2"), "'" + id + "' loging object not exist, return");
|
SerialPrint("E", F("Loging2"), "'" + id + "' loging object not exist, return");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String value = getItemValue(logid1);
|
String value = getItemValue(logid1);
|
||||||
// если значение логгирования пустое
|
// если значение логгирования пустое
|
||||||
if (value == "") {
|
if (value == "")
|
||||||
|
{
|
||||||
SerialPrint("E", F("Loging2"), "'" + id + "' loging value is empty, return");
|
SerialPrint("E", F("Loging2"), "'" + id + "' loging value is empty, return");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String value2 = getItemValue(logid2);
|
String value2 = getItemValue(logid2);
|
||||||
// если значение логгирования пустое
|
// если значение логгирования пустое
|
||||||
if (value == "") {
|
if (value == "")
|
||||||
|
{
|
||||||
SerialPrint("E", F("Loging2"), "'" + id + "' loging value is empty, return");
|
SerialPrint("E", F("Loging2"), "'" + id + "' loging value is empty, return");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// если время не было получено из интернета
|
// если время не было получено из интернета
|
||||||
if (!isTimeSynch) {
|
if (!isTimeSynch)
|
||||||
|
{
|
||||||
SerialPrint("E", F("Loging2"), "'" + id + "' Сant loging - time not synchronized, return");
|
SerialPrint("E", F("Loging2"), "'" + id + "' Сant loging - time not synchronized, return");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -85,13 +93,17 @@ class Loging2 : public IoTItem {
|
|||||||
String filePath = readDataDB(id);
|
String filePath = readDataDB(id);
|
||||||
|
|
||||||
// если данные о файле отсутствуют, создадим новый
|
// если данные о файле отсутствуют, создадим новый
|
||||||
if (filePath == "failed" || filePath == "") {
|
if (filePath == "failed" || filePath == "")
|
||||||
|
{
|
||||||
SerialPrint("E", F("Loging2"), "'" + id + "' file path not found, start create new file");
|
SerialPrint("E", F("Loging2"), "'" + id + "' file path not found, start create new file");
|
||||||
createNewFileWithData(logData2);
|
createNewFileWithData(logData2);
|
||||||
return;
|
return;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
// если файл все же есть но был создан не сегодня, то создаем сегодняшний
|
// если файл все же есть но был создан не сегодня, то создаем сегодняшний
|
||||||
if (getTodayDateDotFormated() != getDateDotFormatedFromUnix(getFileUnixLocalTime(filePath))) {
|
if (getTodayDateDotFormated() != getDateDotFormatedFromUnix(getFileUnixLocalTime(filePath)))
|
||||||
|
{
|
||||||
SerialPrint("E", F("Loging2"), "'" + id + "' file too old, start create new file");
|
SerialPrint("E", F("Loging2"), "'" + id + "' file too old, start create new file");
|
||||||
createNewFileWithData(logData2);
|
createNewFileWithData(logData2);
|
||||||
return;
|
return;
|
||||||
@@ -104,26 +116,32 @@ class Loging2 : public IoTItem {
|
|||||||
SerialPrint("i", F("Loging2"), "'" + id + "' " + "lines = " + String(lines) + ", size = " + String(size));
|
SerialPrint("i", F("Loging2"), "'" + id + "' " + "lines = " + String(lines) + ", size = " + String(size));
|
||||||
|
|
||||||
// если количество строк до заданной величины и дата не менялась
|
// если количество строк до заданной величины и дата не менялась
|
||||||
if (lines <= points && !hasDayChanged()) {
|
if (lines <= points && !hasDayChanged())
|
||||||
|
{
|
||||||
// просто добавим в существующий файл новые данные
|
// просто добавим в существующий файл новые данные
|
||||||
addNewDataToExistingFile(filePath, logData2);
|
addNewDataToExistingFile(filePath, logData2);
|
||||||
// если больше или поменялась дата то создадим следующий файл
|
// если больше или поменялась дата то создадим следующий файл
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
createNewFileWithData(logData2);
|
createNewFileWithData(logData2);
|
||||||
}
|
}
|
||||||
// запускаем процедуру удаления старых файлов если память переполняется
|
// запускаем процедуру удаления старых файлов если память переполняется
|
||||||
deleteLastFile();
|
deleteLastFile();
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
void SetDoByInterval(String valse) {
|
void SetDoByInterval(String valse)
|
||||||
|
{
|
||||||
String value = valse;
|
String value = valse;
|
||||||
// если значение логгирования пустое
|
// если значение логгирования пустое
|
||||||
if (value == "") {
|
if (value == "")
|
||||||
|
{
|
||||||
SerialPrint("E", F("Loging2Event"), "'" + id + "' loging value is empty, return");
|
SerialPrint("E", F("Loging2Event"), "'" + id + "' loging value is empty, return");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// если время не было получено из интернета
|
// если время не было получено из интернета
|
||||||
if (!isTimeSynch) {
|
if (!isTimeSynch)
|
||||||
|
{
|
||||||
SerialPrint("E", F("Loging2Event"), "'" + id + "' Сant loging - time not synchronized, return");
|
SerialPrint("E", F("Loging2Event"), "'" + id + "' Сant loging - time not synchronized, return");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -136,13 +154,17 @@ class Loging2 : public IoTItem {
|
|||||||
String filePath = readDataDB(id);
|
String filePath = readDataDB(id);
|
||||||
|
|
||||||
// если данные о файле отсутствуют, создадим новый
|
// если данные о файле отсутствуют, создадим новый
|
||||||
if (filePath == "failed" || filePath == "") {
|
if (filePath == "failed" || filePath == "")
|
||||||
|
{
|
||||||
SerialPrint("E", F("Loging2Event"), "'" + id + "' file path not found, start create new file");
|
SerialPrint("E", F("Loging2Event"), "'" + id + "' file path not found, start create new file");
|
||||||
createNewFileWithData(logData2);
|
createNewFileWithData(logData2);
|
||||||
return;
|
return;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
// если файл все же есть но был создан не сегодня, то создаем сегодняшний
|
// если файл все же есть но был создан не сегодня, то создаем сегодняшний
|
||||||
if (getTodayDateDotFormated() != getDateDotFormatedFromUnix(getFileUnixLocalTime(filePath))) {
|
if (getTodayDateDotFormated() != getDateDotFormatedFromUnix(getFileUnixLocalTime(filePath)))
|
||||||
|
{
|
||||||
SerialPrint("E", F("Loging2Event"), "'" + id + "' file too old, start create new file");
|
SerialPrint("E", F("Loging2Event"), "'" + id + "' file too old, start create new file");
|
||||||
createNewFileWithData(logData2);
|
createNewFileWithData(logData2);
|
||||||
return;
|
return;
|
||||||
@@ -155,41 +177,51 @@ class Loging2 : public IoTItem {
|
|||||||
SerialPrint("i", F("Loging2Event"), "'" + id + "' " + "lines = " + String(lines) + ", size = " + String(size));
|
SerialPrint("i", F("Loging2Event"), "'" + id + "' " + "lines = " + String(lines) + ", size = " + String(size));
|
||||||
|
|
||||||
// если количество строк до заданной величины и дата не менялась
|
// если количество строк до заданной величины и дата не менялась
|
||||||
if (lines <= points && !hasDayChanged()) {
|
if (lines <= points && !hasDayChanged())
|
||||||
|
{
|
||||||
// просто добавим в существующий файл новые данные
|
// просто добавим в существующий файл новые данные
|
||||||
addNewDataToExistingFile(filePath, logData2);
|
addNewDataToExistingFile(filePath, logData2);
|
||||||
// если больше или поменялась дата то создадим следующий файл
|
// если больше или поменялась дата то создадим следующий файл
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
createNewFileWithData(logData2);
|
createNewFileWithData(logData2);
|
||||||
}
|
}
|
||||||
// запускаем процедуру удаления старых файлов если память переполняется
|
// запускаем процедуру удаления старых файлов если память переполняется
|
||||||
deleteLastFile();
|
deleteLastFile();
|
||||||
}
|
}
|
||||||
void createNewFileWithData(String &logData) {
|
*/
|
||||||
|
void createNewFileWithData(String &logData)
|
||||||
|
{
|
||||||
logData = logData + ",";
|
logData = logData + ",";
|
||||||
String path = "/lg2/" + id + "/" + String(unixTimeShort) + ".txt"; // создадим путь вида /lg/id/133256622333.txt
|
String path = "/lg2/" + id + "/" + String(unixTimeShort) + ".txt"; // создадим путь вида /lg/id/133256622333.txt
|
||||||
// создадим пустой файл
|
// создадим пустой файл
|
||||||
if (writeEmptyFile(path) != "success") {
|
if (writeEmptyFile(path) != "success")
|
||||||
|
{
|
||||||
SerialPrint("E", F("Loging2"), "'" + id + "' file writing error, return");
|
SerialPrint("E", F("Loging2"), "'" + id + "' file writing error, return");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// запишем в него данные
|
// запишем в него данные
|
||||||
if (addFile(path, logData) != "success") {
|
if (addFile(path, logData) != "success")
|
||||||
|
{
|
||||||
SerialPrint("E", F("Loging2"), "'" + id + "' data writing error, return");
|
SerialPrint("E", F("Loging2"), "'" + id + "' data writing error, return");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// запишем путь к нему в базу данных
|
// запишем путь к нему в базу данных
|
||||||
if (saveDataDB(id, path) != "success") {
|
if (saveDataDB(id, path) != "success")
|
||||||
|
{
|
||||||
SerialPrint("E", F("Loging2"), "'" + id + "' db file writing error, return");
|
SerialPrint("E", F("Loging2"), "'" + id + "' db file writing error, return");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SerialPrint("i", F("Loging2"), "'" + id + "' file created http://" + WiFi.localIP().toString() + path);
|
SerialPrint("i", F("Loging2"), "'" + id + "' file created http://" + WiFi.localIP().toString() + path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void addNewDataToExistingFile(String &path, String &logData) {
|
void addNewDataToExistingFile(String &path, String &logData)
|
||||||
|
{
|
||||||
logData = logData + ",";
|
logData = logData + ",";
|
||||||
if (addFile(path, logData) != "success") {
|
if (addFile(path, logData) != "success")
|
||||||
|
{
|
||||||
SerialPrint("i", F("Loging2"), "'" + id + "' file writing error, return");
|
SerialPrint("i", F("Loging2"), "'" + id + "' file writing error, return");
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
@@ -197,11 +229,14 @@ class Loging2 : public IoTItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// данная функция уже перенесена в ядро и будет удалена в последствии
|
// данная функция уже перенесена в ядро и будет удалена в последствии
|
||||||
bool hasDayChanged() {
|
bool hasDayChanged()
|
||||||
|
{
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
String currentDate = getTodayDateDotFormated();
|
String currentDate = getTodayDateDotFormated();
|
||||||
if (!firstTimeInit) {
|
if (!firstTimeInit)
|
||||||
if (prevDate != currentDate) {
|
{
|
||||||
|
if (prevDate != currentDate)
|
||||||
|
{
|
||||||
changed = true;
|
changed = true;
|
||||||
SerialPrint("i", F("NTP"), F("Change day event"));
|
SerialPrint("i", F("NTP"), F("Change day event"));
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
@@ -216,7 +251,8 @@ class Loging2 : public IoTItem {
|
|||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void publishValue() {
|
void publishValue()
|
||||||
|
{
|
||||||
String dir = "/lg2/" + id;
|
String dir = "/lg2/" + id;
|
||||||
filesList = getFilesList(dir);
|
filesList = getFilesList(dir);
|
||||||
|
|
||||||
@@ -226,7 +262,8 @@ class Loging2 : public IoTItem {
|
|||||||
|
|
||||||
bool noData = true;
|
bool noData = true;
|
||||||
|
|
||||||
while (filesList.length()) {
|
while (filesList.length())
|
||||||
|
{
|
||||||
String path = selectToMarker(filesList, ";");
|
String path = selectToMarker(filesList, ";");
|
||||||
|
|
||||||
path = "/lg2/" + id + path;
|
path = "/lg2/" + id + path;
|
||||||
@@ -236,65 +273,83 @@ class Loging2 : public IoTItem {
|
|||||||
unsigned long fileUnixTimeLocal = getFileUnixLocalTime(path);
|
unsigned long fileUnixTimeLocal = getFileUnixLocalTime(path);
|
||||||
|
|
||||||
unsigned long reqUnixTime = strDateToUnix(getItemValue(id + "-date"));
|
unsigned long reqUnixTime = strDateToUnix(getItemValue(id + "-date"));
|
||||||
if (fileUnixTimeLocal > reqUnixTime && fileUnixTimeLocal < reqUnixTime + 86400) {
|
if (fileUnixTimeLocal > reqUnixTime && fileUnixTimeLocal < reqUnixTime + 86400)
|
||||||
|
{
|
||||||
noData = false;
|
noData = false;
|
||||||
String json = getAdditionalJson();
|
String json = getAdditionalJson();
|
||||||
if (_publishType == TO_MQTT) {
|
if (_publishType == TO_MQTT)
|
||||||
|
{
|
||||||
publishChartFileToMqtt(path, id, calculateMaxCount());
|
publishChartFileToMqtt(path, id, calculateMaxCount());
|
||||||
} else if (_publishType == TO_WS) {
|
}
|
||||||
|
else if (_publishType == TO_WS)
|
||||||
|
{
|
||||||
sendFileToWsByFrames(path, "charta", json, _wsNum, WEB_SOCKETS_FRAME_SIZE);
|
sendFileToWsByFrames(path, "charta", json, _wsNum, WEB_SOCKETS_FRAME_SIZE);
|
||||||
} else if (_publishType == TO_MQTT_WS) {
|
}
|
||||||
|
else if (_publishType == TO_MQTT_WS)
|
||||||
|
{
|
||||||
sendFileToWsByFrames(path, "charta", json, _wsNum, WEB_SOCKETS_FRAME_SIZE);
|
sendFileToWsByFrames(path, "charta", json, _wsNum, WEB_SOCKETS_FRAME_SIZE);
|
||||||
publishChartFileToMqtt(path, id, calculateMaxCount());
|
publishChartFileToMqtt(path, id, calculateMaxCount());
|
||||||
}
|
}
|
||||||
SerialPrint("i", F("Loging2"), String(f) + ") " + path + ", " + getDateTimeDotFormatedFromUnix(fileUnixTimeLocal) + ", sent");
|
SerialPrint("i", F("Loging2"), String(f) + ") " + path + ", " + getDateTimeDotFormatedFromUnix(fileUnixTimeLocal) + ", sent");
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
SerialPrint("i", F("Loging2"), String(f) + ") " + path + ", " + getDateTimeDotFormatedFromUnix(fileUnixTimeLocal) + ", skipped");
|
SerialPrint("i", F("Loging2"), String(f) + ") " + path + ", " + getDateTimeDotFormatedFromUnix(fileUnixTimeLocal) + ", skipped");
|
||||||
}
|
}
|
||||||
|
|
||||||
filesList = deleteBeforeDelimiter(filesList, ";");
|
filesList = deleteBeforeDelimiter(filesList, ";");
|
||||||
}
|
}
|
||||||
// если данных нет отправляем пустой грфик
|
// если данных нет отправляем пустой грфик
|
||||||
if (noData) {
|
if (noData)
|
||||||
|
{
|
||||||
clearValue();
|
clearValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String getAdditionalJson() {
|
String getAdditionalJson()
|
||||||
|
{
|
||||||
String topic = mqttRootDevice + "/" + id;
|
String topic = mqttRootDevice + "/" + id;
|
||||||
String json = "{\"maxCount\":" + String(calculateMaxCount()) + ",\"topic\":\"" + topic + "\"}";
|
String json = "{\"maxCount\":" + String(calculateMaxCount()) + ",\"topic\":\"" + topic + "\"}";
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
void publishChartToWsSinglePoint(String value) {
|
void publishChartToWsSinglePoint(String value)
|
||||||
|
{
|
||||||
String topic = mqttRootDevice + "/" + id;
|
String topic = mqttRootDevice + "/" + id;
|
||||||
String json = "{\"maxCount\":" + String(calculateMaxCount()) + ",\"topic\":\"" + topic + "\",\"status\":[{\"x\":" + String(unixTime) + ",\"y1\":" + value + ",\"y2\":" + value + "}]}";
|
String value2 = getItemValue(logid2);
|
||||||
|
String json = "{\"maxCount\":" + String(calculateMaxCount()) + ",\"topic\":\"" + topic + "\",\"status\":[{\"x\":" + String(unixTime) + ",\"y1\":" + value + ",\"y2\":" + value2 + "}]}";
|
||||||
sendStringToWs("chartb", json, -1);
|
sendStringToWs("chartb", json, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearValue() {
|
void clearValue()
|
||||||
|
{
|
||||||
String topic = mqttRootDevice + "/" + id;
|
String topic = mqttRootDevice + "/" + id;
|
||||||
String json = "{\"maxCount\":0,\"topic\":\"" + topic + "\",\"status\":[]}";
|
String json = "{\"maxCount\":0,\"topic\":\"" + topic + "\",\"status\":[]}";
|
||||||
sendStringToWs("chartb", json, -1);
|
sendStringToWs("chartb", json, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearHistory() {
|
void clearHistory()
|
||||||
|
{
|
||||||
String dir = "/lg2/" + id;
|
String dir = "/lg2/" + id;
|
||||||
cleanDirectory(dir);
|
cleanDirectory(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
void deleteLastFile() {
|
void deleteLastFile()
|
||||||
|
{
|
||||||
IoTFSInfo tmp = getFSInfo();
|
IoTFSInfo tmp = getFSInfo();
|
||||||
SerialPrint("i", "Loging2", String(tmp.freePer) + " % free flash remaining");
|
SerialPrint("i", "Loging2", String(tmp.freePer) + " % free flash remaining");
|
||||||
if (tmp.freePer <= 20.00) {
|
if (tmp.freePer <= 20.00)
|
||||||
|
{
|
||||||
String dir = "/lg/" + id;
|
String dir = "/lg/" + id;
|
||||||
filesList = getFilesList(dir);
|
filesList = getFilesList(dir);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (filesList.length()) {
|
while (filesList.length())
|
||||||
|
{
|
||||||
String path = selectToMarker(filesList, ";");
|
String path = selectToMarker(filesList, ";");
|
||||||
path = dir + path;
|
path = dir + path;
|
||||||
i++;
|
i++;
|
||||||
if (i == 1) {
|
if (i == 1)
|
||||||
|
{
|
||||||
removeFile(path);
|
removeFile(path);
|
||||||
SerialPrint("!", "Loging2", String(i) + ") " + path + " => oldest files been deleted");
|
SerialPrint("!", "Loging2", String(i) + ") " + path + " => oldest files been deleted");
|
||||||
return;
|
return;
|
||||||
@@ -305,15 +360,17 @@ class Loging2 : public IoTItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPublishDestination(int publishType, int wsNum) {
|
void setPublishDestination(int publishType, int wsNum)
|
||||||
|
{
|
||||||
_publishType = publishType;
|
_publishType = publishType;
|
||||||
_wsNum = wsNum;
|
_wsNum = wsNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getValue() {
|
String getValue()
|
||||||
|
{
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
void loop() {
|
void loop() {
|
||||||
if (enableDoByInt) {
|
if (enableDoByInt) {
|
||||||
currentMillis = millis();
|
currentMillis = millis();
|
||||||
@@ -326,12 +383,14 @@ class Loging2 : public IoTItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
void regEvent(const String &value, const String &consoleInfo, bool error = false, bool genEvent = true) {
|
void regEvent(const String &value, const String &consoleInfo, bool error = false, bool genEvent = true)
|
||||||
|
{
|
||||||
String userDate = getItemValue(id + "-date");
|
String userDate = getItemValue(id + "-date");
|
||||||
String currentDate = getTodayDateDotFormated();
|
String currentDate = getTodayDateDotFormated();
|
||||||
// отправляем в график данные только когда выбран сегодняшний день
|
// отправляем в график данные только когда выбран сегодняшний день
|
||||||
if (userDate == currentDate) {
|
if (userDate == currentDate)
|
||||||
|
{
|
||||||
// generateEvent(_id, value);
|
// generateEvent(_id, value);
|
||||||
// publishStatusMqtt(_id, value);
|
// publishStatusMqtt(_id, value);
|
||||||
|
|
||||||
@@ -341,53 +400,69 @@ class Loging2 : public IoTItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// просто максимальное количество точек
|
// просто максимальное количество точек
|
||||||
int calculateMaxCount() {
|
int calculateMaxCount()
|
||||||
|
{
|
||||||
return 86400;
|
return 86400;
|
||||||
}
|
}
|
||||||
|
|
||||||
// путь вида: /lg/log/1231231.txt
|
// путь вида: /lg/log/1231231.txt
|
||||||
unsigned long getFileUnixLocalTime(String path) {
|
unsigned long getFileUnixLocalTime(String path)
|
||||||
|
{
|
||||||
return gmtTimeToLocal(selectToMarkerLast(deleteToMarkerLast(path, "."), "/").toInt() + START_DATETIME);
|
return gmtTimeToLocal(selectToMarkerLast(deleteToMarkerLast(path, "."), "/").toInt() + START_DATETIME);
|
||||||
}
|
}
|
||||||
void setValue(const IoTValue &Value, bool genEvent = true) {
|
/*
|
||||||
|
void setValue(const IoTValue &Value, bool genEvent = true)
|
||||||
|
{
|
||||||
value = Value;
|
value = Value;
|
||||||
this->SetDoByInterval(String(value.valD));
|
this->SetDoByInterval(String(value.valD));
|
||||||
SerialPrint("i", "Loging2", "setValue:" + String(value.valD));
|
SerialPrint("i", "Loging2", "setValue:" + String(value.valD));
|
||||||
regEvent(value.valS, "Loging2", false, genEvent);
|
regEvent(value.valS, "Loging2", false, genEvent);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
};
|
};
|
||||||
|
|
||||||
void *getAPI_Loging2(String subtype, String param) {
|
void *getAPI_Loging2(String subtype, String param)
|
||||||
if (subtype == F("Loging2")) {
|
{
|
||||||
|
if (subtype == F("Loging2"))
|
||||||
|
{
|
||||||
return new Loging2(param);
|
return new Loging2(param);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Date : public IoTItem {
|
class Date : public IoTItem
|
||||||
private:
|
{
|
||||||
|
private:
|
||||||
bool firstTime = true;
|
bool firstTime = true;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
String id;
|
String id;
|
||||||
Date(String parameters) : IoTItem(parameters) {
|
Date(String parameters) : IoTItem(parameters)
|
||||||
|
{
|
||||||
jsonRead(parameters, F("id"), id);
|
jsonRead(parameters, F("id"), id);
|
||||||
value.isDecimal = false;
|
value.isDecimal = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setValue(const String &valStr, bool genEvent = true) {
|
void setValue(const String &valStr, bool genEvent = true)
|
||||||
|
{
|
||||||
value.valS = valStr;
|
value.valS = valStr;
|
||||||
setValue(value, genEvent);
|
setValue(value, genEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setValue(const IoTValue &Value, bool genEvent = true) {
|
void setValue(const IoTValue &Value, bool genEvent = true)
|
||||||
|
{
|
||||||
value = Value;
|
value = Value;
|
||||||
regEvent(value.valS, "", false, genEvent);
|
regEvent(value.valS, "", false, genEvent);
|
||||||
// отправка данных при изменении даты
|
// отправка данных при изменении даты
|
||||||
for (std::list<IoTItem *>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) {
|
for (std::list<IoTItem *>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it)
|
||||||
if ((*it)->getSubtype() == "Loging2") {
|
{
|
||||||
if ((*it)->getID() == selectToMarker(id, "-")) {
|
if ((*it)->getSubtype() == "Loging2")
|
||||||
|
{
|
||||||
|
if ((*it)->getID() == selectToMarker(id, "-"))
|
||||||
|
{
|
||||||
(*it)->setPublishDestination(TO_MQTT_WS, -1);
|
(*it)->setPublishDestination(TO_MQTT_WS, -1);
|
||||||
(*it)->publishValue();
|
(*it)->publishValue();
|
||||||
}
|
}
|
||||||
@@ -395,14 +470,18 @@ class Date : public IoTItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setTodayDate() {
|
void setTodayDate()
|
||||||
|
{
|
||||||
setValue(getTodayDateDotFormated());
|
setValue(getTodayDateDotFormated());
|
||||||
SerialPrint("E", F("Loging2"), "today date set " + getTodayDateDotFormated());
|
SerialPrint("E", F("Loging2"), "today date set " + getTodayDateDotFormated());
|
||||||
}
|
}
|
||||||
|
|
||||||
void doByInterval() {
|
void doByInterval()
|
||||||
if (isTimeSynch) {
|
{
|
||||||
if (firstTime) {
|
if (isTimeSynch)
|
||||||
|
{
|
||||||
|
if (firstTime)
|
||||||
|
{
|
||||||
setTodayDate();
|
setTodayDate();
|
||||||
firstTime = false;
|
firstTime = false;
|
||||||
}
|
}
|
||||||
@@ -410,6 +489,7 @@ class Date : public IoTItem {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void *getAPI_Date2(String param) {
|
void *getAPI_Date2(String param)
|
||||||
|
{
|
||||||
return new Date(param);
|
return new Date(param);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,9 @@
|
|||||||
|
|
||||||
void *getAPI_Date3(String params);
|
void *getAPI_Date3(String params);
|
||||||
|
|
||||||
class Loging3 : public IoTItem {
|
class Loging3 : public IoTItem
|
||||||
private:
|
{
|
||||||
|
private:
|
||||||
String logid1;
|
String logid1;
|
||||||
String logid2;
|
String logid2;
|
||||||
String logid3;
|
String logid3;
|
||||||
@@ -18,31 +19,33 @@ class Loging3 : public IoTItem {
|
|||||||
int _wsNum = -1;
|
int _wsNum = -1;
|
||||||
|
|
||||||
int points;
|
int points;
|
||||||
//int keepdays;
|
// int keepdays;
|
||||||
|
|
||||||
IoTItem *dateIoTItem;
|
IoTItem *dateIoTItem;
|
||||||
|
|
||||||
String prevDate = "";
|
String prevDate = "";
|
||||||
bool firstTimeInit = true;
|
bool firstTimeInit = true;
|
||||||
|
|
||||||
//long interval;
|
// long interval;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Loging3(String parameters) : IoTItem(parameters) {
|
Loging3(String parameters) : IoTItem(parameters)
|
||||||
|
{
|
||||||
jsonRead(parameters, F("logid1"), logid1);
|
jsonRead(parameters, F("logid1"), logid1);
|
||||||
jsonRead(parameters, F("logid2"), logid2);
|
jsonRead(parameters, F("logid2"), logid2);
|
||||||
jsonRead(parameters, F("logid3"), logid3);
|
jsonRead(parameters, F("logid3"), logid3);
|
||||||
jsonRead(parameters, F("id"), id);
|
jsonRead(parameters, F("id"), id);
|
||||||
jsonRead(parameters, F("points"), points);
|
jsonRead(parameters, F("points"), points);
|
||||||
if (points > 300) {
|
if (points > 300)
|
||||||
|
{
|
||||||
points = 300;
|
points = 300;
|
||||||
SerialPrint("E", F("Loging3"), "'" + id + "' user set more points than allowed, value reset to 300");
|
SerialPrint("E", F("Loging3"), "'" + id + "' user set more points than allowed, value reset to 300");
|
||||||
}
|
}
|
||||||
|
|
||||||
long interval;
|
long interval;
|
||||||
jsonRead(parameters, F("int"), interval);
|
jsonRead(parameters, F("int"), interval); // в минутах
|
||||||
interval = interval * 60; // приводим к милисекундам
|
setInterval(interval * 60);
|
||||||
//jsonRead(parameters, F("keepdays"), keepdays, false);
|
// jsonRead(parameters, F("keepdays"), keepdays, false);
|
||||||
|
|
||||||
// создадим экземпляр класса даты
|
// создадим экземпляр класса даты
|
||||||
dateIoTItem = (IoTItem *)getAPI_Date3("{\"id\": \"" + id + "-date\",\"int\":\"20\",\"subtype\":\"date\"}");
|
dateIoTItem = (IoTItem *)getAPI_Date3("{\"id\": \"" + id + "-date\",\"int\":\"20\",\"subtype\":\"date\"}");
|
||||||
@@ -50,41 +53,47 @@ class Loging3 : public IoTItem {
|
|||||||
SerialPrint("I", F("Loging3"), "created date instance " + id);
|
SerialPrint("I", F("Loging3"), "created date instance " + id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void doByInterval() {
|
void doByInterval()
|
||||||
|
{
|
||||||
// если объект логгирования не был создан
|
// если объект логгирования не был создан
|
||||||
if (!isItemExist(logid1)) {
|
if (!isItemExist(logid1))
|
||||||
|
{
|
||||||
SerialPrint("E", F("Loging3"), "'" + id + "' loging object not exist, return");
|
SerialPrint("E", F("Loging3"), "'" + id + "' loging object not exist, return");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String value = getItemValue(logid1);
|
String value = getItemValue(logid1);
|
||||||
// если значение логгирования пустое
|
// если значение логгирования пустое
|
||||||
if (value == "") {
|
if (value == "")
|
||||||
|
{
|
||||||
SerialPrint("E", F("Loging3"), "'" + id + "' loging value is empty, return");
|
SerialPrint("E", F("Loging3"), "'" + id + "' loging value is empty, return");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String value2 = getItemValue(logid2);
|
String value2 = getItemValue(logid2);
|
||||||
// если значение логгирования пустое
|
// если значение логгирования пустое
|
||||||
if (value == "") {
|
if (value == "")
|
||||||
|
{
|
||||||
SerialPrint("E", F("Loging3"), "'" + id + "' loging value is empty, return");
|
SerialPrint("E", F("Loging3"), "'" + id + "' loging value is empty, return");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String value3 = getItemValue(logid3);
|
String value3 = getItemValue(logid3);
|
||||||
// если значение логгирования пустое
|
// если значение логгирования пустое
|
||||||
if (value == "") {
|
if (value == "")
|
||||||
|
{
|
||||||
SerialPrint("E", F("Loging3"), "'" + id + "' loging value is empty, return");
|
SerialPrint("E", F("Loging3"), "'" + id + "' loging value is empty, return");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// если время не было получено из интернета
|
// если время не было получено из интернета
|
||||||
if (!isTimeSynch) {
|
if (!isTimeSynch)
|
||||||
|
{
|
||||||
SerialPrint("E", F("Loging"), "'" + id + "' Сant loging - time not synchronized, return");
|
SerialPrint("E", F("Loging"), "'" + id + "' Сant loging - time not synchronized, return");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
regEvent(value, F("Loging3"));
|
regEvent(value, F("Loging3"));
|
||||||
|
|
||||||
//String logData2;
|
// String logData2;
|
||||||
String logData3;
|
String logData3;
|
||||||
|
|
||||||
jsonWriteInt(logData3, "x", unixTime, false);
|
jsonWriteInt(logData3, "x", unixTime, false);
|
||||||
@@ -96,13 +105,17 @@ class Loging3 : public IoTItem {
|
|||||||
String filePath = readDataDB(id);
|
String filePath = readDataDB(id);
|
||||||
|
|
||||||
// если данные о файле отсутствуют, создадим новый
|
// если данные о файле отсутствуют, создадим новый
|
||||||
if (filePath == "failed" || filePath == "") {
|
if (filePath == "failed" || filePath == "")
|
||||||
|
{
|
||||||
SerialPrint("E", F("Loging3"), "'" + id + "' file path not found, start create new file");
|
SerialPrint("E", F("Loging3"), "'" + id + "' file path not found, start create new file");
|
||||||
createNewFileWithData(logData3);
|
createNewFileWithData(logData3);
|
||||||
return;
|
return;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
// если файл все же есть но был создан не сегодня, то создаем сегодняшний
|
// если файл все же есть но был создан не сегодня, то создаем сегодняшний
|
||||||
if (getTodayDateDotFormated() != getDateDotFormatedFromUnix(getFileUnixLocalTime(filePath))) {
|
if (getTodayDateDotFormated() != getDateDotFormatedFromUnix(getFileUnixLocalTime(filePath)))
|
||||||
|
{
|
||||||
SerialPrint("E", F("Loging3"), "'" + id + "' file too old, start create new file");
|
SerialPrint("E", F("Loging3"), "'" + id + "' file too old, start create new file");
|
||||||
createNewFileWithData(logData3);
|
createNewFileWithData(logData3);
|
||||||
return;
|
return;
|
||||||
@@ -115,17 +128,20 @@ class Loging3 : public IoTItem {
|
|||||||
SerialPrint("i", F("Loging3"), "'" + id + "' " + "lines = " + String(lines) + ", size = " + String(size));
|
SerialPrint("i", F("Loging3"), "'" + id + "' " + "lines = " + String(lines) + ", size = " + String(size));
|
||||||
|
|
||||||
// если количество строк до заданной величины и дата не менялась
|
// если количество строк до заданной величины и дата не менялась
|
||||||
if (lines <= points && !hasDayChanged()) {
|
if (lines <= points && !hasDayChanged())
|
||||||
|
{
|
||||||
// просто добавим в существующий файл новые данные
|
// просто добавим в существующий файл новые данные
|
||||||
addNewDataToExistingFile(filePath, logData3);
|
addNewDataToExistingFile(filePath, logData3);
|
||||||
// если больше или поменялась дата то создадим следующий файл
|
// если больше или поменялась дата то создадим следующий файл
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
createNewFileWithData(logData3);
|
createNewFileWithData(logData3);
|
||||||
}
|
}
|
||||||
// запускаем процедуру удаления старых файлов если память переполняется
|
// запускаем процедуру удаления старых файлов если память переполняется
|
||||||
deleteLastFile();
|
deleteLastFile();
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
void SetDoByInterval(String valse) {
|
void SetDoByInterval(String valse) {
|
||||||
String value = valse;
|
String value = valse;
|
||||||
// если значение логгирования пустое
|
// если значение логгирования пустое
|
||||||
@@ -177,31 +193,38 @@ class Loging3 : public IoTItem {
|
|||||||
// запускаем процедуру удаления старых файлов если память переполняется
|
// запускаем процедуру удаления старых файлов если память переполняется
|
||||||
deleteLastFile();
|
deleteLastFile();
|
||||||
}
|
}
|
||||||
void createNewFileWithData(String &logData) {
|
*/
|
||||||
|
void createNewFileWithData(String &logData)
|
||||||
|
{
|
||||||
logData = logData + ",";
|
logData = logData + ",";
|
||||||
String path = "/lg3/" + id + "/" + String(unixTimeShort) + ".txt"; // создадим путь вида /lg/id/133256622333.txt
|
String path = "/lg3/" + id + "/" + String(unixTimeShort) + ".txt"; // создадим путь вида /lg/id/133256622333.txt
|
||||||
// создадим пустой файл
|
// создадим пустой файл
|
||||||
if (writeEmptyFile(path) != "success") {
|
if (writeEmptyFile(path) != "success")
|
||||||
|
{
|
||||||
SerialPrint("E", F("Loging"), "'" + id + "' file writing error, return");
|
SerialPrint("E", F("Loging"), "'" + id + "' file writing error, return");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// запишем в него данные
|
// запишем в него данные
|
||||||
if (addFile(path, logData) != "success") {
|
if (addFile(path, logData) != "success")
|
||||||
|
{
|
||||||
SerialPrint("E", F("Loging3"), "'" + id + "' data writing error, return");
|
SerialPrint("E", F("Loging3"), "'" + id + "' data writing error, return");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// запишем путь к нему в базу данных
|
// запишем путь к нему в базу данных
|
||||||
if (saveDataDB(id, path) != "success") {
|
if (saveDataDB(id, path) != "success")
|
||||||
|
{
|
||||||
SerialPrint("E", F("Loging3"), "'" + id + "' db file writing error, return");
|
SerialPrint("E", F("Loging3"), "'" + id + "' db file writing error, return");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SerialPrint("i", F("Loging3"), "'" + id + "' file created http://" + WiFi.localIP().toString() + path);
|
SerialPrint("i", F("Loging3"), "'" + id + "' file created http://" + WiFi.localIP().toString() + path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void addNewDataToExistingFile(String &path, String &logData) {
|
void addNewDataToExistingFile(String &path, String &logData)
|
||||||
|
{
|
||||||
logData = logData + ",";
|
logData = logData + ",";
|
||||||
if (addFile(path, logData) != "success") {
|
if (addFile(path, logData) != "success")
|
||||||
|
{
|
||||||
SerialPrint("i", F("Loging3"), "'" + id + "' file writing error, return");
|
SerialPrint("i", F("Loging3"), "'" + id + "' file writing error, return");
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
@@ -209,11 +232,14 @@ class Loging3 : public IoTItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// данная функция уже перенесена в ядро и будет удалена в последствии
|
// данная функция уже перенесена в ядро и будет удалена в последствии
|
||||||
bool hasDayChanged() {
|
bool hasDayChanged()
|
||||||
|
{
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
String currentDate = getTodayDateDotFormated();
|
String currentDate = getTodayDateDotFormated();
|
||||||
if (!firstTimeInit) {
|
if (!firstTimeInit)
|
||||||
if (prevDate != currentDate) {
|
{
|
||||||
|
if (prevDate != currentDate)
|
||||||
|
{
|
||||||
changed = true;
|
changed = true;
|
||||||
SerialPrint("i", F("NTP"), F("Change day event"));
|
SerialPrint("i", F("NTP"), F("Change day event"));
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
@@ -228,7 +254,8 @@ class Loging3 : public IoTItem {
|
|||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void publishValue() {
|
void publishValue()
|
||||||
|
{
|
||||||
String dir = "/lg3/" + id;
|
String dir = "/lg3/" + id;
|
||||||
filesList = getFilesList(dir);
|
filesList = getFilesList(dir);
|
||||||
|
|
||||||
@@ -238,7 +265,8 @@ class Loging3 : public IoTItem {
|
|||||||
|
|
||||||
bool noData = true;
|
bool noData = true;
|
||||||
|
|
||||||
while (filesList.length()) {
|
while (filesList.length())
|
||||||
|
{
|
||||||
String path = selectToMarker(filesList, ";");
|
String path = selectToMarker(filesList, ";");
|
||||||
|
|
||||||
path = "/lg3/" + id + path;
|
path = "/lg3/" + id + path;
|
||||||
@@ -248,65 +276,84 @@ class Loging3 : public IoTItem {
|
|||||||
unsigned long fileUnixTimeLocal = getFileUnixLocalTime(path);
|
unsigned long fileUnixTimeLocal = getFileUnixLocalTime(path);
|
||||||
|
|
||||||
unsigned long reqUnixTime = strDateToUnix(getItemValue(id + "-date"));
|
unsigned long reqUnixTime = strDateToUnix(getItemValue(id + "-date"));
|
||||||
if (fileUnixTimeLocal > reqUnixTime && fileUnixTimeLocal < reqUnixTime + 86400) {
|
if (fileUnixTimeLocal > reqUnixTime && fileUnixTimeLocal < reqUnixTime + 86400)
|
||||||
|
{
|
||||||
noData = false;
|
noData = false;
|
||||||
String json = getAdditionalJson();
|
String json = getAdditionalJson();
|
||||||
if (_publishType == TO_MQTT) {
|
if (_publishType == TO_MQTT)
|
||||||
|
{
|
||||||
publishChartFileToMqtt(path, id, calculateMaxCount());
|
publishChartFileToMqtt(path, id, calculateMaxCount());
|
||||||
} else if (_publishType == TO_WS) {
|
}
|
||||||
|
else if (_publishType == TO_WS)
|
||||||
|
{
|
||||||
sendFileToWsByFrames(path, "charta", json, _wsNum, WEB_SOCKETS_FRAME_SIZE);
|
sendFileToWsByFrames(path, "charta", json, _wsNum, WEB_SOCKETS_FRAME_SIZE);
|
||||||
} else if (_publishType == TO_MQTT_WS) {
|
}
|
||||||
|
else if (_publishType == TO_MQTT_WS)
|
||||||
|
{
|
||||||
sendFileToWsByFrames(path, "charta", json, _wsNum, WEB_SOCKETS_FRAME_SIZE);
|
sendFileToWsByFrames(path, "charta", json, _wsNum, WEB_SOCKETS_FRAME_SIZE);
|
||||||
publishChartFileToMqtt(path, id, calculateMaxCount());
|
publishChartFileToMqtt(path, id, calculateMaxCount());
|
||||||
}
|
}
|
||||||
SerialPrint("i", F("Loging3"), String(f) + ") " + path + ", " + getDateTimeDotFormatedFromUnix(fileUnixTimeLocal) + ", sent");
|
SerialPrint("i", F("Loging3"), String(f) + ") " + path + ", " + getDateTimeDotFormatedFromUnix(fileUnixTimeLocal) + ", sent");
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
SerialPrint("i", F("Loging3"), String(f) + ") " + path + ", " + getDateTimeDotFormatedFromUnix(fileUnixTimeLocal) + ", skipped");
|
SerialPrint("i", F("Loging3"), String(f) + ") " + path + ", " + getDateTimeDotFormatedFromUnix(fileUnixTimeLocal) + ", skipped");
|
||||||
}
|
}
|
||||||
|
|
||||||
filesList = deleteBeforeDelimiter(filesList, ";");
|
filesList = deleteBeforeDelimiter(filesList, ";");
|
||||||
}
|
}
|
||||||
// если данных нет отправляем пустой грфик
|
// если данных нет отправляем пустой грфик
|
||||||
if (noData) {
|
if (noData)
|
||||||
|
{
|
||||||
clearValue();
|
clearValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String getAdditionalJson() {
|
String getAdditionalJson()
|
||||||
|
{
|
||||||
String topic = mqttRootDevice + "/" + id;
|
String topic = mqttRootDevice + "/" + id;
|
||||||
String json = "{\"maxCount\":" + String(calculateMaxCount()) + ",\"topic\":\"" + topic + "\"}";
|
String json = "{\"maxCount\":" + String(calculateMaxCount()) + ",\"topic\":\"" + topic + "\"}";
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
void publishChartToWsSinglePoint(String value) {
|
void publishChartToWsSinglePoint(String value)
|
||||||
|
{
|
||||||
String topic = mqttRootDevice + "/" + id;
|
String topic = mqttRootDevice + "/" + id;
|
||||||
String json = "{\"maxCount\":" + String(calculateMaxCount()) + ",\"topic\":\"" + topic + "\",\"status\":[{\"x\":" + String(unixTime) + ",\"y1\":" + value + ",\"y2\":" + value + ",\"y3\":" + value + "}]}";
|
String value2 = getItemValue(logid2);
|
||||||
|
String value3 = getItemValue(logid3);
|
||||||
|
String json = "{\"maxCount\":" + String(calculateMaxCount()) + ",\"topic\":\"" + topic + "\",\"status\":[{\"x\":" + String(unixTime) + ",\"y1\":" + value + ",\"y2\":" + value2 + ",\"y3\":" + value3 + "}]}";
|
||||||
sendStringToWs("chartb", json, -1);
|
sendStringToWs("chartb", json, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearValue() {
|
void clearValue()
|
||||||
|
{
|
||||||
String topic = mqttRootDevice + "/" + id;
|
String topic = mqttRootDevice + "/" + id;
|
||||||
String json = "{\"maxCount\":0,\"topic\":\"" + topic + "\",\"status\":[]}";
|
String json = "{\"maxCount\":0,\"topic\":\"" + topic + "\",\"status\":[]}";
|
||||||
sendStringToWs("chartb", json, -1);
|
sendStringToWs("chartb", json, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearHistory() {
|
void clearHistory()
|
||||||
|
{
|
||||||
String dir = "/lg3/" + id;
|
String dir = "/lg3/" + id;
|
||||||
cleanDirectory(dir);
|
cleanDirectory(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
void deleteLastFile() {
|
void deleteLastFile()
|
||||||
|
{
|
||||||
IoTFSInfo tmp = getFSInfo();
|
IoTFSInfo tmp = getFSInfo();
|
||||||
SerialPrint("i", "Loging3", String(tmp.freePer) + " % free flash remaining");
|
SerialPrint("i", "Loging3", String(tmp.freePer) + " % free flash remaining");
|
||||||
if (tmp.freePer <= 20.00) {
|
if (tmp.freePer <= 20.00)
|
||||||
|
{
|
||||||
String dir = "/lg3/" + id;
|
String dir = "/lg3/" + id;
|
||||||
filesList = getFilesList(dir);
|
filesList = getFilesList(dir);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (filesList.length()) {
|
while (filesList.length())
|
||||||
|
{
|
||||||
String path = selectToMarker(filesList, ";");
|
String path = selectToMarker(filesList, ";");
|
||||||
path = dir + path;
|
path = dir + path;
|
||||||
i++;
|
i++;
|
||||||
if (i == 1) {
|
if (i == 1)
|
||||||
|
{
|
||||||
removeFile(path);
|
removeFile(path);
|
||||||
SerialPrint("!", "Loging3", String(i) + ") " + path + " => oldest files been deleted");
|
SerialPrint("!", "Loging3", String(i) + ") " + path + " => oldest files been deleted");
|
||||||
return;
|
return;
|
||||||
@@ -317,15 +364,17 @@ class Loging3 : public IoTItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPublishDestination(int publishType, int wsNum) {
|
void setPublishDestination(int publishType, int wsNum)
|
||||||
|
{
|
||||||
_publishType = publishType;
|
_publishType = publishType;
|
||||||
_wsNum = wsNum;
|
_wsNum = wsNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getValue() {
|
String getValue()
|
||||||
|
{
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
void loop() {
|
void loop() {
|
||||||
if (enableDoByInt) {
|
if (enableDoByInt) {
|
||||||
currentMillis = millis();
|
currentMillis = millis();
|
||||||
@@ -338,12 +387,14 @@ class Loging3 : public IoTItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
void regEvent(const String &value, const String &consoleInfo, bool error = false, bool genEvent = true) {
|
void regEvent(const String &value, const String &consoleInfo, bool error = false, bool genEvent = true)
|
||||||
|
{
|
||||||
String userDate = getItemValue(id + "-date");
|
String userDate = getItemValue(id + "-date");
|
||||||
String currentDate = getTodayDateDotFormated();
|
String currentDate = getTodayDateDotFormated();
|
||||||
// отправляем в график данные только когда выбран сегодняшний день
|
// отправляем в график данные только когда выбран сегодняшний день
|
||||||
if (userDate == currentDate) {
|
if (userDate == currentDate)
|
||||||
|
{
|
||||||
// generateEvent(_id, value);
|
// generateEvent(_id, value);
|
||||||
// publishStatusMqtt(_id, value);
|
// publishStatusMqtt(_id, value);
|
||||||
|
|
||||||
@@ -353,53 +404,68 @@ class Loging3 : public IoTItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// просто максимальное количество точек
|
// просто максимальное количество точек
|
||||||
int calculateMaxCount() {
|
int calculateMaxCount()
|
||||||
|
{
|
||||||
return 86400;
|
return 86400;
|
||||||
}
|
}
|
||||||
|
|
||||||
// путь вида: /lg/log/1231231.txt
|
// путь вида: /lg/log/1231231.txt
|
||||||
unsigned long getFileUnixLocalTime(String path) {
|
unsigned long getFileUnixLocalTime(String path)
|
||||||
|
{
|
||||||
return gmtTimeToLocal(selectToMarkerLast(deleteToMarkerLast(path, "."), "/").toInt() + START_DATETIME);
|
return gmtTimeToLocal(selectToMarkerLast(deleteToMarkerLast(path, "."), "/").toInt() + START_DATETIME);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
void setValue(const IoTValue &Value, bool genEvent = true) {
|
void setValue(const IoTValue &Value, bool genEvent = true) {
|
||||||
value = Value;
|
value = Value;
|
||||||
this->SetDoByInterval(String(value.valD));
|
this->SetDoByInterval(String(value.valD));
|
||||||
SerialPrint("i", "Loging3", "setValue:" + String(value.valD));
|
SerialPrint("i", "Loging3", "setValue:" + String(value.valD));
|
||||||
regEvent(value.valS, "Loging3", false, genEvent);
|
regEvent(value.valS, "Loging3", false, genEvent);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
};
|
};
|
||||||
|
|
||||||
void *getAPI_Loging3(String subtype, String param) {
|
void *getAPI_Loging3(String subtype, String param)
|
||||||
if (subtype == F("Loging3")) {
|
{
|
||||||
|
if (subtype == F("Loging3"))
|
||||||
|
{
|
||||||
return new Loging3(param);
|
return new Loging3(param);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Date : public IoTItem {
|
class Date : public IoTItem
|
||||||
private:
|
{
|
||||||
|
private:
|
||||||
bool firstTime = true;
|
bool firstTime = true;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
String id;
|
String id;
|
||||||
Date(String parameters) : IoTItem(parameters) {
|
Date(String parameters) : IoTItem(parameters)
|
||||||
|
{
|
||||||
jsonRead(parameters, F("id"), id);
|
jsonRead(parameters, F("id"), id);
|
||||||
value.isDecimal = false;
|
value.isDecimal = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setValue(const String &valStr, bool genEvent = true) {
|
void setValue(const String &valStr, bool genEvent = true)
|
||||||
|
{
|
||||||
value.valS = valStr;
|
value.valS = valStr;
|
||||||
setValue(value, genEvent);
|
setValue(value, genEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setValue(const IoTValue &Value, bool genEvent = true) {
|
void setValue(const IoTValue &Value, bool genEvent = true)
|
||||||
|
{
|
||||||
value = Value;
|
value = Value;
|
||||||
regEvent(value.valS, "", false, genEvent);
|
regEvent(value.valS, "", false, genEvent);
|
||||||
// отправка данных при изменении даты
|
// отправка данных при изменении даты
|
||||||
for (std::list<IoTItem *>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) {
|
for (std::list<IoTItem *>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it)
|
||||||
if ((*it)->getSubtype() == "Loging3") {
|
{
|
||||||
if ((*it)->getID() == selectToMarker(id, "-")) {
|
if ((*it)->getSubtype() == "Loging3")
|
||||||
|
{
|
||||||
|
if ((*it)->getID() == selectToMarker(id, "-"))
|
||||||
|
{
|
||||||
(*it)->setPublishDestination(TO_MQTT_WS, -1);
|
(*it)->setPublishDestination(TO_MQTT_WS, -1);
|
||||||
(*it)->publishValue();
|
(*it)->publishValue();
|
||||||
}
|
}
|
||||||
@@ -407,14 +473,18 @@ class Date : public IoTItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setTodayDate() {
|
void setTodayDate()
|
||||||
|
{
|
||||||
setValue(getTodayDateDotFormated());
|
setValue(getTodayDateDotFormated());
|
||||||
SerialPrint("E", F("Loging3"), "today date set " + getTodayDateDotFormated());
|
SerialPrint("E", F("Loging3"), "today date set " + getTodayDateDotFormated());
|
||||||
}
|
}
|
||||||
|
|
||||||
void doByInterval() {
|
void doByInterval()
|
||||||
if (isTimeSynch) {
|
{
|
||||||
if (firstTime) {
|
if (isTimeSynch)
|
||||||
|
{
|
||||||
|
if (firstTime)
|
||||||
|
{
|
||||||
setTodayDate();
|
setTodayDate();
|
||||||
firstTime = false;
|
firstTime = false;
|
||||||
}
|
}
|
||||||
@@ -422,6 +492,7 @@ class Date : public IoTItem {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void *getAPI_Date3(String param) {
|
void *getAPI_Date3(String param)
|
||||||
|
{
|
||||||
return new Date(param);
|
return new Date(param);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user