thermferm/devices.c

changeset 213
2317b8d644fa
parent 212
a76cbe676bf1
child 215
5ad534c79a22
equal deleted inserted replaced
212:a76cbe676bf1 213:2317b8d644fa
55 } 55 }
56 56
57 57
58 58
59 /* 59 /*
60 * DHT11 sensor read. This should be used in a thread loop. 60 * DHT11 sensor read.
61 */ 61 */
62 void dht11Read(void) { 62 void dht11Read(void) {
63 int tries = 5; 63 int tries = 5;
64 unsigned short got_correct_data = 0; 64 unsigned short got_correct_data = 0;
65 65
187 187
188 #ifdef HAVE_WIRINGPI_H 188 #ifdef HAVE_WIRINGPI_H
189 rc = 0; 189 rc = 0;
190 if ((device->type == DEVTYPE_RC433) && (device->gpiopin != -1) && (device->present == DEVPRESENT_YES)) { 190 if ((device->type == DEVTYPE_RC433) && (device->gpiopin != -1) && (device->present == DEVPRESENT_YES)) {
191 enableTransmit(device->gpiopin); 191 enableTransmit(device->gpiopin);
192 // usleep(10000);
193 snprintf(buf, 39, "%s,%d", device->address, value ? 1:0); 192 snprintf(buf, 39, "%s,%d", device->address, value ? 1:0);
194 for (i = 0; i < strlen(buf); i++) 193 for (i = 0; i < strlen(buf); i++)
195 if (buf[i] == '-') 194 if (buf[i] == '-')
196 buf[i] = ','; 195 buf[i] = ',';
197 rc = toggleSwitch(buf); 196 rc = toggleSwitch(buf);
198 syslog(LOG_NOTICE, "RC433 command %s rc=%d", buf, rc); 197 syslog(LOG_NOTICE, "RC433 command %s rc=%d", buf, rc);
199 if (debug) 198 if (debug)
200 fprintf(stdout, "RC433 command %s rc=%d\n", buf, rc); 199 fprintf(stdout, "RC433 command %s rc=%d\n", buf, rc);
201 // usleep(50000);
202 disableTransmit(); 200 disableTransmit();
203 device->value = value; 201 device->value = value;
204 device->timestamp = time(NULL); 202 device->timestamp = time(NULL);
205 return rc; 203 return rc;
206 } 204 }
407 char *addr = NULL, line[60], *p = NULL; 405 char *addr = NULL, line[60], *p = NULL;
408 FILE *fp; 406 FILE *fp;
409 int temp, rc; 407 int temp, rc;
410 408
411 syslog(LOG_NOTICE, "Thread my_devices_loop started"); 409 syslog(LOG_NOTICE, "Thread my_devices_loop started");
412 if (debug)
413 fprintf(stdout, "Thread my_devices_loop started\n");
414 410
415 /* 411 /*
416 * Loop forever until the external shutdown variable is set. 412 * Loop forever until the external shutdown variable is set.
417 */ 413 */
418 for (;;) { 414 for (;;) {
505 usleep(10000); 501 usleep(10000);
506 } 502 }
507 } 503 }
508 504
509 syslog(LOG_NOTICE, "Thread my_devices_loop stopped"); 505 syslog(LOG_NOTICE, "Thread my_devices_loop stopped");
510 if (debug)
511 fprintf(stdout, "Thread my_devices_loop stopped\n");
512
513 return 0; 506 return 0;
514 } 507 }
515 508
516 509
517 510

mercurial