From 8340ae2a0f96f154ddb87c06ac5ba1f2bc466087 Mon Sep 17 00:00:00 2001 From: Dmitry Borisenko <49808844+DmitryBorisenko33@users.noreply.github.com> Date: Sat, 10 Sep 2022 02:58:42 +0200 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=B5=20=D1=80=D0=B0=D0=B1=D0=BE=D1=87?= =?UTF-8?q?=D0=B0=D1=8F=20=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D1=8F=20-=20?= =?UTF-8?q?=D0=B2=D0=B2=D0=BE=D0=B4=20=D0=B4=D0=B0=D1=82=D1=8B=20=D0=B2=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D1=86=D0=B5=D1=81=D1=81=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data_svelte/items.json | 8 ++- data_svelte/widgets.json | 3 ++ myProfile.json | 2 +- platformio.ini | 2 +- src/EventsAndOrders.cpp | 10 +++- src/MqttClient.cpp | 1 + src/classes/IoTItem.cpp | 4 +- src/modules/API.cpp | 4 +- src/modules/virtual/Logging/Loging.cpp | 65 ++++++++++++++++++++++-- src/modules/virtual/Logging/modinfo.json | 2 +- src/utils/StringUtils.cpp | 7 +-- 11 files changed, 87 insertions(+), 21 deletions(-) diff --git a/data_svelte/items.json b/data_svelte/items.json index 33b747fa..1ee96b5b 100644 --- a/data_svelte/items.json +++ b/data_svelte/items.json @@ -455,18 +455,16 @@ "num": 34 }, { - "name": "35. PWM ESP32", + "name": "35. PWM ESP8266", "type": "Writing", - "subtype": "Pwm32", + "subtype": "Pwm8266", "id": "pwm", "widget": "range", "page": "Кнопки", "descr": "PWM", "int": 0, - "pin": 2, + "pin": 15, "freq": 5000, - "ledChannel": 2, - "PWM_resolution": 10, "val": 0, "apin": -1, "num": 35 diff --git a/data_svelte/widgets.json b/data_svelte/widgets.json index f74875a1..43238fb5 100644 --- a/data_svelte/widgets.json +++ b/data_svelte/widgets.json @@ -194,5 +194,8 @@ "widget": "anydata", "after": "Vlt", "icon": "speedometer" + }, + { + "label": "Без виджета" } ] \ No newline at end of file diff --git a/myProfile.json b/myProfile.json index f80fde33..255072e5 100644 --- a/myProfile.json +++ b/myProfile.json @@ -21,7 +21,7 @@ }, "projectProp": { "platformio": { - "default_envs": "esp32_4mb", + "default_envs": "esp8266_4mb", "data_dir": "data_svelte" } }, diff --git a/platformio.ini b/platformio.ini index 0f24d297..9ff67684 100644 --- a/platformio.ini +++ b/platformio.ini @@ -40,7 +40,7 @@ build_src_filter = ${env:esp32_4mb_fromitems.build_src_filter} [platformio] -default_envs = esp32_4mb +default_envs = esp8266_4mb data_dir = data_svelte [common_env_data] diff --git a/src/EventsAndOrders.cpp b/src/EventsAndOrders.cpp index bffbbc4c..bb6db4a9 100644 --- a/src/EventsAndOrders.cpp +++ b/src/EventsAndOrders.cpp @@ -25,10 +25,16 @@ void handleOrder() { String order = selectToMarker(orderBuf, ","); SerialPrint("i", F("ORDER"), order); + String id = selectToMarker(order, " "); + + //это модификатор для даты графика + // if (id.endsWith("-date")) { + //} + //здесь нужно перебрать все методы execute всех векторов и выполнить те id которых совпали с id события - IoTItem* item = findIoTItem(selectToMarker(order, " ")); + IoTItem* item = findIoTItem(id); if (item) { - SerialPrint("i", F("ORDER"), "order matched " + order); + SerialPrint("i", F("ORDER"), "order found " + order); String valStr = selectToMarkerLast(order, " "); item->setValue(valStr); } diff --git a/src/MqttClient.cpp b/src/MqttClient.cpp index 1741e1c3..491820ff 100644 --- a/src/MqttClient.cpp +++ b/src/MqttClient.cpp @@ -287,6 +287,7 @@ void publishWidgets() { void publishState() { String json = getParamsJson(); + SerialPrint("i", F("DATA"), json); json.replace("{", ""); json.replace("}", ""); json.replace("\"", ""); diff --git a/src/classes/IoTItem.cpp b/src/classes/IoTItem.cpp index 718afc11..2b573938 100644 --- a/src/classes/IoTItem.cpp +++ b/src/classes/IoTItem.cpp @@ -70,7 +70,7 @@ String IoTItem::getValue() { return value.valS; } -//установить +//определяем тип прилетевшей величины void IoTItem::setValue(String valStr) { if (value.isDecimal = isDigitDotCommaStr(valStr)) { value.valD = valStr.toFloat(); @@ -80,7 +80,7 @@ void IoTItem::setValue(String valStr) { setValue(value); } -//установить +// void IoTItem::setValue(IoTValue Value) { value = Value; if (value.isDecimal) { diff --git a/src/modules/API.cpp b/src/modules/API.cpp index b2f9af1f..9ee02105 100644 --- a/src/modules/API.cpp +++ b/src/modules/API.cpp @@ -22,7 +22,7 @@ void* getAPI_ButtonOut(String subtype, String params); void* getAPI_IoTServo(String subtype, String params); void* getAPI_Mcp23017(String subtype, String params); void* getAPI_Mp3(String subtype, String params); -void* getAPI_Pwm32(String subtype, String params); +void* getAPI_Pwm8266(String subtype, String params); void* getAPI_TelegramLT(String subtype, String params); void* getAPI_Lcd2004(String subtype, String params); @@ -50,7 +50,7 @@ if ((tmpAPI = getAPI_ButtonOut(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_IoTServo(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Mcp23017(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Mp3(subtype, params)) != nullptr) return tmpAPI; -if ((tmpAPI = getAPI_Pwm32(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_Pwm8266(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_TelegramLT(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Lcd2004(subtype, params)) != nullptr) return tmpAPI; return nullptr; diff --git a/src/modules/virtual/Logging/Loging.cpp b/src/modules/virtual/Logging/Loging.cpp index 2e1457a8..5cea15d7 100644 --- a/src/modules/virtual/Logging/Loging.cpp +++ b/src/modules/virtual/Logging/Loging.cpp @@ -1,18 +1,25 @@ #include "Global.h" #include "classes/IoTItem.h" +#include "ESPConfiguration.h" #include "NTP.h" +void *getAPI_Date(String params); + +String date; class Loging : public IoTItem { private: String logid; String id; String filesList = ""; + bool firstTime = true; + int points; int keepdays; + IoTItem *dateIoTItem; + unsigned long interval; - bool firstTime = true; public: Loging(String parameters) : IoTItem(parameters) { @@ -26,6 +33,10 @@ class Loging : public IoTItem { jsonRead(parameters, F("int"), interval); interval = interval * 1000 * 60; //приводим к милисекундам jsonRead(parameters, F("keepdays"), keepdays); + + //создадим экземпляр класса даты + dateIoTItem = (IoTItem *)getAPI_Date("{\"id\": \"" + id + "-date\"}"); + IoTItems.push_back(dateIoTItem); } String getValue() { @@ -46,13 +57,21 @@ class Loging : public IoTItem { void regEvent(String value, String consoleInfo = "") { generateEvent(_id, value); publishStatusMqtt(_id, value); - String topic = mqttRootDevice + "/" + _id; - String json = "{\"topic\":\"" + topic + "\",\"status\":[{\"x\":" + String(unixTime) + ",\"y1\":" + value + "}]}"; + String json = createSingleJson(_id, value); publishStatusWsJson(json); 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 + "}]}"; + } + void doByInterval() { + if (firstTime) { + firstTime = false; + } + //если объект логгирования не был создан if (!isItemExist(logid)) { SerialPrint("E", F("Loging"), "'" + id + "' loging object not exist"); @@ -169,7 +188,13 @@ class Loging : public IoTItem { SerialPrint("i", F("Loging"), "file '" + buf + "' too old, deleted"); removeFile(buf); } else { - createJson(buf, i, mqtt); + unsigned long reqUnixTime = strDateToUnix(date); + if (fileUnixTime > reqUnixTime && fileUnixTime < reqUnixTime + 86400) { + createJson(buf, i, mqtt); + SerialPrint("i", F("Loging"), "file '" + buf + "' sent, user requested " + date); + } else { + SerialPrint("i", F("Loging"), "file '" + buf + "' skipped, user requested " + date); + } } SerialPrint("i", F("Loging"), String(f) + ") path: " + buf + ", lines №: " + String(i) + ", created: " + getDateTimeDotFormatedFromUnix(fileUnixTime)); @@ -304,3 +329,35 @@ void *getAPI_Loging(String subtype, String param) { return nullptr; } } + +class Date : public IoTItem { + private: + public: + String id; + Date(String parameters) : IoTItem(parameters) { + jsonRead(parameters, F("id"), id); + value.isDecimal = false; + } + + void setValue(String valStr) { + value.valS = valStr; + date = valStr; + setValue(value); + } + + void setValue(IoTValue Value) { + value = Value; + regEvent(value.valS, ""); + for (std::list::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) { + if ((*it)->getSubtype() == "Loging") { + (*it)->sendChart(true); + } + } + } + + void doByInterval() {} +}; + +void *getAPI_Date(String param) { + return new Date(param); +} diff --git a/src/modules/virtual/Logging/modinfo.json b/src/modules/virtual/Logging/modinfo.json index 1cde9323..5f7c7627 100644 --- a/src/modules/virtual/Logging/modinfo.json +++ b/src/modules/virtual/Logging/modinfo.json @@ -6,7 +6,7 @@ "type": "Writing", "subtype": "Loging", "id": "log", - "widget": "chart1", + "widget": "chart2", "page": "Графики", "descr": "Температура", "int": 1, diff --git a/src/utils/StringUtils.cpp b/src/utils/StringUtils.cpp index 16717fc2..8d84ea64 100644 --- a/src/utils/StringUtils.cpp +++ b/src/utils/StringUtils.cpp @@ -159,7 +159,8 @@ boolean isDigitStr(const String& str) { boolean isDigitDotCommaStr(const String& str) { for (size_t i = 0; i < str.length(); i++) { char latter = str.charAt(i); - if (!isDigit(latter) && latter != '.' && latter != '-') { + //если символ не цифра и не точка и не тире + if (!isDigit(latter) && latter != '.') { return false; } } @@ -186,9 +187,9 @@ String uint64ToString(uint64_t input) { input /= base; if (c < 10) - c +='0'; + c += '0'; else - c += 'A' - 10; + c += 'A' - 10; result = c + result; } while (input); return result;