2022-09-26 20:26:04 +02:00
|
|
|
|
|
|
|
|
#include "Global.h"
|
|
|
|
|
#include "classes/IoTItem.h"
|
|
|
|
|
|
|
|
|
|
#include "PZEMSensor.h"
|
2022-09-27 01:24:22 +02:00
|
|
|
#include "modules/sensors/UART/Uart.h"
|
2022-09-26 20:26:04 +02:00
|
|
|
|
2022-09-26 21:56:54 +02:00
|
|
|
class Pzem004v : public IoTItem {
|
|
|
|
|
private:
|
|
|
|
|
String addr;
|
2022-09-27 18:09:12 +02:00
|
|
|
PZEMSensor* pzem;
|
2022-09-26 21:56:54 +02:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
Pzem004v(String parameters) : IoTItem(parameters) {
|
|
|
|
|
addr = jsonReadStr(parameters, "addr");
|
2022-09-27 00:57:28 +02:00
|
|
|
if (myUART) {
|
|
|
|
|
pzem = new PZEMSensor(myUART, hexStringToUint8(addr));
|
|
|
|
|
}
|
2022-09-27 00:52:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void doByInterval() {
|
2022-09-27 00:57:28 +02:00
|
|
|
if (pzem) {
|
|
|
|
|
value.valD = pzem->values()->voltage;
|
|
|
|
|
regEvent(value.valD, "Pzem Voltage");
|
|
|
|
|
}
|
2022-09-26 21:56:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~Pzem004v(){};
|
|
|
|
|
};
|
|
|
|
|
|
2022-09-27 18:30:18 +02:00
|
|
|
class Pzem004a : public IoTItem {
|
|
|
|
|
private:
|
|
|
|
|
String addr;
|
|
|
|
|
PZEMSensor* pzem;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
Pzem004a(String parameters) : IoTItem(parameters) {
|
|
|
|
|
addr = jsonReadStr(parameters, "addr");
|
|
|
|
|
if (myUART) {
|
|
|
|
|
pzem = new PZEMSensor(myUART, hexStringToUint8(addr));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void doByInterval() {
|
|
|
|
|
if (pzem) {
|
|
|
|
|
value.valD = pzem->values()->current;
|
|
|
|
|
regEvent(value.valD, "Pzem Ampere");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~Pzem004a(){};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Pzem004w : public IoTItem {
|
|
|
|
|
private:
|
|
|
|
|
String addr;
|
|
|
|
|
PZEMSensor* pzem;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
Pzem004w(String parameters) : IoTItem(parameters) {
|
|
|
|
|
addr = jsonReadStr(parameters, "addr");
|
|
|
|
|
if (myUART) {
|
|
|
|
|
pzem = new PZEMSensor(myUART, hexStringToUint8(addr));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void doByInterval() {
|
|
|
|
|
if (pzem) {
|
|
|
|
|
value.valD = pzem->values()->power;
|
|
|
|
|
regEvent(value.valD, "Pzem Watt");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~Pzem004w(){};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Pzem004wh : public IoTItem {
|
|
|
|
|
private:
|
|
|
|
|
String addr;
|
|
|
|
|
PZEMSensor* pzem;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
Pzem004wh(String parameters) : IoTItem(parameters) {
|
|
|
|
|
addr = jsonReadStr(parameters, "addr");
|
|
|
|
|
if (myUART) {
|
|
|
|
|
pzem = new PZEMSensor(myUART, hexStringToUint8(addr));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void doByInterval() {
|
|
|
|
|
if (pzem) {
|
|
|
|
|
value.valD = pzem->values()->energy;
|
|
|
|
|
regEvent(value.valD, "Pzem Watt/hr");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~Pzem004wh(){};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Pzem004hz : public IoTItem {
|
|
|
|
|
private:
|
|
|
|
|
String addr;
|
|
|
|
|
PZEMSensor* pzem;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
Pzem004hz(String parameters) : IoTItem(parameters) {
|
|
|
|
|
addr = jsonReadStr(parameters, "addr");
|
|
|
|
|
if (myUART) {
|
|
|
|
|
pzem = new PZEMSensor(myUART, hexStringToUint8(addr));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void doByInterval() {
|
|
|
|
|
if (pzem) {
|
|
|
|
|
value.valD = pzem->values()->freq;
|
|
|
|
|
regEvent(value.valD, "Pzem Hz");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~Pzem004hz(){};
|
|
|
|
|
};
|
|
|
|
|
|
2022-09-26 21:56:54 +02:00
|
|
|
void* getAPI_Pzem004(String subtype, String param) {
|
2022-09-27 00:52:53 +02:00
|
|
|
if (subtype == F("Pzem004v")) {
|
|
|
|
|
return new Pzem004v(param);
|
2022-09-27 18:30:18 +02:00
|
|
|
} else if (subtype == F("Pzem004a")) {
|
|
|
|
|
return new Pzem004a(param);
|
|
|
|
|
} else if (subtype == F("Pzem004w")) {
|
|
|
|
|
return new Pzem004w(param);
|
|
|
|
|
} else if (subtype == F("Pzem004wh")) {
|
|
|
|
|
return new Pzem004wh(param);
|
|
|
|
|
} else if (subtype == F("Pzem004hz")) {
|
|
|
|
|
return new Pzem004hz(param);
|
2022-09-27 00:52:53 +02:00
|
|
|
} else {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2022-09-26 21:56:54 +02:00
|
|
|
}
|