mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
переписан dht
This commit is contained in:
@@ -1,36 +0,0 @@
|
||||
//#pragma once
|
||||
//#include <Arduino.h>
|
||||
//
|
||||
//#include "Class/LineParsing.h"
|
||||
//#include "Global.h"
|
||||
//#include "items/SensorConvertingClass.h"
|
||||
//
|
||||
//class SensorAnalogClass : public SensorConvertingClass {
|
||||
// public:
|
||||
// SensorAnalogClass() : SensorConvertingClass(){};
|
||||
//
|
||||
// void SensorAnalogInit() {
|
||||
// jsonWriteStr(configOptionJson, _key + "_pin", _pin);
|
||||
// jsonWriteStr(configOptionJson, _key + "_map", _map);
|
||||
// jsonWriteStr(configOptionJson, _key + "_с", _c);
|
||||
// }
|
||||
//
|
||||
// int SensorAnalogRead(String key, String pin) {
|
||||
// int value;
|
||||
//#ifdef ESP32
|
||||
// int pinInt = pin.toInt();
|
||||
// value = analogRead(pinInt);
|
||||
//#endif
|
||||
//#ifdef ESP8266
|
||||
// value = analogRead(A0);
|
||||
//#endif
|
||||
// value = this->mapping(key, value);
|
||||
// float valueFl = this->correction(key, value);
|
||||
// eventGen2(key, String(valueFl));
|
||||
// jsonWriteStr(configLiveJson, key, String(valueFl));
|
||||
// publishStatus(key, String(valueFl));
|
||||
// SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl));
|
||||
// return value;
|
||||
// }
|
||||
//};
|
||||
//extern SensorAnalogClass mySensorAnalog;
|
||||
@@ -1,80 +1,80 @@
|
||||
#pragma once
|
||||
#include "Consts.h"
|
||||
#ifdef SensorDhtEnabled
|
||||
#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() {
|
||||
if (_type == "dht11") {
|
||||
dht.setup(_pin.toInt(), DHTesp::DHT11);
|
||||
}
|
||||
if (_type == "dht22") {
|
||||
dht.setup(_pin.toInt(), DHTesp::DHT22);
|
||||
}
|
||||
sensorReadingMap10sec += _key + ",";
|
||||
|
||||
//to do если надо будет читать несколько dht
|
||||
//dhtEnterCounter++;
|
||||
//jsonWriteInt(configOptionJson, _key + "_num", dhtEnterCounter);
|
||||
|
||||
jsonWriteStr(configOptionJson, _key + "_map", _map);
|
||||
jsonWriteStr(configOptionJson, _key + "_с", _c);
|
||||
}
|
||||
|
||||
void SensorDhtReadTemp(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.getTemperature();
|
||||
if (String(value) != "nan") {
|
||||
//value = this->mapping(key, value);
|
||||
float valueFl = this->correction(key, value);
|
||||
eventGen2(key, String(valueFl));
|
||||
jsonWriteStr(configLiveJson, key, String(valueFl));
|
||||
publishStatus(key, String(valueFl));
|
||||
SerialPrint("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);
|
||||
eventGen2(key, String(valueFl));
|
||||
jsonWriteStr(configLiveJson, key, String(valueFl));
|
||||
publishStatus(key, String(valueFl));
|
||||
SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl));
|
||||
} else {
|
||||
Serial.println("[E] sensor '" + key);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
extern SensorDhtClass mySensorDht;
|
||||
#endif
|
||||
//#pragma once
|
||||
//#include "Consts.h"
|
||||
//#ifdef SensorDhtEnabled
|
||||
//#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() {
|
||||
// if (_type == "dht11") {
|
||||
// dht.setup(_pin.toInt(), DHTesp::DHT11);
|
||||
// }
|
||||
// if (_type == "dht22") {
|
||||
// dht.setup(_pin.toInt(), DHTesp::DHT22);
|
||||
// }
|
||||
// sensorReadingMap10sec += _key + ",";
|
||||
//
|
||||
// //to do если надо будет читать несколько dht
|
||||
// //dhtEnterCounter++;
|
||||
// //jsonWriteInt(configOptionJson, _key + "_num", dhtEnterCounter);
|
||||
//
|
||||
// jsonWriteStr(configOptionJson, _key + "_map", _map);
|
||||
// jsonWriteStr(configOptionJson, _key + "_с", _c);
|
||||
// }
|
||||
//
|
||||
// void SensorDhtReadTemp(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.getTemperature();
|
||||
// if (String(value) != "nan") {
|
||||
// //value = this->mapping(key, value);
|
||||
// float valueFl = this->correction(key, value);
|
||||
// eventGen2(key, String(valueFl));
|
||||
// jsonWriteStr(configLiveJson, key, String(valueFl));
|
||||
// publishStatus(key, String(valueFl));
|
||||
// SerialPrint("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);
|
||||
// eventGen2(key, String(valueFl));
|
||||
// jsonWriteStr(configLiveJson, key, String(valueFl));
|
||||
// publishStatus(key, String(valueFl));
|
||||
// SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl));
|
||||
// } else {
|
||||
// Serial.println("[E] sensor '" + key);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//};
|
||||
//extern SensorDhtClass mySensorDht;
|
||||
//#endif
|
||||
63
include/items/vSensorDht.h
Normal file
63
include/items/vSensorDht.h
Normal file
@@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include <DHTesp.h>
|
||||
#include "Global.h"
|
||||
#include "GyverFilters.h"
|
||||
|
||||
extern DHTesp* dht;
|
||||
|
||||
class SensorDht;
|
||||
|
||||
typedef std::vector<SensorDht> MySensorDhtVector;
|
||||
|
||||
struct tmpParams {
|
||||
unsigned long currentMillis;
|
||||
unsigned long prevMillis;
|
||||
unsigned long difference;
|
||||
unsigned long interval;
|
||||
String key;
|
||||
unsigned int pin;
|
||||
int map1;
|
||||
int map2;
|
||||
int map3;
|
||||
int map4;
|
||||
float c;
|
||||
};
|
||||
|
||||
struct humParams {
|
||||
unsigned long currentMillis;
|
||||
unsigned long prevMillis;
|
||||
unsigned long difference;
|
||||
unsigned long interval;
|
||||
String key;
|
||||
unsigned int pin;
|
||||
int map1;
|
||||
int map2;
|
||||
int map3;
|
||||
int map4;
|
||||
float c;
|
||||
};
|
||||
|
||||
class SensorDht {
|
||||
public:
|
||||
SensorDht();
|
||||
~SensorDht();
|
||||
|
||||
void loopTmp();
|
||||
void loopHum();
|
||||
|
||||
void readTmp();
|
||||
void readHum();
|
||||
|
||||
void tmpInit(const tmpParams& tmpSet);
|
||||
void humInit(const humParams& humSet);
|
||||
|
||||
private:
|
||||
tmpParams _tmpSet;
|
||||
humParams _humSet;
|
||||
};
|
||||
|
||||
extern MySensorDhtVector* mySensorDht;
|
||||
|
||||
extern void dhtTmp();
|
||||
extern void dhtHum();
|
||||
Reference in New Issue
Block a user