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

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

@@ -303,9 +303,39 @@
"round": 1 "round": 1
}, },
{ {
"name": "22. Cенсор температуры GY21", "name": "22. Датчик тока",
"num": 22, "num": 22,
"type": "Reading", "type": "Reading",
"subtype": "I",
"id": "current",
"widget": "anydataAmp",
"page": "Сенсоры",
"descr": "Датчик тока",
"int": 10,
"pin_I": 34,
"calib_I": 111.1,
"plus": 0,
"multiply": 1
},
{
"name": "23. Датчик напряжения",
"num": 23,
"type": "Reading",
"subtype": "U",
"id": "voltage",
"widget": "anydataVlt",
"page": "Сенсоры",
"descr": "Датчик напряжения",
"int": 10,
"pin_U": 35,
"calib_U": 223.1,
"plus": 0,
"multiply": 1
},
{
"name": "24. Cенсор температуры GY21",
"num": 24,
"type": "Reading",
"subtype": "GY21t", "subtype": "GY21t",
"id": "tmp4", "id": "tmp4",
"widget": "anydataTmp", "widget": "anydataTmp",
@@ -315,8 +345,8 @@
"int": 15 "int": 15
}, },
{ {
"name": "23. Cенсор влажности GY21", "name": "25. Cенсор влажности GY21",
"num": 23, "num": 25,
"type": "Reading", "type": "Reading",
"subtype": "GY21h", "subtype": "GY21h",
"id": "Hum4", "id": "Hum4",
@@ -327,8 +357,8 @@
"int": 15 "int": 15
}, },
{ {
"name": "24. Cенсор температуры HDC1080", "name": "26. Cенсор температуры HDC1080",
"num": 24, "num": 26,
"type": "Reading", "type": "Reading",
"subtype": "Hdc1080t", "subtype": "Hdc1080t",
"id": "Temp1080", "id": "Temp1080",
@@ -340,8 +370,8 @@
"round": 1 "round": 1
}, },
{ {
"name": "25. Cенсор влажности HDC1080", "name": "27. Cенсор влажности HDC1080",
"num": 25, "num": 27,
"type": "Reading", "type": "Reading",
"subtype": "Hdc1080h", "subtype": "Hdc1080h",
"id": "Hum1080", "id": "Hum1080",
@@ -353,8 +383,8 @@
"round": 1 "round": 1
}, },
{ {
"name": "26. Cенсор температуры MAX6675", "name": "28. Cенсор температуры MAX6675",
"num": 26, "num": 28,
"type": "Reading", "type": "Reading",
"subtype": "Max6675t", "subtype": "Max6675t",
"id": "maxtmp", "id": "maxtmp",
@@ -367,8 +397,8 @@
"CLK": 14 "CLK": 14
}, },
{ {
"name": "27. Датчик CO2 MHZ-19 UART", "name": "29. Датчик CO2 MHZ-19 UART",
"num": 27, "num": 29,
"type": "Reading", "type": "Reading",
"subtype": "Mhz19uart", "subtype": "Mhz19uart",
"id": "co2uart", "id": "co2uart",
@@ -386,8 +416,8 @@
"ABC": 1 "ABC": 1
}, },
{ {
"name": "28. Датчик CO2 MHZ-19 PWM", "name": "30. Датчик CO2 MHZ-19 PWM",
"num": 28, "num": 30,
"type": "Reading", "type": "Reading",
"subtype": "Mhz19pwm", "subtype": "Mhz19pwm",
"id": "co2pwm", "id": "co2pwm",
@@ -401,8 +431,8 @@
"int": 300 "int": 300
}, },
{ {
"name": "29. Cенсор температуры от MHZ-19 UART", "name": "31. Cенсор температуры от MHZ-19 UART",
"num": 29, "num": 31,
"type": "Reading", "type": "Reading",
"subtype": "Mhz19temp", "subtype": "Mhz19temp",
"id": "Mhz19temp", "id": "Mhz19temp",
@@ -418,8 +448,8 @@
"int": 30 "int": 30
}, },
{ {
"name": "30. Рабочий диапазон от MHZ-19 UART", "name": "32. Рабочий диапазон от MHZ-19 UART",
"num": 30, "num": 32,
"type": "Reading", "type": "Reading",
"subtype": "Mhz19range", "subtype": "Mhz19range",
"id": "Mhz19range", "id": "Mhz19range",
@@ -436,8 +466,8 @@
"int": 30 "int": 30
}, },
{ {
"name": "31. Автокалибровка от MHZ-19 UART", "name": "33. Автокалибровка от MHZ-19 UART",
"num": 31, "num": 33,
"type": "Reading", "type": "Reading",
"subtype": "Mhz19ABC", "subtype": "Mhz19ABC",
"id": "Mhz19ABC", "id": "Mhz19ABC",
@@ -451,8 +481,8 @@
"int": 30 "int": 30
}, },
{ {
"name": "32. Датчик пыли SDS011 PM25", "name": "34. Датчик пыли SDS011 PM25",
"num": 32, "num": 34,
"type": "Reading", "type": "Reading",
"subtype": "Sds011_25", "subtype": "Sds011_25",
"id": "pmuart25", "id": "pmuart25",
@@ -469,8 +499,8 @@
"period": 300 "period": 300
}, },
{ {
"name": "33. Датчик пыли SDS011 PM10", "name": "35. Датчик пыли SDS011 PM10",
"num": 33, "num": 35,
"type": "Reading", "type": "Reading",
"subtype": "Sds011_10", "subtype": "Sds011_10",
"id": "pmuart10", "id": "pmuart10",
@@ -487,8 +517,8 @@
"period": 300 "period": 300
}, },
{ {
"name": "34. Cенсор температуры Sht20", "name": "36. Cенсор температуры Sht20",
"num": 34, "num": 36,
"type": "Reading", "type": "Reading",
"subtype": "Sht20t", "subtype": "Sht20t",
"id": "tmp2", "id": "tmp2",
@@ -499,8 +529,8 @@
"round": 1 "round": 1
}, },
{ {
"name": "35. Cенсор влажности Sht20", "name": "37. Cенсор влажности Sht20",
"num": 35, "num": 37,
"type": "Reading", "type": "Reading",
"subtype": "Sht20h", "subtype": "Sht20h",
"id": "Hum2", "id": "Hum2",
@@ -511,8 +541,8 @@
"round": 1 "round": 1
}, },
{ {
"name": "36. Сонар HC-SR04", "name": "38. Сонар HC-SR04",
"num": 36, "num": 38,
"type": "Reading", "type": "Reading",
"subtype": "Sonar", "subtype": "Sonar",
"id": "sonar", "id": "sonar",
@@ -527,8 +557,8 @@
"header": "Экраны" "header": "Экраны"
}, },
{ {
"name": "37. LCD экран 2004", "name": "39. LCD экран 2004",
"num": 37, "num": 39,
"type": "Reading", "type": "Reading",
"subtype": "Lcd2004", "subtype": "Lcd2004",
"id": "Lcd", "id": "Lcd",
@@ -542,8 +572,8 @@
"id2show": "id датчика" "id2show": "id датчика"
}, },
{ {
"name": "38. LCD экран 1602", "name": "40. LCD экран 1602",
"num": 38, "num": 40,
"type": "Reading", "type": "Reading",
"subtype": "Lcd2004", "subtype": "Lcd2004",
"id": "Lcd", "id": "Lcd",

View File

@@ -54,6 +54,7 @@ lib_deps =
adafruit/Adafruit BMP280 Library adafruit/Adafruit BMP280 Library
beegee-tokyo/DHT sensor library for ESPx beegee-tokyo/DHT sensor library for ESPx
milesburton/DallasTemperature@^3.9.1 milesburton/DallasTemperature@^3.9.1
openenergymonitor/EmonLib@1.1.0
https://github.com/JonasGMorsch/GY-21.git https://github.com/JonasGMorsch/GY-21.git
ClosedCube HDC1080 ClosedCube HDC1080
adafruit/MAX6675 library adafruit/MAX6675 library
@@ -73,6 +74,7 @@ lib_deps =
adafruit/Adafruit BMP280 Library adafruit/Adafruit BMP280 Library
beegee-tokyo/DHT sensor library for ESPx beegee-tokyo/DHT sensor library for ESPx
milesburton/DallasTemperature@^3.9.1 milesburton/DallasTemperature@^3.9.1
openenergymonitor/EmonLib@1.1.0
https://github.com/JonasGMorsch/GY-21.git https://github.com/JonasGMorsch/GY-21.git
ClosedCube HDC1080 ClosedCube HDC1080
adafruit/MAX6675 library adafruit/MAX6675 library

View File

@@ -16,6 +16,7 @@ void* getAPI_Bme280(String subtype, String params);
void* getAPI_Bmp280(String subtype, String params); void* getAPI_Bmp280(String subtype, String params);
void* getAPI_Dht1122(String subtype, String params); void* getAPI_Dht1122(String subtype, String params);
void* getAPI_Ds18b20(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_GY21(String subtype, String params);
void* getAPI_Hdc1080(String subtype, String params); void* getAPI_Hdc1080(String subtype, String params);
void* getAPI_Max6675(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_Bmp280(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Dht1122(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_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_GY21(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Hdc1080(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Hdc1080(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Max6675(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