From 1f9f746149b3ed0d76e0cf9756a21644b0774093 Mon Sep 17 00:00:00 2001 From: Dmitry Borisenko <49808844+DmitryBorisenko33@users.noreply.github.com> Date: Sat, 13 Aug 2022 12:18:58 +0200 Subject: [PATCH] =?UTF-8?q?=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D1=8C=20=D0=BB?= =?UTF-8?q?=D0=BE=D0=B3=D0=B3=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F,=20=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data_svelte/items.json | 149 +++++++++++------------ myProfile.json | 8 +- platformio.ini | 4 +- src/Main.cpp | 32 ++--- src/classes/IoTItem.cpp | 4 +- src/modules/API.cpp | 54 ++++---- src/modules/virtual/Logging/Logging.cpp | 0 src/modules/virtual/Logging/Loging.cpp | 35 ++++++ src/modules/virtual/Logging/modinfo.json | 35 ++++++ 9 files changed, 195 insertions(+), 126 deletions(-) delete mode 100644 src/modules/virtual/Logging/Logging.cpp create mode 100644 src/modules/virtual/Logging/Loging.cpp create mode 100644 src/modules/virtual/Logging/modinfo.json diff --git a/data_svelte/items.json b/data_svelte/items.json index 814fbaaf..22b90cb4 100644 --- a/data_svelte/items.json +++ b/data_svelte/items.json @@ -7,7 +7,19 @@ "header": "Виртуальные элементы" }, { - "name": "1. Таймер", + "name": "1. Логгирование в график", + "type": "Writing", + "subtype": "Loging", + "id": "log", + "widget": "chart1", + "page": "Графики", + "descr": "График", + "int": 60, + "logid": "tmp", + "num": 1 + }, + { + "name": "2. Таймер", "type": "Writing", "subtype": "Timer", "id": "timer", @@ -19,10 +31,10 @@ "ticker": 0, "repeat": 0, "needSave": 0, - "num": 1 + "num": 2 }, { - "name": "2. Окно ввода цифры (переменная)", + "name": "3. Окно ввода цифры (переменная)", "type": "Reading", "subtype": "Variable", "id": "value", @@ -30,11 +42,11 @@ "page": "Ввод", "descr": "Введите цифру", "int": "0", - "val": "0", - "num": 2 + "val": "0.0", + "num": 3 }, { - "name": "3. Окно ввода времени", + "name": "4. Окно ввода времени", "type": "Reading", "subtype": "Variable", "id": "time", @@ -42,11 +54,11 @@ "page": "Ввод", "descr": "Введите время", "int": "0", - "val": "0", - "num": 3 + "val": "02:00", + "num": 4 }, { - "name": "4. Окно ввода даты", + "name": "5. Окно ввода даты", "type": "Reading", "subtype": "Variable", "id": "time", @@ -54,11 +66,11 @@ "page": "Ввод", "descr": "Введите дату", "int": "0", - "val": "0", - "num": 4 + "val": "24.05.2022", + "num": 5 }, { - "name": "5. Виртуальная кнопка", + "name": "6. Виртуальная кнопка", "type": "Reading", "subtype": "VButton", "id": "vbtn", @@ -67,13 +79,13 @@ "descr": "Кнопка", "int": "0", "val": "0", - "num": 5 + "num": 6 }, { "header": "Сенсоры" }, { - "name": "6. Cенсор температуры AHT20", + "name": "7. Cенсор температуры AHT20", "type": "Reading", "subtype": "Aht20t", "id": "Temp20", @@ -83,10 +95,10 @@ "int": 15, "addr": "0x38", "round": 1, - "num": 6 + "num": 7 }, { - "name": "7. Cенсор влажности AHT20", + "name": "8. Cенсор влажности AHT20", "type": "Reading", "subtype": "Aht20h", "id": "Hum20", @@ -96,10 +108,10 @@ "int": 15, "addr": "0x38", "round": 1, - "num": 7 + "num": 8 }, { - "name": "8. Аналоговый сенсор", + "name": "9. Аналоговый сенсор", "type": "Reading", "subtype": "AnalogAdc", "id": "t", @@ -113,10 +125,10 @@ "pin": 0, "int": 15, "avgSteps": 1, - "num": 8 + "num": 9 }, { - "name": "9. Cенсор температуры Bme280", + "name": "10. Cенсор температуры Bme280", "type": "Reading", "subtype": "Bme280t", "id": "tmp3", @@ -126,10 +138,10 @@ "int": 15, "addr": "0x77", "round": 1, - "num": 9 + "num": 10 }, { - "name": "10. Cенсор давления Bme280", + "name": "11. Cенсор давления Bme280", "type": "Reading", "subtype": "Bme280p", "id": "Press3", @@ -139,10 +151,10 @@ "int": 15, "addr": "0x77", "round": 1, - "num": 10 + "num": 11 }, { - "name": "11. Cенсор влажности Bme280", + "name": "12. Cенсор влажности Bme280", "type": "Reading", "subtype": "Bme280h", "id": "Hum3", @@ -152,10 +164,10 @@ "int": 15, "addr": "0x77", "round": 1, - "num": 11 + "num": 12 }, { - "name": "12. Cенсор температуры Bmp280", + "name": "13. Cенсор температуры Bmp280", "type": "Reading", "subtype": "Bmp280t", "id": "tmp3", @@ -165,10 +177,10 @@ "int": 15, "addr": "0x77", "round": 1, - "num": 12 + "num": 13 }, { - "name": "13. Cенсор давления Bmp280", + "name": "14. Cенсор давления Bmp280", "type": "Reading", "subtype": "Bmp280p", "id": "Press3", @@ -178,10 +190,10 @@ "int": 15, "addr": "0x77", "round": 1, - "num": 13 + "num": 14 }, { - "name": "14. Cенсор температуры dht11", + "name": "15. Cенсор температуры dht11", "type": "Reading", "subtype": "Dht1122t", "id": "tmp3", @@ -191,10 +203,10 @@ "int": 15, "pin": 0, "senstype": "dht11", - "num": 14 + "num": 15 }, { - "name": "15. Cенсор влажности dht11", + "name": "16. Cенсор влажности dht11", "type": "Reading", "subtype": "Dht1122h", "id": "Hum3", @@ -204,10 +216,10 @@ "int": 15, "pin": 0, "senstype": "dht11", - "num": 15 + "num": 16 }, { - "name": "16. Cенсор температуры ds18b20", + "name": "17. Cенсор температуры ds18b20", "type": "Reading", "subtype": "Ds18b20", "id": "dstmp", @@ -219,10 +231,10 @@ "index": 0, "addr": "", "round": 1, - "num": 16 + "num": 17 }, { - "name": "17. Cенсор температуры GY21", + "name": "18. Cенсор температуры GY21", "type": "Reading", "subtype": "GY21t", "id": "tmp4", @@ -231,10 +243,10 @@ "descr": "Температура", "round": 1, "int": 15, - "num": 17 + "num": 18 }, { - "name": "18. Cенсор влажности GY21", + "name": "19. Cенсор влажности GY21", "type": "Reading", "subtype": "GY21h", "id": "Hum4", @@ -243,10 +255,10 @@ "descr": "Влажность", "round": 1, "int": 15, - "num": 18 + "num": 19 }, { - "name": "19. Cенсор температуры HDC1080", + "name": "20. Cенсор температуры HDC1080", "type": "Reading", "subtype": "Hdc1080t", "id": "Temp1080", @@ -256,10 +268,10 @@ "int": 15, "addr": "0x40", "round": 1, - "num": 19 + "num": 20 }, { - "name": "20. Cенсор влажности HDC1080", + "name": "21. Cенсор влажности HDC1080", "type": "Reading", "subtype": "Hdc1080h", "id": "Hum1080", @@ -269,10 +281,10 @@ "int": 15, "addr": "0x40", "round": 1, - "num": 20 + "num": 21 }, { - "name": "21. Cенсор температуры MAX6675", + "name": "22. Cенсор температуры MAX6675", "type": "Reading", "subtype": "Max6675t", "id": "maxtmp", @@ -283,11 +295,11 @@ "DO": 12, "CS": 13, "CLK": 14, - "num": 21 + "num": 22 }, { - "name": "22. Сканер кнопок 433 MHz", - "num": 22, + "name": "23. Сканер кнопок 433 MHz", + "num": 23, "type": "Reading", "subtype": "RCswitch", "id": "rsw", @@ -296,7 +308,7 @@ "pinTx": 12 }, { - "name": "23. Cенсор температуры Sht20", + "name": "24. Cенсор температуры Sht20", "type": "Reading", "subtype": "Sht20t", "id": "tmp2", @@ -305,10 +317,10 @@ "descr": "Температура", "int": 15, "round": 1, - "num": 23 + "num": 24 }, { - "name": "24. Cенсор влажности Sht20", + "name": "25. Cенсор влажности Sht20", "type": "Reading", "subtype": "Sht20h", "id": "Hum2", @@ -317,10 +329,10 @@ "descr": "Влажность", "int": 15, "round": 1, - "num": 24 + "num": 25 }, { - "name": "25. Cенсор температуры Sht30", + "name": "26. Cенсор температуры Sht30", "type": "Reading", "subtype": "Sht30t", "id": "tmp30", @@ -329,10 +341,10 @@ "descr": "SHT30 Температура", "int": 15, "round": 1, - "num": 25 + "num": 26 }, { - "name": "26. Cенсор влажности Sht30", + "name": "27. Cенсор влажности Sht30", "type": "Reading", "subtype": "Sht30h", "id": "Hum30", @@ -341,11 +353,11 @@ "descr": "SHT30 Влажность", "int": 15, "round": 1, - "num": 26 + "num": 27 }, { - "name": "27. Сонар HC-SR04", - "num": 27, + "name": "28. Сонар HC-SR04", + "num": 28, "type": "Reading", "subtype": "Sonar", "id": "sonar", @@ -360,7 +372,7 @@ "header": "Исполнительные устройства" }, { - "name": "28. Кнопка подключенная к пину", + "name": "29. Кнопка подключенная к пину", "type": "Writing", "subtype": "ButtonIn", "id": "btn", @@ -373,10 +385,10 @@ "pinMode": "INPUT", "debounceDelay": 50, "fixState": 1, - "num": 28 + "num": 29 }, { - "name": "29. Кнопка управляющая пином (Реле)", + "name": "30. Кнопка управляющая пином (Реле)", "type": "Writing", "subtype": "ButtonOut", "id": "btn", @@ -386,23 +398,6 @@ "int": 0, "inv": 0, "pin": 2, - "num": 29 - }, - { - "name": "30. Поддержка DS1302(1), DS1307(2), DS3231(3), RX8025(4)", - "type": "Reading", - "subtype": "IarduinoRTC", - "id": "RTC", - "widget": "", - "page": "", - "descr": "", - "int": "1", - "chipNum": 1, - "rst": 16, - "clk": 5, - "dat": 4, - "defFormat": "d-m-Y", - "ticker": 0, "num": 30 }, { diff --git a/myProfile.json b/myProfile.json index f115b05a..13041390 100644 --- a/myProfile.json +++ b/myProfile.json @@ -27,6 +27,10 @@ }, "modules": { "Виртуальные элементы": [ + { + "path": "src\\modules\\virtual\\Logging", + "active": true + }, { "path": "src\\modules\\virtual\\Timer", "active": true @@ -127,10 +131,6 @@ "path": "src\\modules\\exec\\EspCam", "active": false }, - { - "path": "src\\modules\\exec\\IarduinoRTC", - "active": true - }, { "path": "src\\modules\\exec\\IoTServo", "active": true diff --git a/platformio.ini b/platformio.ini index e4a9c4b1..80436a63 100644 --- a/platformio.ini +++ b/platformio.ini @@ -65,7 +65,9 @@ lib_deps = adafruit/Adafruit BusIO @ ^1.13.0 dfrobot/DFRobotDFPlayerMini @ ^1.0.5 marcoschwartz/LiquidCrystal_I2C@^1.1.4 + build_src_filter = + + + + + @@ -84,7 +86,6 @@ build_src_filter = + + + - + + + + @@ -110,6 +111,7 @@ lib_deps = adafruit/Adafruit BusIO @ ^1.13.0 dfrobot/DFRobotDFPlayerMini @ ^1.0.5 marcoschwartz/LiquidCrystal_I2C@^1.1.4 + build_src_filter = + + diff --git a/src/Main.cpp b/src/Main.cpp index a93353a6..19e5ceda 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -132,20 +132,20 @@ void loop() { handleEvent(); // сохраняем значения IoTItems в файл каждую секунду, если были изменения (установлены маркеры на сохранение) - currentMillis = millis(); - if (currentMillis - prevMillis >= 1000) { - prevMillis = millis(); - volStrForSave = ""; - for (std::list::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) { - if ((*it)->needSave) { - (*it)->needSave = false; - volStrForSave = volStrForSave + (*it)->getID() + "=" + (*it)->getValue() + ";"; - } - } - - if (volStrForSave != "") { - Serial.print("volStrForSave: "); - Serial.println(volStrForSave.c_str()); - } - } + // currentMillis = millis(); + // if (currentMillis - prevMillis >= 1000) { + // prevMillis = millis(); + // volStrForSave = ""; + // for (std::list::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) { + // if ((*it)->needSave) { + // (*it)->needSave = false; + // volStrForSave = volStrForSave + (*it)->getID() + "=" + (*it)->getValue() + ";"; + // } + // } + // + // if (volStrForSave != "") { + // Serial.print("volStrForSave: "); + // Serial.println(volStrForSave.c_str()); + // } + //} } diff --git a/src/classes/IoTItem.cpp b/src/classes/IoTItem.cpp index 57b4108d..3703a1ea 100644 --- a/src/classes/IoTItem.cpp +++ b/src/classes/IoTItem.cpp @@ -165,8 +165,8 @@ IoTItem* findIoTItem(String name) { return nullptr; } - -String getItemValue(String name) { // поиск плюс получение значения +// поиск плюс получение значения +String getItemValue(String name) { IoTItem* tmp = findIoTItem(name); if (tmp) return tmp->getValue(); diff --git a/src/modules/API.cpp b/src/modules/API.cpp index 0c251dcf..33431763 100644 --- a/src/modules/API.cpp +++ b/src/modules/API.cpp @@ -1,5 +1,6 @@ #include "ESPConfiguration.h" +void* getAPI_Loging(String subtype, String params); void* getAPI_Timer(String subtype, String params); void* getAPI_Variable(String subtype, String params); void* getAPI_VButton(String subtype, String params); @@ -26,30 +27,31 @@ void* getAPI_SysExt(String subtype, String params); void* getAPI_Lcd2004(String subtype, String params); void* getAPI(String subtype, String params) { - void* tmpAPI; - if ((tmpAPI = getAPI_Timer(subtype, params)) != nullptr) return tmpAPI; - if ((tmpAPI = getAPI_Variable(subtype, params)) != nullptr) return tmpAPI; - if ((tmpAPI = getAPI_VButton(subtype, params)) != nullptr) return tmpAPI; - if ((tmpAPI = getAPI_Aht20(subtype, params)) != nullptr) return tmpAPI; - if ((tmpAPI = getAPI_AnalogAdc(subtype, params)) != nullptr) return tmpAPI; - if ((tmpAPI = getAPI_Bme280(subtype, params)) != nullptr) return tmpAPI; - if ((tmpAPI = getAPI_Bmp280(subtype, params)) != nullptr) return tmpAPI; - if ((tmpAPI = getAPI_Dht1122(subtype, params)) != nullptr) return tmpAPI; - if ((tmpAPI = getAPI_Ds18b20(subtype, params)) != nullptr) return tmpAPI; - if ((tmpAPI = getAPI_GY21(subtype, params)) != nullptr) return tmpAPI; - if ((tmpAPI = getAPI_Hdc1080(subtype, params)) != nullptr) return tmpAPI; - if ((tmpAPI = getAPI_Max6675(subtype, params)) != nullptr) return tmpAPI; - if ((tmpAPI = getAPI_RCswitch(subtype, params)) != nullptr) return tmpAPI; - if ((tmpAPI = getAPI_Sht20(subtype, params)) != nullptr) return tmpAPI; - if ((tmpAPI = getAPI_Sht30(subtype, params)) != nullptr) return tmpAPI; - if ((tmpAPI = getAPI_Sonar(subtype, params)) != nullptr) return tmpAPI; - if ((tmpAPI = getAPI_ButtonIn(subtype, params)) != nullptr) return tmpAPI; - 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_Pwm8266(subtype, params)) != nullptr) return tmpAPI; - if ((tmpAPI = getAPI_SysExt(subtype, params)) != nullptr) return tmpAPI; - if ((tmpAPI = getAPI_Lcd2004(subtype, params)) != nullptr) return tmpAPI; - return nullptr; +void* tmpAPI; +if ((tmpAPI = getAPI_Loging(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_Timer(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_Variable(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_VButton(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_Aht20(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_AnalogAdc(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_Bme280(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_Bmp280(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_Dht1122(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_Ds18b20(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_GY21(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_Hdc1080(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_Max6675(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_RCswitch(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_Sht20(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_Sht30(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_Sonar(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_ButtonIn(subtype, params)) != nullptr) return tmpAPI; +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_Pwm8266(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_SysExt(subtype, params)) != nullptr) return tmpAPI; +if ((tmpAPI = getAPI_Lcd2004(subtype, params)) != nullptr) return tmpAPI; +return nullptr; } \ No newline at end of file diff --git a/src/modules/virtual/Logging/Logging.cpp b/src/modules/virtual/Logging/Logging.cpp deleted file mode 100644 index e69de29b..00000000 diff --git a/src/modules/virtual/Logging/Loging.cpp b/src/modules/virtual/Logging/Loging.cpp new file mode 100644 index 00000000..d7e68777 --- /dev/null +++ b/src/modules/virtual/Logging/Loging.cpp @@ -0,0 +1,35 @@ +#include "Global.h" +#include "classes/IoTItem.h" + +class Loging : public IoTItem { + private: + String logval; + + public: + Loging(String parameters) : IoTItem(parameters) { + jsonRead(parameters, F("logid"), logval); + } + + // void setValue(IoTValue Value) { + // value = Value; + // regEvent((String)(int)value.valD, "Loging"); + // } + + void doByInterval() { + Serial.println("logging test " + logval); + String value = getItemValue(logval); + if (value == "") { + SerialPrint("E", F("Logging"), F("no value set")); + } else { + Serial.println("value " + value); + } + } +}; + +void* getAPI_Loging(String subtype, String param) { + if (subtype == F("Loging")) { + return new Loging(param); + } else { + return nullptr; + } +} diff --git a/src/modules/virtual/Logging/modinfo.json b/src/modules/virtual/Logging/modinfo.json new file mode 100644 index 00000000..008f5a33 --- /dev/null +++ b/src/modules/virtual/Logging/modinfo.json @@ -0,0 +1,35 @@ +{ + "menuSection": "Виртуальные элементы", + "configItem": [ + { + "name": "Логгирование в график", + "type": "Writing", + "subtype": "Loging", + "id": "log", + "widget": "chart1", + "page": "Графики", + "descr": "График", + "int": 60, + "logid": "tmp", + "num": 1 + } + ], + "about": { + "authorName": "Dmitry Borisenko", + "authorContact": "https://t.me/Dmitry_Borisenko", + "authorGit": "https://github.com/DmitryBorisenko33", + "specialThanks": "", + "moduleName": "Loging", + "moduleVersion": "1.0", + "moduleDesc": "Расширение позволяющее логгировать любую величину в график", + "propInfo": { + "int": "Интервал", + "logid": "ID величины которую будем логгировать" + } + }, + "defActive": true, + "devices": { + "esp32_4mb": [], + "esp8266_4mb": [] + } +} \ No newline at end of file