Better log output for web graphs. Webgraphs can now display heater and cooler usage.

Mon, 25 Aug 2014 20:47:30 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 25 Aug 2014 20:47:30 +0200
changeset 266
07819a7ad3c1
parent 265
63a003914b72
child 267
a84792cab21c

Better log output for web graphs. Webgraphs can now display heater and cooler usage.

thermferm/server.c file | annotate | diff | comparison | revisions
www-thermferm/getlog.php file | annotate | diff | comparison | revisions
www-thermferm/liveview.php file | annotate | diff | comparison | revisions
--- a/thermferm/server.c	Sun Aug 24 23:01:32 2014 +0200
+++ b/thermferm/server.c	Mon Aug 25 20:47:30 2014 +0200
@@ -585,8 +585,8 @@
  */
 int cmd_list(char *buf)
 {
-    char		*opt, *param, *filename, q[2], buffer[256], *copy = NULL;
-    char		*mode_o = NULL, *mode_n, *target_o = NULL, *target_n, *heater_o = NULL, *heater_n, *cooler_o = NULL, *cooler_n;
+    char		*opt, *param, *filename, q[5], buffer[256], *copy = NULL;
+    char		*mode_o = NULL, *mode_n, *heater_o = NULL, *heater_n, *cooler_o = NULL, *cooler_n;
     units_list		*unit;
     FILE		*fp;
 
@@ -612,7 +612,7 @@
 	    return 1;
 	}
 
-	q[0] = q[1] = 'a';
+	q[0] = q[1] = q[2] = q[3] = q[4] = 'a';
 	for (unit = Config.units; unit; unit = unit->next) {
 	    if (strcmp(param, unit->uuid) == 0)
 		break;
@@ -633,31 +633,32 @@
 		copy = xstrcpy(buffer);
 		mode_n = strtok(buffer, ",\0");
 		mode_n = strtok(NULL, ",\0");
-		target_n = strtok(NULL, ",\0");	/* skip air_temp	*/
-		target_n = strtok(NULL, ",\0");	/* skip beer temp	*/
-		target_n = strtok(NULL, ",\0");
+		heater_n = strtok(NULL, ",\0");	/* skip air_temp	*/
+		heater_n = strtok(NULL, ",\0");	/* skip beer temp	*/
+		heater_n = strtok(NULL, ",\0"); /* skip target temp	*/
 		heater_n = strtok(NULL, ",\0");
 		cooler_n = strtok(NULL, ",\0");
 
 		if (strncmp(mode_n, (char *)"Mode", 4)) {
-		    if ((q[0] != buffer[11]) || (q[1] != buffer[12])) {
+		    /*
+		     * Output a line each 10 minutes or if something changes.
+		     */
+		    if ((q[0] != buffer[11]) || (q[1] != buffer[12]) || (q[3] != buffer[14])) {
 			q[0] = buffer[11];
 			q[1] = buffer[12];
+			q[2] = buffer[13];
+			q[3] = buffer[14];
 		    	srv_send(copy);
-		    } else if ((mode_o && strcmp(mode_o, mode_n)) || (target_o && strcmp(target_o, target_n)) ||
+		    } else if ((mode_o && strcmp(mode_o, mode_n)) ||
 			       (heater_o && strcmp(heater_o, heater_n)) || (cooler_o && strcmp(cooler_o, cooler_n))) {
 			srv_send(copy);
 		    }
-		}
-
+	    	}
 		free(copy);
 		copy = NULL;
 		if (mode_o)
 		    free(mode_o);
 		mode_o = xstrcpy(mode_n);
-		if (target_o)
-		    free(target_o);
-		target_o = xstrcpy(target_n);
 		if (heater_o)
 		    free(heater_o);
 		heater_o = xstrcpy(heater_n);
@@ -666,6 +667,15 @@
 		cooler_o = xstrcpy(cooler_n);
 	    }
 	}
+	if (mode_o)
+	    free(mode_o);
+	mode_o = NULL;
+	if (heater_o)
+	    free(heater_o);
+	heater_o = NULL;
+	if (cooler_o)
+	    free(cooler_o);
+	cooler_o = NULL;
 	free(filename);
 	filename = NULL;
 	srv_send((char *)".");
--- a/www-thermferm/getlog.php	Sun Aug 24 23:01:32 2014 +0200
+++ b/www-thermferm/getlog.php	Mon Aug 25 20:47:30 2014 +0200
@@ -40,8 +40,11 @@
 	if ($j > 1)
 	    $row .= ',';
 	$f = explode(",", $arr[$j]);
+	$heater = $f[5] / 100;
+	$cooler = $f[6] / 100;
+	$fan =    $f[7] / 100;
 	$row .= '{"Date":"'.$f[0].'","Mode":"'.$f[1].'","Air":"'.$f[2].'","Beer":"'.$f[3].'","Target":"'.$f[4].'",';
-        $row .= '"Heater":"'.$f[5].'","Cooler":"'.$f[6].'","Fan":"'.$f[7].'","Door":"'.$f[8].'"}';
+        $row .= '"Heater":'.$heater.',"Cooler":'.$cooler.',"Fan":'.$fan.',"Door":"'.$f[8].'"}';
 	$j++;
     }
 }
