text: #include <DHT.h>
  #include "logging.h"
  #define DHTTYPE DHT22
  #define DHTPIN  2
  const int DHT_DECIMALS = 1;
  
  // Initialize DHT sensor
  // NOTE: For working with a faster than ATmega328p 16 MHz Arduino chip, like an ESP8266,
  // you need to increase the threshold for cycle counts considered a 1 or 0.
  // You can do this by passing a 3rd parameter for this threshold.  It's a bit
  // of fiddling to find the right value, but in general the faster the CPU the
  // higher the value.  The default for a 16mhz AVR is a value of 6.  For an
  // Arduino Due that runs at 84mhz a value of 30 works.
  // This is for the ESP8266 processor on ESP-01 
  DHT dht(DHTPIN, DHTTYPE, 11); // 11 works fine for ESP8266
   
  float humidity, temp_c;  // Values read from sensor
  
  // Generally, you should use "unsigned long" for variables that hold time
  unsigned long previousMillis = 0;        // will store last temp was read
  const long interval = 2000;              // interval at which to read sensor
  long lastRead = 0;
  bool gettemperature() {
    // Wait at least 2 seconds seconds between measurements.
    // if the difference between the current time and last time you read
    // the sensor is bigger than the interval you set, read the sensor
    // Works better than delay for things happening elsewhere also
    unsigned long currentMillis = millis();
   
    if(currentMillis - previousMillis < interval) {
      logWarning("Temperature was read too fast, can only be read every 2 seconds");
      return false;
    }
    // save the last time you read the sensor 
    previousMillis = currentMillis;   
  
    // Reading temperature for humidity takes about 250 milliseconds!
    // Sensor readings may also be up to 2 seconds 'old' (it's a very slow sensor)
    humidity = dht.readHumidity();          // Read humidity (percent)
    temp_c = dht.readTemperature(false);     // Read temperature as Fahrenheit
    // Check if any reads failed and exit early (to try again).
    if (isnan(humidity) || isnan(temp_c)) {
      logError("Failed to read from DHT sensor!");
      return false;
    }
    else {
      lastRead= now();
      logDebug("Successfully read temperature values");
      return true;
    }
  }
  