thermferm/devices.c

changeset 212
a76cbe676bf1
parent 209
c5b1dfd83e81
child 213
2317b8d644fa
equal deleted inserted replaced
211:81160e2e738c 212:a76cbe676bf1
178 178
179 for (device = Config.devices; device; device = device->next) { 179 for (device = Config.devices; device; device = device->next) {
180 if (strcmp(uuid, device->uuid) == 0) { 180 if (strcmp(uuid, device->uuid) == 0) {
181 /* 181 /*
182 * Execute command if different then the old value. But also 182 * Execute command if different then the old value. But also
183 * every 2 minutes because commands can get lost of devices were 183 * every 2 minutes because commands can have temporary
184 * disconnected, or with radio problems. 184 * disconnects, or have radio problems.
185 */ 185 */
186 if ((value != device->value) || (((int)now - (int)device->timestamp) > 120)) { 186 if ((value != device->value) || (((int)now - (int)device->timestamp) > 120)) {
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); 192 // usleep(10000);
193 snprintf(buf, 39, "%s,%d", device->address, value ? 1:0); 193 snprintf(buf, 39, "%s,%d", device->address, value ? 1:0);
194 for (i = 0; i < strlen(buf); i++) 194 for (i = 0; i < strlen(buf); i++)
195 if (buf[i] == '-') 195 if (buf[i] == '-')
196 buf[i] = ','; 196 buf[i] = ',';
197 rc = toggleSwitch(buf); 197 rc = toggleSwitch(buf);
198 syslog(LOG_NOTICE, "RC433 command %s rc=%d", buf, rc); 198 syslog(LOG_NOTICE, "RC433 command %s rc=%d", buf, rc);
199 if (debug) 199 if (debug)
200 fprintf(stdout, "RC433 command %s rc=%d\n", buf, rc); 200 fprintf(stdout, "RC433 command %s rc=%d\n", buf, rc);
201 usleep(50000); 201 // usleep(50000);
202 disableTransmit(); 202 disableTransmit();
203 } 203 device->value = value;
204 device->value = value; 204 device->timestamp = time(NULL);
205 device->timestamp = time(NULL); 205 return rc;
206 return rc; 206 }
207 207
208 if ((device->type == DEVTYPE_GPIO) && (device->gpiopin != -1) && (device->present == DEVPRESENT_YES)) { 208 if ((device->type == DEVTYPE_GPIO) && (device->gpiopin != -1) && (device->present == DEVPRESENT_YES)) {
209 209
210 } 210 }
211 #endif 211 #endif
496 #endif 496 #endif
497 497
498 default: 498 default:
499 break; 499 break;
500 } 500 }
501 } 501
502 usleep(10000); 502 /*
503 * Delay a bit after procesing a device.
504 */
505 usleep(10000);
506 }
503 } 507 }
504 508
505 syslog(LOG_NOTICE, "Thread my_devices_loop stopped"); 509 syslog(LOG_NOTICE, "Thread my_devices_loop stopped");
506 if (debug) 510 if (debug)
507 fprintf(stdout, "Thread my_devices_loop stopped\n"); 511 fprintf(stdout, "Thread my_devices_loop stopped\n");

mercurial