Write loglines only every 60 seconds

Thu, 19 Jun 2014 15:47:16 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 19 Jun 2014 15:47:16 +0200
changeset 64
2431965e8a8c
parent 63
07802719f63d
child 65
a08a1fce439e

Write loglines only every 60 seconds

thermferm/thermferm.c file | annotate | diff | comparison | revisions
--- a/thermferm/thermferm.c	Thu Jun 19 14:32:33 2014 +0200
+++ b/thermferm/thermferm.c	Thu Jun 19 15:47:16 2014 +0200
@@ -263,8 +263,9 @@
 int server(void)
 {
     char                buf[1024];
-    w1_therm		*tmp1, *old1;
-    rc_switch		*tmp2, *old2;
+    time_t		now, last = (time_t)0;
+    w1_therm		*tmp1;
+    rc_switch		*tmp2;
     int			rc, run = 1, temp;
 
     if (lockprog((char *)"thermferm")) {
@@ -311,10 +312,8 @@
 	    tmp1->update = FALSE;
 	    lcdupdate = TRUE;
 	}
-	old1 = tmp1->next;
-	tmp1 = old1;
-	old2 = tmp2->next;
-	tmp2 = old2;
+	tmp1 = tmp1->next;
+	tmp2 = tmp2->next;
 	if (((tmp1->lastval / 100) < (tempB - 5)) && (coolerB == 1)) {
 	    coolerB = 0;
 	    syslog(LOG_NOTICE, "Temperature B is %.1f, switched cooler off", (tmp1->lastval / 1000.0));
@@ -338,14 +337,23 @@
 	    snprintf(buf, 16, "%5.2f %cC %c %s            ", tmp1->lastval / 1000.0, 0xdf, coolerA ? '-' : ' ', tmp1->alias);
 	    mb_lcdPuts(lcdHandle, buf);
 	    temp = tmp1->lastval;
-	    old1 = tmp1->next;
-	    tmp1 = old1;
+	    tmp1 = tmp1->next;
 	    lcdPosition(lcdHandle, 0, 1);
 	    snprintf(buf, 16, "%5.2f %cC %c %s            ", tmp1->lastval / 1000.0, 0xdf, coolerB ? '-' : ' ', tmp1->alias);
 	    mb_lcdPuts(lcdHandle, buf);
-	    snprintf(buf, 1023, "%.2f,%s,%.2f,%s", temp / 1000.0, coolerA ? (char *)"on" : (char *)"off",
+	}
+
+	now = time(NULL);
+	if (((int)now - (int)last) > 60) {
+	    last = now;
+	    tmp1 = Config.w1therms;
+	    temp = tmp1->lastval;
+	    tmp1 = tmp1->next;
+	    if (temp && tmp1->lastval && run) {
+	    	snprintf(buf, 1023, "%.2f,%s,%.2f,%s", temp / 1000.0, coolerA ? (char *)"on" : (char *)"off",
 			    			 tmp1->lastval / 1000.0, coolerB ? (char *)"on" : (char *)"off");
-	    logger((char *)"thermferm.log", (char *)"thermferm", buf);
+	    	logger((char *)"thermferm.log", (char *)"thermferm", buf);
+	    }
 	}
 	usleep(100000);
 

mercurial