# HG changeset patch # User Michiel Broek # Date 1399992396 -7200 # Node ID 8701b4dab77b425012a8cb4bfde064126a65d4ea # Parent f3c5ae78b746cdec8069f18e5452e4ed34a0b8e2 Don't block with a missing DHT11 sensor diff -r f3c5ae78b746 -r 8701b4dab77b lib/dht11.c --- a/lib/dht11.c Tue May 13 16:33:47 2014 +0200 +++ b/lib/dht11.c Tue May 13 16:46:36 2014 +0200 @@ -120,17 +120,20 @@ if ((counter == 255) && (j == 0)) { if (dht11_temperature != -1) { syslog(LOG_NOTICE, "dht11 sensor disappeared"); + } else { + syslog(LOG_NOTICE, "dht11 sensor not present"); } dht11_temperature = -1; dht11_humidity = -1; dht11_valid = false; - } else { + return; + } - /* - * check we read 40 bits (8bit x 5 ) + verify checksum in the last byte - * print it out if data is good - */ - if ((j >= 40) && (dht11_dat[4] == ((dht11_dat[0] + dht11_dat[1] + dht11_dat[2] + dht11_dat[3]) & 0xFF))) { + /* + * check we read 40 bits (8bit x 5 ) + verify checksum in the last byte + * print it out if data is good + */ + if ((j >= 40) && (dht11_dat[4] == ((dht11_dat[0] + dht11_dat[1] + dht11_dat[2] + dht11_dat[3]) & 0xFF))) { got_correct_data = 1; int h = dht11_dat[0] + dht11_dat[1]; @@ -144,12 +147,11 @@ dht11_temperature = t; dht11_humidity = h; dht11_valid = true; - } else { + } else { tries--; if (tries == 0) syslog(LOG_INFO, "dht11 data checksum was wrong 5 times"); usleep(100000); - } } } }