--- a/www-thermferm/liveview.php	Sun Aug 24 23:01:32 2014 +0200
+++ b/www-thermferm/liveview.php	Mon Aug 25 20:47:30 2014 +0200
@@ -107,15 +107,15 @@
 	$outstr .= '       {'.PHP_EOL;
 	$outstr .= '          datatype: "json",'.PHP_EOL;
 	$outstr .= '          datafields: ['.PHP_EOL;
-	$outstr .= '             { name: \'Date\' },'.PHP_EOL;
-	$outstr .= '             { name: \'Mode\' },'.PHP_EOL;
-	$outstr .= '             { name: \'Air\', type: \'float\' },'.PHP_EOL;
-	$outstr .= '             { name: \'Beer\', type: \'float\' },'.PHP_EOL;
-	$outstr .= '             { name: \'Target\', type: \'float\' },'.PHP_EOL;
-	$outstr .= '             { name: \'Heater\', type: \'bool\' },'.PHP_EOL;
-	$outstr .= '             { name: \'Cooler\', type: \'int\' },'.PHP_EOL;
-	$outstr .= '             { name: \'Fan\' },'.PHP_EOL;
-	$outstr .= '             { name: \'Door\', type: \'bool\' }'.PHP_EOL;
+	$outstr .= '             { name: "Date" },'.PHP_EOL;
+	$outstr .= '             { name: "Mode" },'.PHP_EOL;
+	$outstr .= '             { name: "Air", type: "float" },'.PHP_EOL;
+	$outstr .= '             { name: "Beer", type: "float" },'.PHP_EOL;
+	$outstr .= '             { name: "Target", type: "float" },'.PHP_EOL;
+	$outstr .= '             { name: "Heater", type: "int" },'.PHP_EOL;
+	$outstr .= '             { name: "Cooler", type: "int" },'.PHP_EOL;
+	$outstr .= '             { name: "Fan", type: "int" },'.PHP_EOL;
+	$outstr .= '             { name: "Door", type: "int" }'.PHP_EOL;
 	$outstr .= '          ],'.PHP_EOL;
 	$outstr .= '          url: \'getlog.php?unit='.$unit.'\''.PHP_EOL;
 	$outstr .= '       };'.PHP_EOL;
@@ -144,18 +144,34 @@
 	$outstr .= '         colorScheme: \'scheme01\','.PHP_EOL;
 	$outstr .= '         seriesGroups:'.PHP_EOL;
 	$outstr .= '           [{'.PHP_EOL;
-	$outstr .= '             type: \'line\','.PHP_EOL;
+	$outstr .= '             type: "stepline",'.PHP_EOL;
 	$outstr .= '             columnsGapPercent: 30,'.PHP_EOL;
 	$outstr .= '             seriesGapPercent: 0,'.PHP_EOL;
 	$outstr .= '             valueAxis:'.PHP_EOL;
 	$outstr .= '             {'.PHP_EOL;
+	$outstr .= '               minValue: 0,'.PHP_EOL;
+	$outstr .= '               maxValue: 4,'.PHP_EOL;
+	$outstr .= '               displayValueAxis: false,'.PHP_EOL;
+	$outstr .= '               description: "Heat/Cool"'.PHP_EOL;
+	$outstr .= '             },'.PHP_EOL;
+	$outstr .= '             series: ['.PHP_EOL;
+	$outstr .= '               { dataField: "Cooler", displayText: "Cool", opacity: 0.5 },'.PHP_EOL;
+	$outstr .= '               { dataField: "Heater", displayText: "Heat", opacity: 0.5 }'.PHP_EOL;
+	$outstr .= '             ]'.PHP_EOL;
+	$outstr .= '            },'.PHP_EOL;
+	$outstr .= '            {'.PHP_EOL;
+	$outstr .= '             type: \'spline\','.PHP_EOL;
+	$outstr .= '             columnsGapPercent: 30,'.PHP_EOL;
+	$outstr .= '             seriesGapPercent: 0,'.PHP_EOL;
+	$outstr .= '             valueAxis:'.PHP_EOL;
+	$outstr .= '             {'.PHP_EOL;
+	$outstr .= '               minValue: 0,'.PHP_EOL;
 	$outstr .= '               description: \'Degrees C\''.PHP_EOL;
 	$outstr .= '             },'.PHP_EOL;
 	$outstr .= '             series: ['.PHP_EOL;
-	$outstr .= '               { dataField: \'Air\', displayText: \'Air\' },'.PHP_EOL;
-	$outstr .= '               { dataField: \'Beer\', displayText: \'Beer\' },'.PHP_EOL;
-	$outstr .= '               { dataField: \'Heater\', displayText: \'Heater\' },'.PHP_EOL;
-	$outstr .= '               { dataField: \'Target\', displayText: \'Target\' }'.PHP_EOL;
+	$outstr .= '               { dataField: "Air", displayText: "Air" },'.PHP_EOL;
+	$outstr .= '               { dataField: "Beer", displayText: "Beer" },'.PHP_EOL;
+	$outstr .= '               { dataField: "Target", displayText: "Target", opacity: 0.7 }'.PHP_EOL;
 	$outstr .= '             ]'.PHP_EOL;
 	$outstr .= '           }]'.PHP_EOL;
 	$outstr .= '       };'.PHP_EOL;

mercurial