# HG changeset patch # User Michiel Broek # Date 1407777452 -7200 # Node ID 382938c5fce21bf134cbd2f7314ebd32412d9a75 # Parent ae720212accce3f1bbb583743ef5d0c881d30042 Make sure we don't read the DHT11 within 2 seconds. diff -r ae720212accc -r 382938c5fce2 thermferm/devices.c --- a/thermferm/devices.c Mon Aug 11 18:38:57 2014 +0200 +++ b/thermferm/devices.c Mon Aug 11 19:17:32 2014 +0200 @@ -40,6 +40,7 @@ int dht11_temperature = -1; int dht11_humidity = -1; int dht11_valid = FALSE; +time_t dht11_last = (time_t)0; static uint8_t sizecvt(const int read_value) { @@ -405,6 +406,7 @@ char *addr = NULL, line[60], *p = NULL; FILE *fp; int temp, rc; + time_t now; syslog(LOG_NOTICE, "Thread my_devices_loop started"); @@ -469,9 +471,16 @@ #ifdef HAVE_WIRINGPI_H case DEVTYPE_DHT: - if (device->subdevice == 0) { + /* + * Make sure we don't read the sensor withing 2 seconds. + */ + now = time(NULL); + if ((int)(now - dht11_last) > 2) { dht11_pin = device->gpiopin; dht11Read(); + dht11_last = now; + } + if (device->subdevice == 0) { if (dht11_valid) { device->value = dht11_temperature * 1000; device->timestamp = time(NULL);