mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 20:09:14 +03:00
Портируем сенсоры Dht11 и Dht22 одним модулем
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
"map": "1,1024,1,1024",
|
"map": "1,1024,1,1024",
|
||||||
"plus": 0,
|
"plus": 0,
|
||||||
"multiply": 1,
|
"multiply": 1,
|
||||||
|
"round": 1,
|
||||||
"pin": 0,
|
"pin": 0,
|
||||||
"int": 15
|
"int": 15
|
||||||
},
|
},
|
||||||
@@ -41,5 +42,27 @@
|
|||||||
"page": "Сенсоры",
|
"page": "Сенсоры",
|
||||||
"descr": "Влажность",
|
"descr": "Влажность",
|
||||||
"int": 15
|
"int": 15
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "Reading",
|
||||||
|
"subtype": "Dht1122t",
|
||||||
|
"id": "tmp3",
|
||||||
|
"widget": "anydataTmp",
|
||||||
|
"page": "Сенсоры",
|
||||||
|
"descr": "Температура",
|
||||||
|
"int": 15,
|
||||||
|
"pin": 0,
|
||||||
|
"senstype": "dht11"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "Reading",
|
||||||
|
"subtype": "Dht1122h",
|
||||||
|
"id": "Hum3",
|
||||||
|
"widget": "anydataTmp",
|
||||||
|
"page": "Сенсоры",
|
||||||
|
"descr": "Влажность",
|
||||||
|
"int": 15,
|
||||||
|
"pin": 0,
|
||||||
|
"senstype": "dht11"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -29,6 +29,7 @@ lib_deps =
|
|||||||
${common_env_data.lib_deps_external}
|
${common_env_data.lib_deps_external}
|
||||||
milesburton/DallasTemperature@^3.9.1
|
milesburton/DallasTemperature@^3.9.1
|
||||||
robtillaart/SHT2x@^0.1.1
|
robtillaart/SHT2x@^0.1.1
|
||||||
|
beegee-tokyo/DHT sensor library for ESPx
|
||||||
monitor_filters = esp8266_exception_decoder
|
monitor_filters = esp8266_exception_decoder
|
||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
@@ -43,6 +44,7 @@ lib_deps =
|
|||||||
${common_env_data.lib_deps_external}
|
${common_env_data.lib_deps_external}
|
||||||
milesburton/DallasTemperature@^3.9.1
|
milesburton/DallasTemperature@^3.9.1
|
||||||
robtillaart/SHT2x@^0.1.1
|
robtillaart/SHT2x@^0.1.1
|
||||||
|
beegee-tokyo/DHT sensor library for ESPx
|
||||||
monitor_filters = esp32_exception_decoder
|
monitor_filters = esp32_exception_decoder
|
||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
void* getAPI_AnalogAdc(String subtype, String params);
|
void* getAPI_AnalogAdc(String subtype, String params);
|
||||||
void* getAPI_Ds18b20(String subtype, String params);
|
void* getAPI_Ds18b20(String subtype, String params);
|
||||||
void* getAPI_Sht20(String subtype, String params);
|
void* getAPI_Sht20(String subtype, String params);
|
||||||
|
void* getAPI_Dht1122(String subtype, String params);
|
||||||
//============================================================================================
|
//============================================================================================
|
||||||
|
|
||||||
void* getAPI(String subtype, String params) {
|
void* getAPI(String subtype, String params) {
|
||||||
@@ -14,6 +15,7 @@ void* getAPI(String subtype, String params) {
|
|||||||
if ((tmpAPI = getAPI_AnalogAdc(subtype, params)) != nullptr) return tmpAPI;
|
if ((tmpAPI = getAPI_AnalogAdc(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_Sht20(subtype, params)) != nullptr) return tmpAPI;
|
if ((tmpAPI = getAPI_Sht20(subtype, params)) != nullptr) return tmpAPI;
|
||||||
|
if ((tmpAPI = getAPI_Dht1122(subtype, params)) != nullptr) return tmpAPI;
|
||||||
//================================================================================================================
|
//================================================================================================================
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|||||||
80
src/modules/Dht1122.cpp
Normal file
80
src/modules/Dht1122.cpp
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
/******************************************************************
|
||||||
|
Used DHT Temperature & Humidity Sensor library for Arduino & ESP32.
|
||||||
|
Support for DHT11 and DHT22/AM2302/RHT03
|
||||||
|
https://github.com/beegee-tokyo/arduino-DHTesp
|
||||||
|
******************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
#include "Global.h"
|
||||||
|
#include "Classes/IoTSensor.h"
|
||||||
|
|
||||||
|
#include "DHTesp.h"
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
|
||||||
|
std::map<int, DHTesp*> dhts;
|
||||||
|
|
||||||
|
class Dht1122t : public IoTSensor {
|
||||||
|
private:
|
||||||
|
int _pin;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Dht1122t(String parameters): IoTSensor(parameters) {
|
||||||
|
jsonRead(parameters, "pin", _pin);
|
||||||
|
}
|
||||||
|
|
||||||
|
void doByInterval() {
|
||||||
|
float value = dhts[_pin]->getTemperature();
|
||||||
|
if (String(value) != "nan") regEvent((String)value, "Dht1122t");
|
||||||
|
else SerialPrint("E", "Sensor DHTt", "Error");
|
||||||
|
}
|
||||||
|
|
||||||
|
~Dht1122t();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class Dht1122h : public IoTSensor {
|
||||||
|
private:
|
||||||
|
int _pin;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Dht1122h(String parameters): IoTSensor(parameters) {
|
||||||
|
jsonRead(parameters, "pin", _pin);
|
||||||
|
}
|
||||||
|
|
||||||
|
void doByInterval() {
|
||||||
|
float value = dhts[_pin]->getHumidity();
|
||||||
|
if (String(value) != "nan") regEvent((String)value, "Dht1122h");
|
||||||
|
else SerialPrint("E", "Sensor DHTh", "Error");
|
||||||
|
}
|
||||||
|
|
||||||
|
~Dht1122h();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void* getAPI_Dht1122(String subtype, String param) {
|
||||||
|
int pin;
|
||||||
|
String senstype;
|
||||||
|
jsonRead(param, "pin", pin);
|
||||||
|
jsonRead(param, "senstype", senstype);
|
||||||
|
|
||||||
|
if (dhts.find(pin) == dhts.end()) {
|
||||||
|
DHTesp* dht = new DHTesp();
|
||||||
|
|
||||||
|
if (senstype == "dht11") {
|
||||||
|
dht->setup(pin, DHTesp::DHT11);
|
||||||
|
} else if (senstype == "dht22") {
|
||||||
|
dht->setup(pin, DHTesp::DHT22);
|
||||||
|
}
|
||||||
|
|
||||||
|
dhts[pin] = dht;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (subtype == F("Dht1122t")) {
|
||||||
|
return new Dht1122t(param);
|
||||||
|
} else if (subtype == F("Dht1122h")) {
|
||||||
|
return new Dht1122h(param);
|
||||||
|
} else {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user