mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
Add DHT sensor
This commit is contained in:
@@ -1,43 +1,75 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
#include "items/SensorConvertingClass.h"
|
||||
|
||||
DHTesp dht;
|
||||
class SensorDhtClass : public SensorConvertingClass {
|
||||
public:
|
||||
SensorDhtClass() : SensorConvertingClass(){};
|
||||
|
||||
void SensorDhtInit() {
|
||||
//oneWire = new OneWire((uint8_t)_pin.toInt());
|
||||
//sensors.setOneWire(oneWire);
|
||||
//sensors.begin();
|
||||
//sensors.setResolution(48);
|
||||
|
||||
if (_type == "dht11") {
|
||||
dht.setup(_pin.toInt(), DHTesp::DHT11);
|
||||
}
|
||||
if (_type == "dht22") {
|
||||
dht.setup(_pin.toInt(), DHTesp::DHT22);
|
||||
}
|
||||
sensorReadingMap += _key + ",";
|
||||
//dhtEnterCounter++;
|
||||
|
||||
//to do если надо будет читать несколько dht
|
||||
//dhtEnterCounter++;
|
||||
//jsonWriteInt(configOptionJson, _key + "_num", dhtEnterCounter);
|
||||
|
||||
jsonWriteStr(configOptionJson, _key + "_map", _map);
|
||||
jsonWriteStr(configOptionJson, _key + "_с", _c);
|
||||
}
|
||||
|
||||
void SensorDhtRead(String key) {
|
||||
void SensorDhtReadTemp(String key) {
|
||||
//to do если надо будет читать несколько dht
|
||||
//int cnt = jsonReadInt(configOptionJson, key + "_num");
|
||||
float value;
|
||||
byte num = sensors.getDS18Count();
|
||||
sensors.requestTemperatures();
|
||||
|
||||
int cnt = jsonReadInt(configOptionJson, key + "_num");
|
||||
|
||||
for (byte i = 0; i < num; i++) {
|
||||
if (i == cnt) {
|
||||
value = sensors.getTempCByIndex(i);
|
||||
static int counter;
|
||||
if (dht.getStatus() != 0 && counter < 5) {
|
||||
counter++;
|
||||
//return;
|
||||
} else {
|
||||
counter = 0;
|
||||
value = dht.getTemperature();
|
||||
if (String(value) != "nan") {
|
||||
//value = this->mapping(key, value);
|
||||
float valueFl = this->correction(key, value);
|
||||
eventGen(key, "");
|
||||
jsonWriteStr(configLiveJson, key, String(valueFl));
|
||||
MqttClient::publishStatus(key, String(valueFl));
|
||||
Serial.println("[I] sensor '" + key + "' data: " + String(valueFl));
|
||||
} else {
|
||||
Serial.println("[E] sensor '" + key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SensorDhtReadHum(String key) {
|
||||
//to do если надо будет читать несколько dht
|
||||
//int cnt = jsonReadInt(configOptionJson, key + "_num");
|
||||
float value;
|
||||
static int counter;
|
||||
if (dht.getStatus() != 0 && counter < 5) {
|
||||
counter++;
|
||||
//return;
|
||||
} else {
|
||||
counter = 0;
|
||||
value = dht.getHumidity();
|
||||
if (String(value) != "nan") {
|
||||
//value = this->mapping(key, value);
|
||||
float valueFl = this->correction(key, value);
|
||||
eventGen(key, "");
|
||||
jsonWriteStr(configLiveJson, key, String(valueFl));
|
||||
MqttClient::publishStatus(key, String(valueFl));
|
||||
Serial.println("[I] sensor '" + key + "' data: " + String(valueFl));
|
||||
} else {
|
||||
Serial.println("[E] sensor '" + key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,4 +25,9 @@ extern void ultrasonicCm();
|
||||
extern void ultrasonicReading();
|
||||
|
||||
extern void dallasTemp();
|
||||
extern void dallasReading();
|
||||
extern void dallasReading();
|
||||
|
||||
extern void dhtTemp();
|
||||
extern void dhtReadingTemp();
|
||||
extern void dhtHum();
|
||||
extern void dhtReadingHum();
|
||||
Reference in New Issue
Block a user