--- a/thermferm/devices.c Fri Apr 05 16:19:39 2024 +0200 +++ b/thermferm/devices.c Fri Apr 05 19:30:41 2024 +0200 @@ -246,7 +246,7 @@ return 0; now = time(NULL); - pthread_mutex_lock(&mutexes[LOCK_DEVICES]); +// pthread_mutex_lock(&mutexes[LOCK_DEVICES]); for (device = Config.devices; device; device = device->next) { if (! strcmp(uuid, device->uuid)) { @@ -273,15 +273,15 @@ for (i = 0; i < strlen(buf); i++) if (buf[i] == '-') buf[i] = ','; - pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); +// pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); enableTransmit(device->gpiopin); rc = toggleSwitch(buf); disableTransmit(); - pthread_mutex_lock(&mutexes[LOCK_DEVICES]); +// pthread_mutex_lock(&mutexes[LOCK_DEVICES]); syslog(LOG_NOTICE, "RC433 command %s rc=%d", buf, rc); device->value = value; device->timestamp = time(NULL); - pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); +// pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); return rc; } @@ -314,10 +314,10 @@ if ((write_w1(device->address, (char *)"output", output)) == 0) { syslog(LOG_NOTICE, "DS2413 PIO%c value=%d (%s)", (device->subdevice == 0) ? 'A' : 'B', (value == 0) ? 0 : 1, device->comment); - pthread_mutex_lock(&mutexes[LOCK_DEVICES]); +// pthread_mutex_lock(&mutexes[LOCK_DEVICES]); device->value = (value == 0) ? 0 : 1; device->timestamp = time(NULL); - pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); +// pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); } } } @@ -344,13 +344,13 @@ } #endif } else { - pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); +// pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); return 0; } // if ((test_value != my_value) || (((int)now - (int)my_timestamp) >= 120)) } // if (! strcmp(uuid, device->uuid)) } // for (device = Config.devices; device; device = device->next) - pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); +// pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); return 0; } @@ -367,7 +367,7 @@ if (uuid == NULL) return 0; - pthread_mutex_lock(&mutexes[LOCK_DEVICES]); +// pthread_mutex_lock(&mutexes[LOCK_DEVICES]); for (device = Config.devices; device; device = device->next) { if (! strcmp(uuid, device->uuid)) { @@ -377,13 +377,13 @@ } else { tmp = 0; } - pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); +// pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); *value = tmp; return present; } } - pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); +// pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); return DEVPRESENT_NO; } @@ -723,15 +723,15 @@ #endif // char *addr = NULL, line1[60], line2[60], *p = NULL; // FILE *fp; - int rc, found; + int found; time_t now; my_devices_state = 1; syslog(LOG_NOTICE, "Thread my_devices_loop started"); #ifdef HAVE_WIRINGPI_H - if ((rc = piHiPri(50))) - syslog(LOG_NOTICE, "my_devices_loop: piHiPri(50) rc=%d", rc); +// if ((rc = piHiPri(50))) +// syslog(LOG_NOTICE, "my_devices_loop: piHiPri(50) rc=%d", rc); #endif dht11_next = time(NULL); @@ -773,6 +773,7 @@ if (my_devices_shutdown) break; +//syslog(LOG_NOTICE, "device type %d address %s-%d comment %s", device->type, device->address, device->subdevice, device->comment); switch (device->type) { case DEVTYPE_W1: @@ -788,7 +789,7 @@ found = FALSE; for (dev_w1 = w1_devices; dev_w1; dev_w1 = dev_w1->next) { if (strcmp(device->address, dev_w1->address) == 0) { - syslog(LOG_NOTICE, "sensor %s value %d", dev_w1->address, dev_w1->value); +// syslog(LOG_NOTICE, "sensor %s value %d", dev_w1->address, dev_w1->value); found = TRUE; if ((dev_w1->value == -1) || (dev_w1->value < -55000)) { syslog(LOG_NOTICE, "sensor %s value error %d", device->address, dev_w1->value); @@ -804,9 +805,9 @@ if (found == FALSE) { if (device->present != DEVPRESENT_NO) { syslog(LOG_NOTICE, "sensor %s is missing", device->address); - pthread_mutex_lock(&mutexes[LOCK_DEVICES]); +// pthread_mutex_lock(&mutexes[LOCK_DEVICES]); device->present = DEVPRESENT_NO; - pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); +// pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); } } @@ -825,16 +826,16 @@ if (device->subdevice == 0) { /* Read once during subdevice 0 */ dht11Read(device->address); - pthread_mutex_lock(&mutexes[LOCK_DEVICES]); +// pthread_mutex_lock(&mutexes[LOCK_DEVICES]); device->present = dht11_state; if (dht11_state == DEVPRESENT_YES) { device->value = dht11_temperature; device->timestamp = time(NULL); } - pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); +// pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); } else if (device->subdevice == 1) { /* Data already present, valid or not. */ - pthread_mutex_lock(&mutexes[LOCK_DEVICES]); +// pthread_mutex_lock(&mutexes[LOCK_DEVICES]); device->present = dht11_state; if (dht11_state == DEVPRESENT_YES) { device->value = dht11_humidity; @@ -843,7 +844,7 @@ } else { dht11_next = now + 1; } - pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); +// pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); } } break; @@ -851,18 +852,18 @@ #ifdef HAVE_WIRINGPI_H case DEVTYPE_GPIO: if (device->direction == DEVDIR_IN_BIN) { - pthread_mutex_lock(&mutexes[LOCK_DEVICES]); +// pthread_mutex_lock(&mutexes[LOCK_DEVICES]); device->value = digitalRead(device->gpiopin); device->offset = 0; device->timestamp = time(NULL); - pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); +// pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); } break; #endif #ifdef USE_SIMULATOR case DEVTYPE_SIM: - pthread_mutex_lock(&mutexes[LOCK_DEVICES]); +// pthread_mutex_lock(&mutexes[LOCK_DEVICES]); if (Config.simulators) { simulator = Config.simulators; if (device->subdevice == 0) { @@ -882,7 +883,7 @@ device->timestamp = time(NULL); } } - pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); +// pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); break; #endif default: