pzem - чтение напряжения

This commit is contained in:
Dmitry Borisenko
2022-09-27 00:52:53 +02:00
parent c091f1b4cc
commit e688c95c59
10 changed files with 150 additions and 53 deletions

View File

@@ -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
}
]

View File

@@ -217,6 +217,7 @@
"icon": "speedometer"
},
{
"name": "nil",
"label": "Без виджета"
}
]

View File

@@ -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",

View File

@@ -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 =
+<modules\sensors\GY21>
+<modules\sensors\Hdc1080>
+<modules\sensors\Max6675>
+<modules\sensors\Pzem004t>
+<modules\sensors\RCswitch>
+<modules\sensors\Sht20>
+<modules\sensors\Sht30>
+<modules\sensors\SoftUart>
+<modules\sensors\Sonar>
+<modules\exec\ButtonIn>
+<modules\exec\ButtonOut>

View File

@@ -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;

View File

@@ -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;
}
}

View File

@@ -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": []

View File

@@ -2,7 +2,8 @@
#include "Global.h"
#include "classes/IoTItem.h"
#include <Arduino.h>
//#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;

View File

@@ -0,0 +1,9 @@
#pragma once
#ifdef ESP8266
#include <SoftwareSerial.h>
extern SoftwareSerial* myUART;
#else
#include <HardwareSerial.h>
extern HardwareSerial* myUART;
#endif

View File

@@ -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"