From e7e174de103154e71f2eca2641e49d4a6679eab7 Mon Sep 17 00:00:00 2001 From: Dmitry Borisenko <49808844+DmitryBorisenko33@users.noreply.github.com> Date: Mon, 26 Sep 2022 16:19:44 +0200 Subject: [PATCH] =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=87=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=B3=D1=80=D0=B0=D1=84=D0=B8=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data_svelte/empty.txt | 1 - include/Const.h | 2 +- src/modules/virtual/Logging/Loging.cpp | 68 +++++++++++++----------- src/modules/virtual/Logging/modinfo.json | 10 ++-- 4 files changed, 41 insertions(+), 40 deletions(-) delete mode 100644 data_svelte/empty.txt diff --git a/data_svelte/empty.txt b/data_svelte/empty.txt deleted file mode 100644 index bfbc2438..00000000 --- a/data_svelte/empty.txt +++ /dev/null @@ -1 +0,0 @@ -{"x":0,"y1":0}, \ No newline at end of file diff --git a/include/Const.h b/include/Const.h index 4889c6cd..a164f11a 100644 --- a/include/Const.h +++ b/include/Const.h @@ -1,7 +1,7 @@ #pragma once //Версия прошивки -#define FIRMWARE_VERSION 425 +#define FIRMWARE_VERSION 426 #ifdef esp8266_4mb #define FIRMWARE_NAME "esp8266_4mb" diff --git a/src/modules/virtual/Logging/Loging.cpp b/src/modules/virtual/Logging/Loging.cpp index 441c4307..ae048d25 100644 --- a/src/modules/virtual/Logging/Loging.cpp +++ b/src/modules/virtual/Logging/Loging.cpp @@ -142,6 +142,11 @@ class Loging : public IoTItem { if (prevDate != currentDate) { changed = true; SerialPrint("i", F("NTP"), "Change day event"); +#if defined(ESP8266) + FileFS.gc(); +#endif +#if defined(ESP32) +#endif } } firstTimeDate = false; @@ -172,12 +177,12 @@ class Loging : public IoTItem { if (fileUnixTimeLocal > reqUnixTime && fileUnixTimeLocal < reqUnixTime + 86400) { noData = false; if (_publishType == TO_MQTT) { - sendChartFileToMqtt(path); + publishChartFileToMqtt(path); } else if (_publishType == TO_WS) { - sendChartFileToWs(path, _wsNum, 1000); + publishChartToWs(path, _wsNum, 1000); } else if (_publishType == TO_MQTT_WS) { - sendChartFileToMqtt(path); - sendChartFileToWs(path, _wsNum, 1000); + publishChartFileToMqtt(path); + publishChartToWs(path, _wsNum, 1000); } SerialPrint("i", F("Loging"), String(f) + ") " + path + ", " + getDateTimeDotFormatedFromUnix(fileUnixTimeLocal) + ", sent"); } else { @@ -192,11 +197,6 @@ class Loging : public IoTItem { } } - void clearValue() { - SerialPrint("i", F("Loging"), "clear chart"); - sendChartFileToWs("/empty.txt", -1, 1000); - } - void clearHistory() { String dir = "/lg/" + id; cleanDirectory(dir); @@ -211,9 +211,7 @@ class Loging : public IoTItem { int i = 0; while (filesList.length()) { String path = selectToMarker(filesList, ";"); - path = dir + path; - i++; if (i == 1) { removeFile(path); @@ -226,7 +224,7 @@ class Loging : public IoTItem { } } - bool sendChartFileToMqtt(String path) { + bool publishChartFileToMqtt(String path) { File configFile = FileFS.open(path, FILE_READ); if (!configFile) { SerialPrint("E", F("Loging"), path + " file reading error, json not created, return"); @@ -234,18 +232,21 @@ class Loging : public IoTItem { } String oneSingleJson = configFile.readString(); configFile.close(); - // String topic = mqttRootDevice + "/" + id; - // oneSingleJson = "{\"maxCount\":" + String(calculateMaxCount()) + ",\"topic\":\"" + topic + "\",\"status\":[" + oneSingleJson + "]}"; - oneSingleJson += "]}"; + String topic = mqttRootDevice + "/" + id; + oneSingleJson = "{\"maxCount\":" + String(calculateMaxCount()) + ",\"topic\":\"" + topic + "\",\"status\":[" + oneSingleJson + "]}"; oneSingleJson.replace("},]}", "}]}"); SerialPrint("i", "Loging", "json size: " + String(oneSingleJson.length())); publishChartMqtt(id, oneSingleJson); return true; } - void sendChartFileToWs(String filename, int num, size_t frameSize) { - String topic = mqttRootDevice + "/" + id; - String st = "/st/chart.json|" + topic; + //особая функция отправки графиков в веб + void publishChartToWs(String filename, int num, size_t frameSize) { + String json; + jsonWriteStr(json, "topic", mqttRootDevice + "/" + id); + jsonWriteInt(json, "maxCount", calculateMaxCount()); + + String st = "/st/chart.json|"; if (num == -1) { standWebSocket.broadcastTXT(st); } else { @@ -270,7 +271,7 @@ class Loging : public IoTItem { countRead = file.read(payload, sizeof(payload)); } file.close(); - String end = "/end/chart.json|" + topic; + String end = "/end/chart.json|" + json; if (num == -1) { standWebSocket.broadcastTXT(end); } else { @@ -278,6 +279,20 @@ class Loging : public IoTItem { } } + void clearValue() { + String topic = mqttRootDevice + "/" + id; + String json = "{\"maxCount\":0,\"topic\":\"" + topic + "\",\"status\":[]}"; + String pk = "/string/chart.json|" + json; + standWebSocket.broadcastTXT(pk); + } + + void publishChartToWsSinglePoint(String value) { + String topic = mqttRootDevice + "/" + id; + String json = "{\"maxCount\":" + String(calculateMaxCount()) + ",\"topic\":\"" + topic + "\",\"status\":[{\"x\":" + String(unixTime) + ",\"y1\":" + value + "}]}"; + String pk = "/string/chart.json|" + json; + standWebSocket.broadcastTXT(pk); + } + void setPublishDestination(int publishType, int wsNum = -1) { _publishType = publishType; _wsNum = wsNum; @@ -305,22 +320,12 @@ class Loging : public IoTItem { if (userDate == currentDate) { // generateEvent(_id, value); // publishStatusMqtt(_id, value); - // String json = createSingleJson(_id, value); - // publishChartWs(-1, json); + + publishChartToWsSinglePoint(value); // SerialPrint("i", "Sensor " + consoleInfo, "'" + _id + "' data: " + value + "'"); } } - 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\"}"; - } - //просто максимальное количество точек int calculateMaxCount() { return 86400; @@ -362,7 +367,6 @@ class Date : public IoTItem { //отправка данных при изменении даты for (std::list::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) { if ((*it)->getSubtype() == "Loging") { - //отправляем только свои данные if ((*it)->getID() == selectToMarker(id, "-")) { (*it)->setPublishDestination(TO_MQTT_WS); (*it)->clearValue(); diff --git a/src/modules/virtual/Logging/modinfo.json b/src/modules/virtual/Logging/modinfo.json index 2d3e0d1d..42f2e768 100644 --- a/src/modules/virtual/Logging/modinfo.json +++ b/src/modules/virtual/Logging/modinfo.json @@ -9,11 +9,10 @@ "widget": "chart2", "page": "Графики", "descr": "Температура", + "num": 1, "int": 5, "logid": "t", - "num": 1, - "points": 300, - "keepdays": 2 + "points": 300 } ], "about": { @@ -25,12 +24,11 @@ "moduleVersion": "3.0", "usedRam": 15, "title": "Логирование в график", - "moduleDesc": "Расширение позволяющее логировать любую величину в график. Графики доступны в мобильном приложении и в веб интерфейсе. Данные графиков хранятся в встроенной памяти esp. График отображает период времени выбранный пользователем. В окне ввода даты нужно выбрать день, историю которого вы хотите посмотреть", + "moduleDesc": "Расширение позволяющее логировать любую величину в график. Графики доступны в мобильном приложении и в веб интерфейсе. Данные графиков хранятся в встроенной памяти esp. В окне ввода даты нужно выбрать день, историю которого вы хотите посмотреть. Старые файлы будут удаляться автоматически после того как объем оставшейся flesh памяти устройства будет менее 20 процентов", "propInfo": { "int": "Интервал логирования в мнутах, рекомендуется для esp8266 использоать интервал не менее 5-ти минут", "logid": "ID величины которую будем логировать", - "points": "Максимальное количество точек в одном файле, может быть не более 300. Не рекомендуется менять этот параметр", - "keepdays": "Количество дней за которое необходимо хранить историю. Данные старее будут удалены автоматически" + "points": "Максимальное количество точек в одном файле, может быть не более 300. Не рекомендуется менять этот параметр" } }, "defActive": true,