From e688c95c5939f399293498cb00592d2344b26bdb Mon Sep 17 00:00:00 2001 From: Dmitry Borisenko <49808844+DmitryBorisenko33@users.noreply.github.com> Date: Tue, 27 Sep 2022 00:52:53 +0200 Subject: [PATCH] =?UTF-8?q?pzem=20-=20=D1=87=D1=82=D0=B5=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20=D0=BD=D0=B0=D0=BF=D1=80=D1=8F=D0=B6=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data_svelte/items.json | 133 +++++++++++++++++----- data_svelte/widgets.json | 1 + myProfile.json | 4 +- platformio.ini | 3 + src/modules/API.cpp | 4 + src/modules/sensors/Pzem004t/Pzem004t.cpp | 14 ++- src/modules/sensors/Pzem004t/modinfo.json | 19 ++-- src/modules/sensors/SoftUart/SoftUart.cpp | 7 +- src/modules/sensors/SoftUart/SoftUart.h | 9 ++ src/modules/sensors/SoftUart/modinfo.json | 9 +- 10 files changed, 150 insertions(+), 53 deletions(-) create mode 100644 src/modules/sensors/SoftUart/SoftUart.h diff --git a/data_svelte/items.json b/data_svelte/items.json index 42bbc731..ed0f650a 100644 --- a/data_svelte/items.json +++ b/data_svelte/items.json @@ -311,8 +311,68 @@ "num": 23 }, { - "name": "24. Сканер кнопок 433 MHz", - "num": 24, + "name": "24. PZEM 004t Напряжение", + "type": "Reading", + "subtype": "Pzem004v", + "id": "V", + "widget": "anydataVlt", + "page": "Сенсоры", + "descr": "Напряжение", + "int": 15, + "addr": "0xF8", + "num": 24 + }, + { + "name": "25. PZEM 004t Сила тока", + "type": "Reading", + "subtype": "Pzem004a", + "id": "A", + "widget": "anydataAmp", + "page": "Сенсоры", + "descr": "Сила тока", + "int": 15, + "addr": "0xF8", + "num": 25 + }, + { + "name": "26. PZEM 004t Мощность", + "type": "Reading", + "subtype": "Pzem004w", + "id": "A", + "widget": "anydataWt", + "page": "Сенсоры", + "descr": "Мощность", + "int": 15, + "addr": "0xF8", + "num": 26 + }, + { + "name": "27. PZEM 004t Энергия", + "type": "Reading", + "subtype": "Pzem004wh", + "id": "Wh", + "widget": "anydataWth", + "page": "Сенсоры", + "descr": "Энергия", + "int": 15, + "addr": "0xF8", + "num": 27 + }, + { + "name": "28. PZEM 004t Частота", + "type": "Reading", + "subtype": "Pzem004hz", + "id": "Hz", + "widget": "anydataHtz", + "page": "Сенсоры", + "descr": "Энергия", + "int": 15, + "addr": "0x77", + "num": 28 + }, + { + "name": "29. Сканер кнопок 433 MHz", + "num": 29, "type": "Reading", "subtype": "RCswitch", "id": "rsw", @@ -321,7 +381,7 @@ "pinTx": 12 }, { - "name": "25. Sht20 Температура", + "name": "30. Sht20 Температура", "type": "Reading", "subtype": "Sht20t", "id": "tmp2", @@ -330,10 +390,10 @@ "descr": "Температура", "int": 15, "round": 1, - "num": 25 + "num": 30 }, { - "name": "26. Sht20 Влажность", + "name": "31. Sht20 Влажность", "type": "Reading", "subtype": "Sht20h", "id": "Hum2", @@ -342,10 +402,10 @@ "descr": "Влажность", "int": 15, "round": 1, - "num": 26 + "num": 31 }, { - "name": "27. Sht30 Температура", + "name": "32. Sht30 Температура", "type": "Reading", "subtype": "Sht30t", "id": "tmp30", @@ -354,10 +414,10 @@ "descr": "SHT30 Температура", "int": 15, "round": 1, - "num": 27 + "num": 32 }, { - "name": "28. Sht30 Влажность", + "name": "33. Sht30 Влажность", "type": "Reading", "subtype": "Sht30h", "id": "Hum30", @@ -366,11 +426,24 @@ "descr": "SHT30 Влажность", "int": 15, "round": 1, - "num": 28 + "num": 33 }, { - "name": "29. HC-SR04 Ультразвуковой дальномер", - "num": 29, + "name": "34. UART", + "type": "Reading", + "subtype": "SoftUART", + "page": "", + "descr": "", + "widget": "nil", + "id": "u", + "tx": 15, + "rx": 16, + "speed": 9600, + "num": 34 + }, + { + "name": "35. HC-SR04 Ультразвуковой дальномер", + "num": 35, "type": "Reading", "subtype": "Sonar", "id": "sonar", @@ -385,7 +458,7 @@ "header": "Исполнительные устройства" }, { - "name": "30. Кнопка подключенная к пину", + "name": "36. Кнопка подключенная к пину", "type": "Writing", "subtype": "ButtonIn", "id": "btn", @@ -398,10 +471,10 @@ "pinMode": "INPUT", "debounceDelay": 50, "fixState": 0, - "num": 30 + "num": 36 }, { - "name": "31. Управление пином", + "name": "37. Управление пином", "type": "Writing", "subtype": "ButtonOut", "id": "btn", @@ -411,10 +484,10 @@ "int": 0, "inv": 0, "pin": 2, - "num": 31 + "num": 37 }, { - "name": "32. Сервопривод", + "name": "38. Сервопривод", "type": "Writing", "subtype": "IoTServo", "id": "servo", @@ -425,10 +498,10 @@ "pin": 12, "apin": -1, "amap": "0, 4096, 0, 180", - "num": 32 + "num": 38 }, { - "name": "33. Расширитель портов Mcp23017", + "name": "39. Расширитель портов Mcp23017", "type": "Reading", "subtype": "Mcp23017", "id": "Mcp", @@ -438,10 +511,10 @@ "int": "0", "addr": "0x20", "index": 1, - "num": 33 + "num": 39 }, { - "name": "34. MP3 плеер", + "name": "40. MP3 плеер", "type": "Reading", "subtype": "Mp3", "id": "mp3", @@ -451,10 +524,10 @@ "int": 1, "pins": "14,12", "volume": 20, - "num": 34 + "num": 40 }, { - "name": "35. PWM ESP8266", + "name": "41. PWM ESP8266", "type": "Writing", "subtype": "Pwm8266", "id": "pwm", @@ -466,10 +539,10 @@ "freq": 5000, "val": 0, "apin": -1, - "num": 35 + "num": 41 }, { - "name": "36. Телеграм-Лайт", + "name": "42. Телеграм-Лайт", "type": "Writing", "subtype": "TelegramLT", "id": "tg", @@ -478,13 +551,13 @@ "descr": "", "token": "", "chatID": "", - "num": 36 + "num": 42 }, { "header": "Экраны" }, { - "name": "37. LCD экран 2004", + "name": "43. LCD экран 2004", "type": "Reading", "subtype": "Lcd2004", "id": "Lcd", @@ -496,10 +569,10 @@ "size": "20,4", "coord": "0,0", "id2show": "id датчика", - "num": 37 + "num": 43 }, { - "name": "38. LCD экран 1602", + "name": "44. LCD экран 1602", "type": "Reading", "subtype": "Lcd2004", "id": "Lcd", @@ -511,6 +584,6 @@ "size": "16,2", "coord": "0,0", "id2show": "id датчика", - "num": 38 + "num": 44 } ] \ No newline at end of file diff --git a/data_svelte/widgets.json b/data_svelte/widgets.json index 5b852c3c..9480d4a2 100644 --- a/data_svelte/widgets.json +++ b/data_svelte/widgets.json @@ -217,6 +217,7 @@ "icon": "speedometer" }, { + "name": "nil", "label": "Без виджета" } ] \ No newline at end of file diff --git a/myProfile.json b/myProfile.json index f8fb97a1..a50d1c86 100644 --- a/myProfile.json +++ b/myProfile.json @@ -99,7 +99,7 @@ }, { "path": "src\\modules\\sensors\\Pzem004t", - "active": false + "active": true }, { "path": "src\\modules\\sensors\\RCswitch", @@ -119,7 +119,7 @@ }, { "path": "src\\modules\\sensors\\SoftUart", - "active": false + "active": true }, { "path": "src\\modules\\sensors\\Sonar", diff --git a/platformio.ini b/platformio.ini index ef5b920a..b19a3d3d 100644 --- a/platformio.ini +++ b/platformio.ini @@ -64,6 +64,7 @@ lib_deps = rc-switch @ ^2.6.4 robtillaart/SHT2x@^0.1.1 WEMOS SHT3x@1.0.0 + plerup/espsoftwareserial adafruit/Adafruit MCP23017 Arduino Library@^2.0.2 adafruit/Adafruit BusIO @ ^1.13.0 dfrobot/DFRobotDFPlayerMini @ ^1.0.5 @@ -82,9 +83,11 @@ build_src_filter = + + + + + + + + + + + + + diff --git a/src/modules/API.cpp b/src/modules/API.cpp index 9ee02105..f1ce947d 100644 --- a/src/modules/API.cpp +++ b/src/modules/API.cpp @@ -13,9 +13,11 @@ void* getAPI_Ds18b20(String subtype, String params); void* getAPI_GY21(String subtype, String params); void* getAPI_Hdc1080(String subtype, String params); void* getAPI_Max6675(String subtype, String params); +void* getAPI_Pzem004(String subtype, String params); void* getAPI_RCswitch(String subtype, String params); void* getAPI_Sht20(String subtype, String params); void* getAPI_Sht30(String subtype, String params); +void* getAPI_SoftUART(String subtype, String params); void* getAPI_Sonar(String subtype, String params); void* getAPI_ButtonIn(String subtype, String params); void* getAPI_ButtonOut(String subtype, String params); @@ -41,9 +43,11 @@ 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_Pzem004(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_SoftUART(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; diff --git a/src/modules/sensors/Pzem004t/Pzem004t.cpp b/src/modules/sensors/Pzem004t/Pzem004t.cpp index 9eb06d50..950d6d1f 100644 --- a/src/modules/sensors/Pzem004t/Pzem004t.cpp +++ b/src/modules/sensors/Pzem004t/Pzem004t.cpp @@ -3,7 +3,7 @@ #include "classes/IoTItem.h" #include "PZEMSensor.h" -//#include "SoftUART.h" +#include "modules/sensors/SoftUart/SoftUart.h" PZEMSensor* pzem; @@ -14,11 +14,21 @@ class Pzem004v : public IoTItem { public: Pzem004v(String parameters) : IoTItem(parameters) { addr = jsonReadStr(parameters, "addr"); - // pzem = new PZEMSensor(myUART, hexStringToUint8(addr)); + pzem = new PZEMSensor(myUART, hexStringToUint8(addr)); + } + + void doByInterval() { + value.valD = pzem->values()->voltage; + regEvent(value.valD, "Pzem Voltage"); } ~Pzem004v(){}; }; void* getAPI_Pzem004(String subtype, String param) { + if (subtype == F("Pzem004v")) { + return new Pzem004v(param); + } else { + return nullptr; + } } diff --git a/src/modules/sensors/Pzem004t/modinfo.json b/src/modules/sensors/Pzem004t/modinfo.json index 1baf3a8c..f11d346d 100644 --- a/src/modules/sensors/Pzem004t/modinfo.json +++ b/src/modules/sensors/Pzem004t/modinfo.json @@ -10,8 +10,7 @@ "page": "Сенсоры", "descr": "Напряжение", "int": 15, - "addr": "0x77", - "round": 1 + "addr": "0xF8" }, { "name": "PZEM 004t Сила тока", @@ -22,8 +21,7 @@ "page": "Сенсоры", "descr": "Сила тока", "int": 15, - "addr": "0x77", - "round": 1 + "addr": "0xF8" }, { "name": "PZEM 004t Мощность", @@ -34,8 +32,7 @@ "page": "Сенсоры", "descr": "Мощность", "int": 15, - "addr": "0x77", - "round": 1 + "addr": "0xF8" }, { "name": "PZEM 004t Энергия", @@ -46,8 +43,7 @@ "page": "Сенсоры", "descr": "Энергия", "int": 15, - "addr": "0x77", - "round": 1 + "addr": "0xF8" }, { "name": "PZEM 004t Частота", @@ -58,8 +54,7 @@ "page": "Сенсоры", "descr": "Энергия", "int": 15, - "addr": "0x77", - "round": 1 + "addr": "0x77" } ], "about": { @@ -67,7 +62,7 @@ "authorContact": "https://t.me/Dmitry_Borisenko", "authorGit": "https://github.com/DmitryBorisenko33", "specialThanks": "Serghei Crasnicov @Serghei63", - "moduleName": "Bme280", + "moduleName": "Pzem004", "moduleVersion": "1.0", "usedRam": 15, "subTypes": [ @@ -84,7 +79,7 @@ "int": "Количество секунд между опросами датчика" } }, - "defActive": false, + "defActive": true, "devices": { "esp32_4mb": [], "esp8266_4mb": [] diff --git a/src/modules/sensors/SoftUart/SoftUart.cpp b/src/modules/sensors/SoftUart/SoftUart.cpp index eb9b50df..372a2a2c 100644 --- a/src/modules/sensors/SoftUart/SoftUart.cpp +++ b/src/modules/sensors/SoftUart/SoftUart.cpp @@ -2,7 +2,8 @@ #include "Global.h" #include "classes/IoTItem.h" #include -//#include "SoftUART.h" + +#include "modules/sensors/SoftUart/SoftUart.h" #ifdef ESP8266 SoftwareSerial* myUART = nullptr; @@ -14,6 +15,7 @@ class SoftUART : public IoTItem { private: int tx; int rx; + int speed; public: SoftUART(String parameters) : IoTItem(parameters) { @@ -36,9 +38,6 @@ class SoftUART : public IoTItem { void uartHandle() { if (myUART) { - if (!jsonReadBool(configSetupJson, "uart")) { - return; - } static String incStr; if (myUART->available()) { char inc; diff --git a/src/modules/sensors/SoftUart/SoftUart.h b/src/modules/sensors/SoftUart/SoftUart.h new file mode 100644 index 00000000..b64ffa23 --- /dev/null +++ b/src/modules/sensors/SoftUart/SoftUart.h @@ -0,0 +1,9 @@ +#pragma once + +#ifdef ESP8266 +#include +extern SoftwareSerial* myUART; +#else +#include +extern HardwareSerial* myUART; +#endif \ No newline at end of file diff --git a/src/modules/sensors/SoftUart/modinfo.json b/src/modules/sensors/SoftUart/modinfo.json index 36ab564d..692574a7 100644 --- a/src/modules/sensors/SoftUart/modinfo.json +++ b/src/modules/sensors/SoftUart/modinfo.json @@ -5,6 +5,9 @@ "name": "UART", "type": "Reading", "subtype": "SoftUART", + "page": "", + "descr": "", + "widget": "nil", "id": "u", "tx": 15, "rx": 16, @@ -16,21 +19,21 @@ "authorContact": "https://t.me/Dmitry_Borisenko", "authorGit": "https://github.com/DmitryBorisenko33", "specialThanks": "Serghei Crasnicov @Serghei63", - "moduleName": "Bme280", + "moduleName": "SoftUART", "moduleVersion": "1.0", "usedRam": 15, "subTypes": [ "SoftUART" ], "title": "Софтовый uart для esp8266 или harware uart для esp32", - "moduleDesc": "Используется вместе с Pzem004t", + "moduleDesc": "Используется вместе с Pzem004t, в последствии будет доработан для связи с arduino платами", "propInfo": { "tx": "TX пин", "rx": "RX пин", "speed": "Скорость UART" } }, - "defActive": false, + "defActive": true, "devices": { "esp32_4mb": [ "plerup/espsoftwareserial"