Добавляем сенсор для мониторинга напряжения и ток с использованием аналового входа

This commit is contained in:
2022-05-20 08:52:15 +03:00
parent cbd9a4de8d
commit e3072ce887
6 changed files with 181 additions and 33 deletions

View File

@@ -16,6 +16,7 @@ void* getAPI_Bme280(String subtype, String params);
void* getAPI_Bmp280(String subtype, String params);
void* getAPI_Dht1122(String subtype, String params);
void* getAPI_Ds18b20(String subtype, String params);
void* getAPI_Emon(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);
@@ -43,6 +44,7 @@ if ((tmpAPI = getAPI_Bme280(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Bmp280(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Dht1122(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Ds18b20(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Emon(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;

View File

@@ -0,0 +1,72 @@
/******************************************************************
Used Energy Monitoring Library
https://github.com/openenergymonitor/EmonLib
adapted for version 4 @Serghei63
******************************************************************/
#include "Global.h"
#include "classes/IoTItem.h"
#include <map>
extern IoTGpio IoTgpio;
#include "EmonLib.h" // Include Emon Library
EnergyMonitor emon1; // Create an instance
class Energy : public IoTItem {
private:
unsigned int _pinI; // ток
unsigned int _calibI; // ток
public:
Energy(String parameters): IoTItem(parameters) {
_pinI = jsonReadInt(parameters, "pin_I");
_calibI = jsonReadInt(parameters, "calib_I");
emon1.current(_pinI, _calibI); // Current: input pin, calibration.
}
void doByInterval() {
value.valD = emon1.calcIrms(1480); // Calculate Irms only
regEvent(value.valD, "current");
}
~Energy(){};
};
class Power : public IoTItem {
private:
unsigned int _pinU; // напряжение
unsigned int _calibU; // напряжение
public:
Power(String parameters): IoTItem(parameters) {
_pinU = jsonReadInt(parameters, "pin_U");
_calibU = jsonReadInt(parameters, "calib_U");
emon1.voltage(_pinU, _calibU, 1.7); // Voltage: input pin, calibration, phase_shift
}
void doByInterval() {
if (emon1.Irms > 0) emon1.calcVI(10, 1000); // Calculate all. No.of half wavelengths (crossings), time-out при условии, что ток не нулевой
value.valD = emon1.Vrms; //extract Vrms into Variable;
regEvent(value.valD, "voltage");
}
~Power(){};
};
void* getAPI_Emon(String subtype, String param) {
if (subtype == F("I")) {
return new Energy(param);
} else if (subtype == F("U")) {
return new Power(param);
} else {
return nullptr;
}
}

View File

@@ -0,0 +1,34 @@
[
{
"name": "Датчик тока",
"num": 31,
"type": "Reading",
"subtype": "I",
"id": "current",
"widget": "anydataAmp",
"page": "Сенсоры",
"descr": "Датчик тока",
"int": 10,
"pin_I": 34,
"calib_I": 111.1,
"plus": 0,
"multiply": 1
},
{
"name": "Датчик напряжения",
"num": 32,
"type": "Reading",
"subtype": "U",
"id": "voltage",
"widget": "anydataVlt",
"page": "Сенсоры",
"descr": "Датчик напряжения",
"int": 10,
"pin_U": 35,
"calib_U": 223.1,
"plus": 0,
"multiply": 1
}
]

View File

@@ -0,0 +1,8 @@
[env:esp8266_4mb]
lib_deps =
openenergymonitor/EmonLib@1.1.0
[env:esp32_4mb]
lib_deps =
openenergymonitor/EmonLib@1.1.0