Domotique/WifiControlSensor/sensor_DHT.ino
Mathieu Maret bdbcfd25d4 DHT: get temp and humidity
And save them with mqtt
2016-04-07 15:26:01 +02:00

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