thermferm/devices.c

changeset 586
504463dad07d
parent 585
326cf2982eee
child 587
b8580eedfcc7
equal deleted inserted replaced
585:326cf2982eee 586:504463dad07d
789 rc = sscanf(p, "%d", &temp); 789 rc = sscanf(p, "%d", &temp);
790 if ((rc == 1) && (device->value != temp)) { 790 if ((rc == 1) && (device->value != temp)) {
791 #ifdef HAVE_WIRINGPI_H 791 #ifdef HAVE_WIRINGPI_H
792 piLock(LOCK_DEVICES); 792 piLock(LOCK_DEVICES);
793 #endif 793 #endif
794 device->value = temp; 794 if (temp < -125000) {
795 device->timestamp = time(NULL); 795 syslog(LOG_NOTICE, "sensor %s value error '%d`", device->address, temp);
796 device->present = DEVPRESENT_YES; 796 syslog(LOG_NOTICE, " %s", line1);
797 device->present = DEVPRESENT_ERROR;
798 } else {
799 device->value = temp;
800 device->timestamp = time(NULL);
801 device->present = DEVPRESENT_YES;
802 }
797 #ifdef HAVE_WIRINGPI_H 803 #ifdef HAVE_WIRINGPI_H
798 piUnlock(LOCK_DEVICES); 804 piUnlock(LOCK_DEVICES);
799 #endif 805 #endif
800 } 806 }
801 if ((temp == 85000) || (temp < -125000)) { 807 if (temp == 85000) {
802 syslog(LOG_NOTICE, "sensor %s value error '%d`", device->address, temp); 808 syslog(LOG_NOTICE, "sensor %s value error '%d`", device->address, temp);
803 } 809 }
804 } else { 810 } else {
805 syslog(LOG_NOTICE, "sensor %s CRC error '%s`", device->address, line1); 811 syslog(LOG_NOTICE, "sensor %s CRC error '%s`", device->address, line1);
806 #ifdef HAVE_WIRINGPI_H 812 #ifdef HAVE_WIRINGPI_H
903 909
904 #ifdef HAVE_WIRINGPI_H 910 #ifdef HAVE_WIRINGPI_H
905 case DEVTYPE_DHT: 911 case DEVTYPE_DHT:
906 /* 912 /*
907 * Make sure we don't read the sensor within 2 seconds. 913 * Make sure we don't read the sensor within 2 seconds.
908 * But we use 20 seconds interval. 914 * But we use 30 seconds interval.
909 */ 915 */
910 now = time(NULL); 916 now = time(NULL);
911 if ((int)(now - dht11_last) > 20) { 917 if ((int)(now - dht11_last) > 30) {
912 dht11_pin = device->gpiopin; 918 dht11_pin = device->gpiopin;
913 dht11Read(); 919 dht11Read();
914 dht11_last = now; 920 dht11_last = now;
915 // } 921 if (device->subdevice == 0) {
916 if (device->subdevice == 0) { 922 piLock(LOCK_DEVICES);
917 piLock(LOCK_DEVICES); 923 if (dht11_valid) {
918 if (dht11_valid) { 924 device->value = dht11_temperature * 1000;
919 device->value = dht11_temperature * 1000; 925 device->timestamp = time(NULL);
920 device->timestamp = time(NULL); 926 device->present = DEVPRESENT_YES;
921 device->present = DEVPRESENT_YES; 927 } else {
922 } else { 928 device->present = DEVPRESENT_ERROR;
923 device->present = DEVPRESENT_ERROR; 929 }
930 piUnlock(LOCK_DEVICES);
931 } else if (device->subdevice == 1) {
932 piLock(LOCK_DEVICES);
933 if (dht11_valid) {
934 device->value = dht11_humidity * 1000;
935 device->timestamp = time(NULL);
936 device->present = DEVPRESENT_YES;
937 } else {
938 device->present = DEVPRESENT_ERROR;
939 }
940 piUnlock(LOCK_DEVICES);
924 } 941 }
925 piUnlock(LOCK_DEVICES);
926 } else if (device->subdevice == 1) {
927 piLock(LOCK_DEVICES);
928 if (dht11_valid) {
929 device->value = dht11_humidity * 1000;
930 device->timestamp = time(NULL);
931 device->present = DEVPRESENT_YES;
932 } else {
933 device->present = DEVPRESENT_ERROR;
934 }
935 piUnlock(LOCK_DEVICES);
936 }
937 } 942 }
938 break; 943 break;
939 944
940 case DEVTYPE_GPIO: 945 case DEVTYPE_GPIO:
941 if (device->direction == DEVDIR_IN_BIN) { 946 if (device->direction == DEVDIR_IN_BIN) {

mercurial