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 |