mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 06:32:19 +03:00
31
src/items/SensorPower.cpp
Normal file
31
src/items/SensorPower.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "items/SensorPower.h"
|
||||
|
||||
SensorPZEM* myPowerSensor;
|
||||
|
||||
void SensorPZEM::loop() {
|
||||
uint32_t now = millis();
|
||||
if ((_lastUpdate + _interval) < now) {
|
||||
post("voltage", String(_pzem->values()->voltage, 2));
|
||||
post("current", String(_pzem->values()->current, 2));
|
||||
post("power", String(_pzem->values()->power, 2));
|
||||
post("energy", String(_pzem->values()->energy, 2));
|
||||
post("freq", String(_pzem->values()->freq, 0));
|
||||
post("pf", String(_pzem->values()->pf, 2));
|
||||
_lastUpdate = now;
|
||||
}
|
||||
}
|
||||
|
||||
String SensorPZEM::getDataKey(const char* param_key) {
|
||||
String res = _key;
|
||||
res += "_";
|
||||
res += param_key;
|
||||
return res;
|
||||
}
|
||||
|
||||
void SensorPZEM::post(const char* key, const String& value) {
|
||||
String dataKey = getDataKey(key);
|
||||
eventGen2(dataKey, value);
|
||||
jsonWriteStr(configLiveJson, dataKey, value);
|
||||
publishStatus(dataKey, value);
|
||||
SerialPrint("I", "Sensor", "'" + dataKey + "' data: " + value);
|
||||
}
|
||||
Reference in New Issue
Block a user