# HG changeset patch # User Michiel Broek # Date 1556444310 -7200 # Node ID 504463dad07deb727e136844d4e89ace80b182d6 # Parent 326cf2982eeee801c5477c84b528f68634dedaef Changed 1-wire DS18B20 sensor error check. diff -r 326cf2982eee -r 504463dad07d thermferm/devices.c --- a/thermferm/devices.c Sat Apr 27 21:07:00 2019 +0200 +++ b/thermferm/devices.c Sun Apr 28 11:38:30 2019 +0200 @@ -791,14 +791,20 @@ #ifdef HAVE_WIRINGPI_H piLock(LOCK_DEVICES); #endif - device->value = temp; - device->timestamp = time(NULL); - device->present = DEVPRESENT_YES; + if (temp < -125000) { + syslog(LOG_NOTICE, "sensor %s value error '%d`", device->address, temp); + syslog(LOG_NOTICE, " %s", line1); + device->present = DEVPRESENT_ERROR; + } else { + device->value = temp; + device->timestamp = time(NULL); + device->present = DEVPRESENT_YES; + } #ifdef HAVE_WIRINGPI_H piUnlock(LOCK_DEVICES); #endif } - if ((temp == 85000) || (temp < -125000)) { + if (temp == 85000) { syslog(LOG_NOTICE, "sensor %s value error '%d`", device->address, temp); } } else { @@ -905,35 +911,34 @@ case DEVTYPE_DHT: /* * Make sure we don't read the sensor within 2 seconds. - * But we use 20 seconds interval. + * But we use 30 seconds interval. */ now = time(NULL); - if ((int)(now - dht11_last) > 20) { + if ((int)(now - dht11_last) > 30) { dht11_pin = device->gpiopin; dht11Read(); dht11_last = now; - // } - if (device->subdevice == 0) { - piLock(LOCK_DEVICES); - if (dht11_valid) { - device->value = dht11_temperature * 1000; - device->timestamp = time(NULL); - device->present = DEVPRESENT_YES; - } else { - device->present = DEVPRESENT_ERROR; + if (device->subdevice == 0) { + piLock(LOCK_DEVICES); + if (dht11_valid) { + device->value = dht11_temperature * 1000; + device->timestamp = time(NULL); + device->present = DEVPRESENT_YES; + } else { + device->present = DEVPRESENT_ERROR; + } + piUnlock(LOCK_DEVICES); + } else if (device->subdevice == 1) { + piLock(LOCK_DEVICES); + if (dht11_valid) { + device->value = dht11_humidity * 1000; + device->timestamp = time(NULL); + device->present = DEVPRESENT_YES; + } else { + device->present = DEVPRESENT_ERROR; + } + piUnlock(LOCK_DEVICES); } - piUnlock(LOCK_DEVICES); - } else if (device->subdevice == 1) { - piLock(LOCK_DEVICES); - if (dht11_valid) { - device->value = dht11_humidity * 1000; - device->timestamp = time(NULL); - device->present = DEVPRESENT_YES; - } else { - device->present = DEVPRESENT_ERROR; - } - piUnlock(LOCK_DEVICES); - } } break;