mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-31 04:19:15 +03:00
Меняем структуру FS для хранения модулей и добавляем скрипт сборки модулей для интеграции в меню и библиотеки
This commit is contained in:
80
src/modules/sensors/Dht1122/Dht1122.cpp
Normal file
80
src/modules/sensors/Dht1122/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/IoTItem.h"
|
||||
|
||||
#include "DHTesp.h"
|
||||
#include <map>
|
||||
|
||||
|
||||
std::map<int, DHTesp*> dhts;
|
||||
|
||||
class Dht1122t : public IoTItem {
|
||||
private:
|
||||
DHTesp* _dht;
|
||||
|
||||
public:
|
||||
Dht1122t(DHTesp* dht, String parameters): IoTItem(parameters) {
|
||||
_dht = dht;
|
||||
}
|
||||
|
||||
void doByInterval() {
|
||||
value.valD = _dht->getTemperature();
|
||||
if (String(value.valD) != "nan") regEvent(value.valD, "Dht1122t");
|
||||
else SerialPrint("E", "Sensor DHTt", "Error");
|
||||
}
|
||||
|
||||
~Dht1122t() {};
|
||||
};
|
||||
|
||||
|
||||
class Dht1122h : public IoTItem {
|
||||
private:
|
||||
DHTesp* _dht;
|
||||
|
||||
public:
|
||||
Dht1122h(DHTesp* dht, String parameters): IoTItem(parameters) {
|
||||
_dht = dht;
|
||||
}
|
||||
|
||||
void doByInterval() {
|
||||
value.valD = _dht->getHumidity();
|
||||
if (String(value.valD) != "nan") regEvent(value.valD, "Dht1122h");
|
||||
else SerialPrint("E", "Sensor DHTh", "Error");
|
||||
}
|
||||
|
||||
~Dht1122h() {};
|
||||
};
|
||||
|
||||
|
||||
void* getAPI_Dht1122(String subtype, String param) {
|
||||
if (subtype == F("Dht1122t") || subtype == F("Dht1122h")) {
|
||||
int pin;
|
||||
String senstype;
|
||||
jsonRead(param, "pin", pin);
|
||||
jsonRead(param, "senstype", senstype);
|
||||
|
||||
if (dhts.find(pin) == dhts.end()) {
|
||||
dhts[pin] = new DHTesp();
|
||||
|
||||
if (senstype == "dht11") {
|
||||
dhts[pin]->setup(pin, DHTesp::DHT11);
|
||||
} else if (senstype == "dht22") {
|
||||
dhts[pin]->setup(pin, DHTesp::DHT22);
|
||||
}
|
||||
}
|
||||
|
||||
if (subtype == F("Dht1122t")) {
|
||||
return new Dht1122t(dhts[pin], param);
|
||||
} else if (subtype == F("Dht1122h")) {
|
||||
return new Dht1122h(dhts[pin], param);
|
||||
}
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
28
src/modules/sensors/Dht1122/items.json
Normal file
28
src/modules/sensors/Dht1122/items.json
Normal file
@@ -0,0 +1,28 @@
|
||||
[
|
||||
{
|
||||
"name": "Cенсор температуры dht11",
|
||||
"num": 5,
|
||||
"type": "Reading",
|
||||
"subtype": "Dht1122t",
|
||||
"id": "tmp3",
|
||||
"widget": "anydataTmp",
|
||||
"page": "Сенсоры",
|
||||
"descr": "Температура",
|
||||
"int": 15,
|
||||
"pin": 0,
|
||||
"senstype": "dht11"
|
||||
},
|
||||
{
|
||||
"name": "Cенсор влажности dht11",
|
||||
"num": 6,
|
||||
"type": "Reading",
|
||||
"subtype": "Dht1122h",
|
||||
"id": "Hum3",
|
||||
"widget": "anydataHum",
|
||||
"page": "Сенсоры",
|
||||
"descr": "Влажность",
|
||||
"int": 15,
|
||||
"pin": 0,
|
||||
"senstype": "dht11"
|
||||
}
|
||||
]
|
||||
7
src/modules/sensors/Dht1122/platformio.ini
Normal file
7
src/modules/sensors/Dht1122/platformio.ini
Normal file
@@ -0,0 +1,7 @@
|
||||
[env:esp8266_4mb]
|
||||
lib_deps =
|
||||
beegee-tokyo/DHT sensor library for ESPx
|
||||
|
||||
[env:esp32_4mb]
|
||||
lib_deps =
|
||||
beegee-tokyo/DHT sensor library for ESPx
|
||||
Reference in New Issue
Block a user