проверка на отсутствие

This commit is contained in:
Dmitry Borisenko
2022-09-27 20:55:16 +02:00
parent f92291c545
commit 62ff324139
7 changed files with 55 additions and 29 deletions

View File

@@ -367,7 +367,7 @@
"page": "Сенсоры",
"descr": "Частота",
"int": 15,
"addr": "0x77",
"addr": "0xF8",
"num": 28
},
{

View File

@@ -209,13 +209,6 @@
],
"status": 0
},
{
"name": "anydataVlt",
"label": "Вольты",
"widget": "anydata",
"after": "Vlt",
"icon": "speedometer"
},
{
"name": "nil",
"label": "Без виджета"

View File

@@ -1,7 +1,6 @@
#pragma once
#include <Arduino.h>
#include <SoftwareSerial.h>
#define PZEM_DEFAULT_ADDR 0xF8
@@ -22,13 +21,13 @@ class PZEMSensor {
PZEMSensor(Stream *serial, uint16_t addr = PZEM_DEFAULT_ADDR);
~PZEMSensor();
PZEM_Info* values();
PZEM_Info *values(bool &online);
bool setAddress(uint8_t addr);
uint8_t getAddress();
bool setPowerAlarm(uint16_t watts);
bool getPowerAlarm();
bool reset();
void search();
bool search();
// Get most up to date values from device registers and cache them
bool refresh();

View File

@@ -43,11 +43,13 @@ PZEMSensor::PZEMSensor(Stream *port, uint16_t addr) {
init();
}
PZEM_Info *PZEMSensor::values() {
PZEM_Info *PZEMSensor::values(bool &online) {
// Update vales if necessary
if (!refresh()) {
_values = PZEM_Info();
online = false;
}
online = true;
return &_values;
}
@@ -295,7 +297,8 @@ uint16_t PZEMSensor::CRC16(const uint8_t *data, uint16_t len) {
return crc;
}
void PZEMSensor::search() {
bool PZEMSensor::search() {
bool ret = false;
static uint8_t response[7];
for (uint16_t addr = 0x01; addr <= 0xF8; addr++) {
sendCmd8(CMD_RIR, 0x00, 0x01, false, addr);
@@ -303,8 +306,9 @@ void PZEMSensor::search() {
// Something went wrong
continue;
} else {
Serial.print("Device on addr: ");
Serial.print(addr);
Serial.println("Pzem " + String(addr));
ret = true;
}
}
return ret;
}

View File

@@ -61,6 +61,7 @@ lib_deps =
https://github.com/JonasGMorsch/GY-21.git
ClosedCube HDC1080
adafruit/MAX6675 library
mandulaj/PZEM-004T-v30
rc-switch @ ^2.6.4
robtillaart/SHT2x@^0.1.1
WEMOS SHT3x@1.0.0

View File

@@ -20,8 +20,13 @@ class Pzem004v : public IoTItem {
void doByInterval() {
if (pzem) {
value.valD = pzem->values()->voltage;
regEvent(value.valD, "Pzem Voltage");
bool online = false;
value.valD = pzem->values(online)->voltage;
if (online) {
regEvent(value.valD, "Pzem V");
} else {
SerialPrint("E", "Pzem", "V error");
}
}
}
@@ -43,8 +48,13 @@ class Pzem004a : public IoTItem {
void doByInterval() {
if (pzem) {
value.valD = pzem->values()->current;
regEvent(value.valD, "Pzem Ampere");
bool online = false;
value.valD = pzem->values(online)->current;
if (online) {
regEvent(value.valD, "Pzem A");
} else {
SerialPrint("E", "Pzem", "A error");
}
}
}
@@ -66,8 +76,13 @@ class Pzem004w : public IoTItem {
void doByInterval() {
if (pzem) {
value.valD = pzem->values()->power;
regEvent(value.valD, "Pzem Watt");
bool online = false;
value.valD = pzem->values(online)->power;
if (online) {
regEvent(value.valD, "Pzem W");
} else {
SerialPrint("E", "Pzem", "W error");
}
}
}
@@ -89,8 +104,13 @@ class Pzem004wh : public IoTItem {
void doByInterval() {
if (pzem) {
value.valD = pzem->values()->energy;
regEvent(value.valD, "Pzem Watt/hr");
bool online = false;
value.valD = pzem->values(online)->energy;
if (online) {
regEvent(value.valD, "Pzem Wh");
} else {
SerialPrint("E", "Pzem", "Wh error");
}
}
}
@@ -112,8 +132,13 @@ class Pzem004hz : public IoTItem {
void doByInterval() {
if (pzem) {
value.valD = pzem->values()->freq;
bool online = false;
value.valD = pzem->values(online)->freq;
if (online) {
regEvent(value.valD, "Pzem Hz");
} else {
SerialPrint("E", "Pzem", "Hz error");
}
}
}

View File

@@ -54,7 +54,7 @@
"page": "Сенсоры",
"descr": "Частота",
"int": 15,
"addr": "0x77"
"addr": "0xF8"
}
],
"about": {
@@ -81,7 +81,11 @@
},
"defActive": true,
"devices": {
"esp32_4mb": [],
"esp8266_4mb": []
"esp32_4mb": [
"mandulaj/PZEM-004T-v30"
],
"esp8266_4mb": [
"mandulaj/PZEM-004T-v30"
]
}
}