2022-08-13 12:18:58 +02:00
|
|
|
|
#include "Global.h"
|
|
|
|
|
|
#include "classes/IoTItem.h"
|
2022-09-10 02:58:42 +02:00
|
|
|
|
#include "ESPConfiguration.h"
|
2022-08-25 15:46:19 +02:00
|
|
|
|
#include "NTP.h"
|
2022-08-13 12:18:58 +02:00
|
|
|
|
|
2022-09-10 02:58:42 +02:00
|
|
|
|
void *getAPI_Date(String params);
|
|
|
|
|
|
|
2022-08-13 12:18:58 +02:00
|
|
|
|
class Loging : public IoTItem {
|
|
|
|
|
|
private:
|
2022-08-25 23:16:49 +02:00
|
|
|
|
String logid;
|
2022-08-25 00:45:17 +02:00
|
|
|
|
String id;
|
2022-09-08 00:27:38 +02:00
|
|
|
|
String filesList = "";
|
|
|
|
|
|
|
2022-09-11 15:41:50 +02:00
|
|
|
|
int _publishType = -2;
|
|
|
|
|
|
int _wsNum = -1;
|
|
|
|
|
|
|
2022-08-25 15:15:06 +02:00
|
|
|
|
int points;
|
2022-08-30 00:41:27 +02:00
|
|
|
|
int keepdays;
|
2022-08-27 00:57:19 +02:00
|
|
|
|
|
2022-09-10 02:58:42 +02:00
|
|
|
|
IoTItem *dateIoTItem;
|
|
|
|
|
|
|
2022-09-13 00:56:34 +02:00
|
|
|
|
String prevDate = "";
|
|
|
|
|
|
bool firstTimeDate = true;
|
|
|
|
|
|
|
2022-09-08 18:48:27 +02:00
|
|
|
|
unsigned long interval;
|
2022-08-13 12:18:58 +02:00
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
Loging(String parameters) : IoTItem(parameters) {
|
2022-08-25 23:16:49 +02:00
|
|
|
|
jsonRead(parameters, F("logid"), logid);
|
2022-08-25 00:45:17 +02:00
|
|
|
|
jsonRead(parameters, F("id"), id);
|
2022-08-25 15:15:06 +02:00
|
|
|
|
jsonRead(parameters, F("points"), points);
|
2022-08-31 00:13:45 +02:00
|
|
|
|
if (points > 300) {
|
2022-08-30 00:23:06 +02:00
|
|
|
|
points = 300;
|
|
|
|
|
|
SerialPrint("E", F("Loging"), "'" + id + "' user set more points than allowed, value reset to 300");
|
|
|
|
|
|
}
|
2022-08-25 20:23:53 +02:00
|
|
|
|
jsonRead(parameters, F("int"), interval);
|
2022-09-08 19:21:28 +02:00
|
|
|
|
interval = interval * 1000 * 60; //приводим к милисекундам
|
2022-08-30 00:41:27 +02:00
|
|
|
|
jsonRead(parameters, F("keepdays"), keepdays);
|
2022-09-10 02:58:42 +02:00
|
|
|
|
|
|
|
|
|
|
//создадим экземпляр класса даты
|
2022-09-15 14:02:24 +02:00
|
|
|
|
dateIoTItem = (IoTItem *)getAPI_Date("{\"id\": \"" + id + "-date\",\"int\":\"20\",\"subtype\":\"date\"}");
|
2022-09-10 02:58:42 +02:00
|
|
|
|
IoTItems.push_back(dateIoTItem);
|
2022-09-11 10:39:51 +02:00
|
|
|
|
SerialPrint("E", F("Loging"), "created date instance " + id);
|
2022-08-25 15:15:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-08-13 12:18:58 +02:00
|
|
|
|
void doByInterval() {
|
2022-09-16 01:52:04 +02:00
|
|
|
|
SerialPrint("E", F("Loging"), "----------------------start loging cycle----------------------------");
|
2022-08-27 00:57:19 +02:00
|
|
|
|
//если объект логгирования не был создан
|
2022-08-25 23:16:49 +02:00
|
|
|
|
if (!isItemExist(logid)) {
|
2022-09-16 01:52:04 +02:00
|
|
|
|
SerialPrint("E", F("Loging"), "'" + id + "' loging object not exist, return");
|
2022-08-25 23:16:49 +02:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2022-08-27 00:57:19 +02:00
|
|
|
|
|
2022-08-25 23:16:49 +02:00
|
|
|
|
String value = getItemValue(logid);
|
2022-08-27 00:57:19 +02:00
|
|
|
|
//если значение логгирования пустое
|
2022-08-13 12:18:58 +02:00
|
|
|
|
if (value == "") {
|
2022-09-16 01:52:04 +02:00
|
|
|
|
SerialPrint("E", F("Loging"), "'" + id + "' loging value is empty, return");
|
2022-08-25 23:16:49 +02:00
|
|
|
|
return;
|
2022-08-27 00:57:19 +02:00
|
|
|
|
}
|
2022-08-25 00:45:17 +02:00
|
|
|
|
|
2022-08-27 00:57:19 +02:00
|
|
|
|
//если время не было получено из интернета
|
|
|
|
|
|
if (!isTimeSynch) {
|
2022-09-16 01:52:04 +02:00
|
|
|
|
SerialPrint("E", F("Loging"), "'" + id + "' Сant loging - time not synchronized, return");
|
2022-08-27 00:57:19 +02:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-08 23:35:19 +02:00
|
|
|
|
regEvent(value, F("Loging"));
|
2022-08-27 00:57:19 +02:00
|
|
|
|
|
|
|
|
|
|
String logData = String(unixTimeShort) + " " + value;
|
|
|
|
|
|
|
|
|
|
|
|
//прочитаем путь к файлу последнего сохранения
|
2022-08-27 01:24:59 +02:00
|
|
|
|
String filePath = readDataDB(id);
|
|
|
|
|
|
|
2022-08-27 00:57:19 +02:00
|
|
|
|
//если данные о файле отсутствуют, создадим новый
|
2022-08-30 00:23:06 +02:00
|
|
|
|
if (filePath == "failed" || filePath == "") {
|
2022-09-16 01:52:04 +02:00
|
|
|
|
SerialPrint("E", F("Loging"), "'" + id + "' file path not found, start create new file");
|
2022-08-27 00:57:19 +02:00
|
|
|
|
createNewFileWithData(logData);
|
2022-08-27 01:32:31 +02:00
|
|
|
|
return;
|
2022-09-16 01:52:04 +02:00
|
|
|
|
} else {
|
|
|
|
|
|
//если файл все же есть но был создан не сегодня, то создаем сегодняшний
|
|
|
|
|
|
if (getDateDotFormated() != getDateDotFormatedFromUnix(getFileUnixLocalTime(filePath))) {
|
|
|
|
|
|
SerialPrint("E", F("Loging"), "'" + id + "' file too old, start create new file");
|
|
|
|
|
|
createNewFileWithData(logData);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2022-08-13 12:18:58 +02:00
|
|
|
|
}
|
2022-08-27 00:57:19 +02:00
|
|
|
|
|
|
|
|
|
|
//считаем количество строк
|
2022-08-27 01:24:59 +02:00
|
|
|
|
int lines = countLines(filePath);
|
|
|
|
|
|
SerialPrint("i", F("Loging"), "'" + id + "' " + String(lines) + " lines found in file");
|
2022-08-27 00:57:19 +02:00
|
|
|
|
|
2022-09-13 00:56:34 +02:00
|
|
|
|
//если количество строк до заданной величины и дата не менялась
|
|
|
|
|
|
if (lines <= points && !hasDayChanged()) {
|
2022-08-27 00:57:19 +02:00
|
|
|
|
//просто добавим в существующий файл новые данные
|
|
|
|
|
|
addNewDataToExistingFile(filePath, logData);
|
2022-09-13 00:56:34 +02:00
|
|
|
|
//если больше или поменялась дата то создадим следующий файл
|
2022-08-27 00:57:19 +02:00
|
|
|
|
} else {
|
|
|
|
|
|
createNewFileWithData(logData);
|
|
|
|
|
|
}
|
2022-09-15 14:02:24 +02:00
|
|
|
|
//запускаем процедуру удаления старых файлов если память переполняется
|
|
|
|
|
|
deleteLastFile();
|
2022-09-16 01:52:04 +02:00
|
|
|
|
SerialPrint("E", F("Loging"), "----------------------compl loging cycle----------------------------");
|
2022-08-27 00:57:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void createNewFileWithData(String &logData) {
|
2022-09-08 00:27:38 +02:00
|
|
|
|
String path = "/lg/" + id + "/" + String(unixTimeShort) + ".txt"; //создадим путь вида /lg/id/133256622333.txt
|
2022-09-16 01:52:04 +02:00
|
|
|
|
//создадим пустой файл
|
|
|
|
|
|
if (writeEmptyFile(path) != "sucсess") {
|
|
|
|
|
|
SerialPrint("E", F("Loging"), "'" + id + "' file writing error, return");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
//запишем в него данные
|
|
|
|
|
|
if (addFileLn(path, logData) != "sucсess") {
|
|
|
|
|
|
SerialPrint("E", F("Loging"), "'" + id + "' data writing error, return");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
//запишем путь к нему в базу данных
|
|
|
|
|
|
if (saveDataDB(id, path) != "sucсess") {
|
|
|
|
|
|
SerialPrint("E", F("Loging"), "'" + id + "' db file writing error, return");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2022-08-30 00:23:06 +02:00
|
|
|
|
SerialPrint("i", F("Loging"), "'" + id + "' file created http://" + WiFi.localIP().toString() + path);
|
2022-08-13 12:18:58 +02:00
|
|
|
|
}
|
2022-08-25 00:45:17 +02:00
|
|
|
|
|
2022-08-30 00:23:06 +02:00
|
|
|
|
void addNewDataToExistingFile(String &path, String &logData) {
|
2022-09-16 01:52:04 +02:00
|
|
|
|
if (addFileLn(path, logData) != "sucсess") {
|
|
|
|
|
|
SerialPrint("i", F("Loging"), "'" + id + "' file writing error, return");
|
|
|
|
|
|
return;
|
|
|
|
|
|
};
|
2022-08-30 00:23:06 +02:00
|
|
|
|
SerialPrint("i", F("Loging"), "'" + id + "' loging in file http://" + WiFi.localIP().toString() + path);
|
2022-08-25 00:45:17 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-13 00:56:34 +02:00
|
|
|
|
bool hasDayChanged() {
|
|
|
|
|
|
bool changed = false;
|
|
|
|
|
|
String currentDate = getDateDotFormated();
|
|
|
|
|
|
if (!firstTimeDate) {
|
|
|
|
|
|
if (prevDate != currentDate) {
|
|
|
|
|
|
changed = true;
|
|
|
|
|
|
SerialPrint("i", F("NTP"), "Change day event");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
firstTimeDate = false;
|
|
|
|
|
|
prevDate = currentDate;
|
|
|
|
|
|
return changed;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-11 15:41:50 +02:00
|
|
|
|
void sendChart() {
|
2022-09-16 01:52:04 +02:00
|
|
|
|
SerialPrint("E", F("Loging"), "----------------------start send chart----------------------------");
|
|
|
|
|
|
|
|
|
|
|
|
String dir = "/lg/" + id;
|
2022-09-14 18:06:40 +02:00
|
|
|
|
filesList = getFilesList(dir);
|
2022-09-16 01:52:04 +02:00
|
|
|
|
|
|
|
|
|
|
SerialPrint("i", F("Loging"), "file list: " + filesList);
|
|
|
|
|
|
|
2022-09-08 00:27:38 +02:00
|
|
|
|
int f = 0;
|
2022-08-30 00:23:06 +02:00
|
|
|
|
|
2022-09-11 01:30:22 +02:00
|
|
|
|
bool noData = true;
|
|
|
|
|
|
|
2022-09-08 00:27:38 +02:00
|
|
|
|
while (filesList.length()) {
|
|
|
|
|
|
String buf = selectToMarker(filesList, ";");
|
|
|
|
|
|
|
2022-09-16 01:52:04 +02:00
|
|
|
|
buf = "/lg/" + id + buf;
|
|
|
|
|
|
|
2022-09-08 00:27:38 +02:00
|
|
|
|
f++;
|
|
|
|
|
|
int i = 0;
|
2022-09-08 19:21:28 +02:00
|
|
|
|
|
2022-09-16 01:52:04 +02:00
|
|
|
|
unsigned long fileUnixTimeLocal = getFileUnixLocalTime(buf);
|
2022-09-08 00:27:38 +02:00
|
|
|
|
|
2022-09-11 14:13:58 +02:00
|
|
|
|
unsigned long reqUnixTime = strDateToUnix(getItemValue(id + "-date"));
|
2022-09-11 01:30:22 +02:00
|
|
|
|
if (fileUnixTimeLocal > reqUnixTime && fileUnixTimeLocal < reqUnixTime + 86400) {
|
|
|
|
|
|
noData = false;
|
2022-09-16 01:52:04 +02:00
|
|
|
|
if (!createJson(buf, i)) {
|
|
|
|
|
|
SerialPrint("E", F("Loging"), buf + " file reading error, json not created, return");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2022-09-13 00:56:34 +02:00
|
|
|
|
SerialPrint("i", F("Loging"), String(f) + ") " + buf + ", " + String(i) + ", " + getDateTimeDotFormatedFromUnix(fileUnixTimeLocal) + ", sent");
|
2022-09-08 19:21:28 +02:00
|
|
|
|
} else {
|
2022-09-13 00:56:34 +02:00
|
|
|
|
SerialPrint("i", F("Loging"), String(f) + ") " + buf + ", nil, " + getDateTimeDotFormatedFromUnix(fileUnixTimeLocal) + ", skipped");
|
2022-09-08 19:21:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-08 00:27:38 +02:00
|
|
|
|
filesList = deleteBeforeDelimiter(filesList, ";");
|
2022-08-30 00:23:06 +02:00
|
|
|
|
}
|
2022-09-11 01:30:22 +02:00
|
|
|
|
//если данных нет отправляем пустой грфик
|
|
|
|
|
|
if (noData) {
|
2022-09-13 00:56:34 +02:00
|
|
|
|
cleanChart();
|
2022-09-11 01:30:22 +02:00
|
|
|
|
}
|
2022-09-16 01:52:04 +02:00
|
|
|
|
SerialPrint("E", F("Loging"), "----------------------compl send chart----------------------------");
|
2022-09-08 00:27:38 +02:00
|
|
|
|
}
|
2022-08-25 20:23:53 +02:00
|
|
|
|
|
2022-09-13 00:56:34 +02:00
|
|
|
|
void cleanChart() {
|
|
|
|
|
|
SerialPrint("i", F("Loging"), "clear chart");
|
|
|
|
|
|
String cleanJson = createEmtyJson();
|
|
|
|
|
|
publishJson(cleanJson);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-08 00:27:38 +02:00
|
|
|
|
void cleanData() {
|
2022-09-16 01:52:04 +02:00
|
|
|
|
String dir = "/lg/" + id;
|
|
|
|
|
|
cleanDirectory(dir);
|
2022-09-08 00:27:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-15 14:02:24 +02:00
|
|
|
|
void deleteLastFile() {
|
|
|
|
|
|
IoTFSInfo tmp = getFSInfo();
|
|
|
|
|
|
SerialPrint("i", "Loging", String(tmp.freePer) + " % free flash remaining");
|
2022-09-16 01:52:04 +02:00
|
|
|
|
if (tmp.freePer <= 20.00) {
|
|
|
|
|
|
String dir = "/lg/" + id;
|
2022-09-15 14:02:24 +02:00
|
|
|
|
filesList = getFilesList(dir);
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
while (filesList.length()) {
|
|
|
|
|
|
String buf = selectToMarker(filesList, ";");
|
|
|
|
|
|
|
2022-09-16 01:52:04 +02:00
|
|
|
|
buf = dir + buf;
|
|
|
|
|
|
|
2022-09-15 14:02:24 +02:00
|
|
|
|
i++;
|
|
|
|
|
|
if (i == 1) {
|
|
|
|
|
|
removeFile(buf);
|
|
|
|
|
|
SerialPrint("!", "Loging", String(i) + ") " + buf + " => oldest files been deleted");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
filesList = deleteBeforeDelimiter(filesList, ";");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-16 01:52:04 +02:00
|
|
|
|
bool createJson(String file, int &i) {
|
|
|
|
|
|
File configFile = FileFS.open(file, FILE_READ);
|
2022-09-08 00:27:38 +02:00
|
|
|
|
if (!configFile) {
|
2022-09-16 01:52:04 +02:00
|
|
|
|
return false;
|
2022-08-30 00:23:06 +02:00
|
|
|
|
}
|
2022-09-08 00:27:38 +02:00
|
|
|
|
configFile.seek(0, SeekSet);
|
|
|
|
|
|
String buf = "{}";
|
|
|
|
|
|
String oneSingleJson;
|
|
|
|
|
|
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 != "") {
|
|
|
|
|
|
oneSingleJson += buf + ",";
|
|
|
|
|
|
}
|
|
|
|
|
|
} while (psn < sz);
|
|
|
|
|
|
|
|
|
|
|
|
configFile.close();
|
|
|
|
|
|
|
|
|
|
|
|
String topic = mqttRootDevice + "/" + id;
|
|
|
|
|
|
oneSingleJson = "{\"maxCount\":" + String(calculateMaxCount()) + ",\"topic\":\"" + topic + "\",\"status\":[" + oneSingleJson + "]}";
|
|
|
|
|
|
oneSingleJson.replace("},]}", "}]}");
|
2022-08-13 12:18:58 +02:00
|
|
|
|
|
2022-09-11 15:41:50 +02:00
|
|
|
|
publishJson(oneSingleJson);
|
2022-09-16 01:52:04 +02:00
|
|
|
|
return true;
|
2022-09-11 15:41:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// publishType 1 - в mqtt, 2 - в ws, 3 - mqtt и ws
|
|
|
|
|
|
// wsNum = -1 => broadcast
|
|
|
|
|
|
void setPublishType(int publishType, int wsNum) {
|
|
|
|
|
|
_publishType = publishType;
|
|
|
|
|
|
_wsNum = wsNum;
|
2022-09-08 00:27:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-11 15:41:50 +02:00
|
|
|
|
void publishJson(String &oneSingleJson) {
|
|
|
|
|
|
if (_publishType == 1) {
|
2022-09-11 14:13:58 +02:00
|
|
|
|
publishChartMqtt(id, oneSingleJson);
|
2022-09-11 15:41:50 +02:00
|
|
|
|
} else if (_publishType == 2) {
|
|
|
|
|
|
publishChartWs(_wsNum, oneSingleJson);
|
|
|
|
|
|
} else if (_publishType == 3) {
|
2022-09-11 14:13:58 +02:00
|
|
|
|
publishChartMqtt(id, oneSingleJson);
|
2022-09-11 15:41:50 +02:00
|
|
|
|
publishChartWs(_wsNum, oneSingleJson);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
SerialPrint("E", F("Loging"), "wrong publishType");
|
2022-08-30 00:23:06 +02:00
|
|
|
|
}
|
2022-08-13 12:18:58 +02:00
|
|
|
|
}
|
2022-08-30 00:23:06 +02:00
|
|
|
|
|
2022-09-11 01:30:22 +02:00
|
|
|
|
String getValue() {
|
|
|
|
|
|
return "";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
|
|
if (enableDoByInt) {
|
|
|
|
|
|
currentMillis = millis();
|
|
|
|
|
|
difference = currentMillis - prevMillis;
|
|
|
|
|
|
if (difference >= interval) {
|
|
|
|
|
|
prevMillis = millis();
|
|
|
|
|
|
this->doByInterval();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void regEvent(String value, String consoleInfo = "") {
|
2022-09-13 00:56:34 +02:00
|
|
|
|
String userDate = getItemValue(id + "-date");
|
|
|
|
|
|
String currentDate = getDateDotFormated();
|
|
|
|
|
|
//отправляем в график данные только когда выбран сегодняшний день
|
|
|
|
|
|
if (userDate == currentDate) {
|
|
|
|
|
|
generateEvent(_id, value);
|
|
|
|
|
|
publishStatusMqtt(_id, value);
|
|
|
|
|
|
String json = createSingleJson(_id, value);
|
|
|
|
|
|
publishChartWs(-1, json);
|
|
|
|
|
|
SerialPrint("i", "Sensor " + consoleInfo, "'" + _id + "' data: " + value + "'");
|
|
|
|
|
|
}
|
2022-09-11 01:30:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String createSingleJson(String id, String value) {
|
|
|
|
|
|
String topic = mqttRootDevice + "/" + _id;
|
|
|
|
|
|
return "{\"topic\":\"" + topic + "\",\"status\":[{\"x\":" + String(unixTime) + ",\"y1\":" + value + "}]}";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String createEmtyJson() {
|
|
|
|
|
|
String topic = mqttRootDevice + "/" + _id;
|
|
|
|
|
|
return "{\"topic\":\"" + topic + "\",\"status\":[],\"maxCount\":\"0\"}";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-08 23:35:19 +02:00
|
|
|
|
//просто максимальное количество точек
|
2022-09-08 00:27:38 +02:00
|
|
|
|
int calculateMaxCount() {
|
2022-09-08 23:35:19 +02:00
|
|
|
|
return 86400;
|
2022-09-08 00:27:38 +02:00
|
|
|
|
}
|
2022-09-16 01:52:04 +02:00
|
|
|
|
|
|
|
|
|
|
//путь вида: /lg/log/1231231.txt
|
|
|
|
|
|
unsigned long getFileUnixLocalTime(String path) {
|
|
|
|
|
|
return gmtTimeToLocal(selectToMarkerLast(deleteToMarkerLast(path, "."), "/").toInt() + START_DATETIME);
|
|
|
|
|
|
}
|
2022-09-08 00:27:38 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void *getAPI_Loging(String subtype, String param) {
|
|
|
|
|
|
if (subtype == F("Loging")) {
|
|
|
|
|
|
return new Loging(param);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-09-10 02:58:42 +02:00
|
|
|
|
|
|
|
|
|
|
class Date : public IoTItem {
|
|
|
|
|
|
private:
|
2022-09-11 01:30:22 +02:00
|
|
|
|
bool firstTime = true;
|
|
|
|
|
|
|
2022-09-10 02:58:42 +02:00
|
|
|
|
public:
|
|
|
|
|
|
String id;
|
|
|
|
|
|
Date(String parameters) : IoTItem(parameters) {
|
|
|
|
|
|
jsonRead(parameters, F("id"), id);
|
|
|
|
|
|
value.isDecimal = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void setValue(String valStr) {
|
|
|
|
|
|
value.valS = valStr;
|
|
|
|
|
|
setValue(value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void setValue(IoTValue Value) {
|
|
|
|
|
|
value = Value;
|
|
|
|
|
|
regEvent(value.valS, "");
|
2022-09-11 14:13:58 +02:00
|
|
|
|
//отправка данных при изменении даты
|
2022-09-10 02:58:42 +02:00
|
|
|
|
for (std::list<IoTItem *>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) {
|
|
|
|
|
|
if ((*it)->getSubtype() == "Loging") {
|
2022-09-11 14:13:58 +02:00
|
|
|
|
//отправляем только свои данные
|
|
|
|
|
|
if ((*it)->getID() == selectToMarker(id, "-")) {
|
2022-09-11 15:41:50 +02:00
|
|
|
|
(*it)->setPublishType(3, -1);
|
2022-09-13 00:56:34 +02:00
|
|
|
|
(*it)->cleanChart();
|
2022-09-11 15:41:50 +02:00
|
|
|
|
(*it)->sendChart();
|
2022-09-11 14:13:58 +02:00
|
|
|
|
}
|
2022-09-10 02:58:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-11 01:30:22 +02:00
|
|
|
|
void doByInterval() {
|
|
|
|
|
|
if (isTimeSynch) {
|
|
|
|
|
|
if (firstTime) {
|
|
|
|
|
|
setValue(getDateDotFormated());
|
|
|
|
|
|
SerialPrint("E", F("Loging"), "today date set " + getDateDotFormated());
|
|
|
|
|
|
firstTime = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-09-10 02:58:42 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void *getAPI_Date(String param) {
|
|
|
|
|
|
return new Date(param);
|
|
|
|
|
|
}
|