

/* **********************************************************************
 *		PUCONTERM sensor module
 */
 

#include "sensor.h"

//
// the DHT object encapsules the DHT library object for the (single) DHT11 sensor
//
DHT dht(DHT11_PIN, DHTTYPE);

/* *****************************************************************************
 *  FUNCTION:       sensorDHTloop 
 *  DESCRIPTION:    reads DHT11 sensor: temperature and  relative humidity
 *                  to be called periodically with periods of >=2000ms
 */
void sensorDHTloop(int param) {
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);
  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    SERIAL_PRINTF("DHT Sensor loop %d; Failed to read from DHT sensor! humidity = %f, temperature/C = %f, temperature/F = %f\n",param,h,t,f);
    return;
  }
  SERIAL_PRINTF("DHT Sensor loop %d: humidity = %f, temperature/C = %f, temperature/F = %f\n",param,h,t,f);
}

void initSensor() {
  dht.begin();
  delay(3000);
  sensorDHTloop(9);
  addLoopScanner(15000,sensorDHTloop,0,"15000 seconds DHT sensor loop");
}
