Domotique/WifiControlSensor/sensor_DHT.ino

29 lines
466 B
Arduino
Raw Normal View History

#ifdef CONFIG_ENABLE_DHT
#include "sensor_DHT.h"
int DHTSetup(int pin){
2016-07-08 01:02:01 +02:00
dht = new DHT(pin, DHTTYPE);
dht->begin();
return 0;
}
int DHTGetTempAndHumidity(float &t, float &h){
2016-06-01 00:36:14 +02:00
if(!DHTIsConnected())
goto err;
2016-07-08 01:02:01 +02:00
t = dht->readTemperature();
h = dht->readHumidity();
if(isnan(t) || isnan(h))
2016-06-01 00:36:14 +02:00
goto err;
return 0;
err:
t=0;
h=0;
2016-07-08 01:02:01 +02:00
return -1;
}
bool DHTIsConnected(){
2016-07-08 01:02:01 +02:00
//No way to know if connected
//Check at least if initialized
return dht != NULL;
}
#endif