2022-09-26 20:26:04 +02:00
|
|
|
|
|
|
|
|
#include "Global.h"
|
|
|
|
|
#include "classes/IoTItem.h"
|
|
|
|
|
|
|
|
|
|
#include "PZEMSensor.h"
|
2022-09-27 00:52:53 +02:00
|
|
|
#include "modules/sensors/SoftUart/SoftUart.h"
|
2022-09-26 20:26:04 +02:00
|
|
|
|
2022-09-26 21:56:54 +02:00
|
|
|
PZEMSensor* pzem;
|
2022-09-26 20:26:04 +02:00
|
|
|
|
2022-09-26 21:56:54 +02:00
|
|
|
class Pzem004v : public IoTItem {
|
|
|
|
|
private:
|
|
|
|
|
String addr;
|
|
|
|
|
|
|
|
|
|
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(){};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void* getAPI_Pzem004(String subtype, String param) {
|
2022-09-27 00:52:53 +02:00
|
|
|
if (subtype == F("Pzem004v")) {
|
|
|
|
|
return new Pzem004v(param);
|
|
|
|
|
} else {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2022-09-26 21:56:54 +02:00
|
|
|
}
|