bdbcfd25d4
And save them with mqtt
30 lines
525 B
C++
30 lines
525 B
C++
#ifdef CONFIG_ENABLE_DHT
|
|
#include "sensor_DHT.h"
|
|
int DHTSetup(int pin){
|
|
dht = new DHT(pin, DHTTYPE);
|
|
dht->begin();
|
|
return 0;
|
|
}
|
|
|
|
int DHTGetTempAndHumidity(float &t, float &h){
|
|
int ret = 0;
|
|
t = dht->readTemperature();
|
|
h = dht->readHumidity();
|
|
if(isnan(t)){
|
|
t = 0;
|
|
ret = -1;
|
|
}
|
|
if(isnan(h)){
|
|
h = 0;
|
|
ret = -1;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
bool DHTIsConnected(){
|
|
//No way to know if connected
|
|
//Check at least if initialized
|
|
return dht != NULL;
|
|
}
|
|
#endif
|