thermometers/thermometers.c

changeset 145
1396350141cf
parent 144
3446371e0bdb
child 149
f019ea6a9d31
--- a/thermometers/thermometers.c	Tue Jul 29 20:42:02 2014 +0200
+++ b/thermometers/thermometers.c	Tue Jul 29 21:05:40 2014 +0200
@@ -109,7 +109,7 @@
 
     if (rdconfig((char *)"thermometers.conf")) {
 	fprintf(stderr, "Error reading configuration\n");
-	syslog(LOG_NOTICE, "halted");
+	syslog(LOG_NOTICE, "Error reading configuration, halted");
 	return 1;
     }
 
@@ -208,29 +208,15 @@
 
 int server(void)
 {
-    char                hostname[256], buf[1024];
-    int                 temp, rc = 0, deviation;
+    char                buf[1024];
+    int                 temp, rc = 0;
 #ifdef HAVE_WIRINGPI_H
     int			lcdupdate;
 #endif
-    w1_therm		*tmp1, *old1;
-    char		*device, *alias, line[60], *p = NULL;
+    w1_therm		*tmp1;
+    char		*device, line[60], *p = NULL;
     FILE		*fp;
 
-    /*
-     * Build MQTT id
-     */
-    hostname[0] = '\0';
-    gethostname(hostname, 256);
-    hostname[255] = '\0';
-
-    /*
-     * Initialise is complete, report our presence state
-     */
-#ifdef HAVE_WIRINGPI_H
-//    setBacklight(0);
-#endif
-
     if (debug)
 	fprintf(stdout, (char *)"Enter loop\n");
 
@@ -242,8 +228,7 @@
 	    /*
 	     * Here send our 1-wire sensors values
 	     */
-	    for (tmp1 = Config.w1therms; tmp1; tmp1 = old1) {
-		old1 = tmp1->next;
+	    for (tmp1 = Config.w1therms; tmp1; tmp1 = tmp1->next) {
 
 		/*
 		 * Build path and alias topic
@@ -253,13 +238,6 @@
 		device = xstrcat(device, (char *)"/");
 		device = xstrcat(device, tmp1->name);
 		device = xstrcat(device, (char *)"/w1_slave");
-		alias = xstrcpy((char *)"/raw/");
-		alias = xstrcat(alias, hostname);
-		alias = xstrcat(alias, (char *)"/thermometers/w1/");
-		alias = xstrcat(alias, tmp1->master);
-		alias = xstrcat(alias, (char *)"/");
-		alias = xstrcat(alias, tmp1->name);
-		alias = xstrcat(alias, (char *)"/temperature");
 
 		/*
 		 * Read sensor data
@@ -282,27 +260,6 @@
 			p = strtok(NULL, (char *)"=");
 			rc = sscanf(p, "%d", &temp);
 			if ((rc == 1) && (tmp1->lastval != temp)) {
-			    /*
-			     * It is possible to have read errors or extreme values.
-			     * This can happen with bad connections so we compare the
-			     * value with the previous one. If the difference is too
-			     * much, we don't send that value. That also means that if
-			     * the next value is ok again, it will be marked invalid too.
-			     * Maximum error is 20 degrees for now.
-			     */
-			    deviation = 20000;
-			    if ((tmp1->lastval == 0) ||
-				(tmp1->lastval && (temp > (tmp1->lastval - deviation)) && (temp < (tmp1->lastval + deviation)))) {
-			    	/*
-			    	 * Temperature is changed and valid, update and publish this.
-			    	 */
-			    	sprintf(buf, "%.1f", temp / 1000.0);
-			    } else {
-				syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, tmp1->lastval, temp);
-				if (debug) {
-				    fprintf(stdout, "deviation error deviation=%d, old=%d new=%d\n", deviation, tmp1->lastval, temp);
-				}
-			    }
 			    tmp1->lastval = temp;
 #ifdef HAVE_WIRINGPI_H
 			    lcdupdate = TRUE;
@@ -321,8 +278,6 @@
 
 		free(device);
 		device = NULL;
-		free(alias);
-		alias = NULL;
 	    }
 
 #ifdef HAVE_WIRINGPI_H
@@ -331,8 +286,7 @@
 		tmp1 = Config.w1therms;
 		snprintf(buf, 16, "%5.1f %cC %s            ", tmp1->lastval / 1000.0, 0xdf, tmp1->alias);
 		lcdPuts(lcdHandle, buf);
-		old1 = tmp1->next;
-		tmp1 = old1;
+		tmp1 = tmp1->next;
 		lcdPosition(lcdHandle, 0, 1);
 		snprintf(buf, 16, "%5.1f %cC %s            ", tmp1->lastval / 1000.0, 0xdf, tmp1->alias);
 		lcdPuts(lcdHandle, buf);

mercurial