38 |
38 |
39 int dht11_pin = -1; |
39 int dht11_pin = -1; |
40 int dht11_temperature = -1; |
40 int dht11_temperature = -1; |
41 int dht11_humidity = -1; |
41 int dht11_humidity = -1; |
42 int dht11_valid = FALSE; |
42 int dht11_valid = FALSE; |
|
43 time_t dht11_last = (time_t)0; |
43 |
44 |
44 |
45 |
45 static uint8_t sizecvt(const int read_value) { |
46 static uint8_t sizecvt(const int read_value) { |
46 /* |
47 /* |
47 * digitalRead() and friends from wiringpi are defined as returning a value |
48 * digitalRead() and friends from wiringpi are defined as returning a value |
403 { |
404 { |
404 devices_list *device; |
405 devices_list *device; |
405 char *addr = NULL, line[60], *p = NULL; |
406 char *addr = NULL, line[60], *p = NULL; |
406 FILE *fp; |
407 FILE *fp; |
407 int temp, rc; |
408 int temp, rc; |
|
409 time_t now; |
408 |
410 |
409 syslog(LOG_NOTICE, "Thread my_devices_loop started"); |
411 syslog(LOG_NOTICE, "Thread my_devices_loop started"); |
410 |
412 |
411 /* |
413 /* |
412 * Loop forever until the external shutdown variable is set. |
414 * Loop forever until the external shutdown variable is set. |
467 } |
469 } |
468 break; |
470 break; |
469 |
471 |
470 #ifdef HAVE_WIRINGPI_H |
472 #ifdef HAVE_WIRINGPI_H |
471 case DEVTYPE_DHT: |
473 case DEVTYPE_DHT: |
472 if (device->subdevice == 0) { |
474 /* |
|
475 * Make sure we don't read the sensor withing 2 seconds. |
|
476 */ |
|
477 now = time(NULL); |
|
478 if ((int)(now - dht11_last) > 2) { |
473 dht11_pin = device->gpiopin; |
479 dht11_pin = device->gpiopin; |
474 dht11Read(); |
480 dht11Read(); |
|
481 dht11_last = now; |
|
482 } |
|
483 if (device->subdevice == 0) { |
475 if (dht11_valid) { |
484 if (dht11_valid) { |
476 device->value = dht11_temperature * 1000; |
485 device->value = dht11_temperature * 1000; |
477 device->timestamp = time(NULL); |
486 device->timestamp = time(NULL); |
478 device->present = DEVPRESENT_YES; |
487 device->present = DEVPRESENT_YES; |
479 } else { |
488 } else { |