thermferm/devices.c

changeset 185
4f34271cf1e7
parent 181
4099412fca09
child 187
3c8bf18fdf42
--- a/thermferm/devices.c	Tue Aug 05 16:24:17 2014 +0200
+++ b/thermferm/devices.c	Tue Aug 05 21:33:06 2014 +0200
@@ -38,16 +38,21 @@
     devices_list	*device;
     char		buf[40];
     int			i, rc;
+    time_t		now;
 
     if (uuid == NULL)
 	return 0;
 
-    if (debug)
-	fprintf(stdout, "device_out(%s, %d)\n", uuid, value);
+    now = time(NULL);
 
     for (device = Config.devices; device; device = device->next) {
 	if (strcmp(uuid, device->uuid) == 0) {
-	    if (value != device->value) {
+	    /*
+	     * Execute command if different then the old value. But also
+	     * every 2 minutes because commands can get lost of devices were
+	     * disconnected, or with radio problems.
+	     */
+	    if ((value != device->value) || (((int)now - (int)device->timestamp) > 120)) {
 
 #ifdef HAVE_WIRINGPI_H
 		rc = 0;
@@ -81,6 +86,7 @@
 	    }
 	}
     }
+
     return 0;
 }	   
 

mercurial