Reset output when a different profile is selected. Better startup logging about the unit state. Added Beer, Fridge and partial Profile settings from the liveview weeb screen.

Fri, 08 Aug 2014 23:07:44 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Fri, 08 Aug 2014 23:07:44 +0200
changeset 195
b34a1b2421fb
parent 194
9eaaba49450f
child 196
4d7a96c5d1ff

Reset output when a different profile is selected. Better startup logging about the unit state. Added Beer, Fridge and partial Profile settings from the liveview weeb screen.

thermferm/server.c file | annotate | diff | comparison | revisions
thermferm/thermferm.c file | annotate | diff | comparison | revisions
www-thermferm/css/style.css file | annotate | diff | comparison | revisions
www-thermferm/index.php file | annotate | diff | comparison | revisions
www-thermferm/liveview.php file | annotate | diff | comparison | revisions
--- a/thermferm/server.c	Thu Aug 07 22:06:18 2014 +0200
+++ b/thermferm/server.c	Fri Aug 08 23:07:44 2014 +0200
@@ -1116,8 +1116,10 @@
 					/* Initialize log if the unit is turned on */
 					if ((unit->mode == UNITMODE_OFF) && (i != UNITMODE_OFF))
 					    initlog(unit->name);
+					syslog(LOG_NOTICE, "Mode from %s to %s via web interface", UNITMODE[unit->mode], UNITMODE[i]);
 					unit->mode = i;
 					/* Allways turn everything off after a mode change */
+					unit->PID_I_err = unit->PID_err_old = 0.0;
 					unit->heater_state = unit->cooler_state = unit->fan_state = 0;
 					device_out(unit->heater_address, unit->heater_state);
 					device_out(unit->cooler_address, unit->cooler_state);
@@ -1145,6 +1147,14 @@
 				    	unit->profile = xstrcpy(val);
 				    else
 				    	unit->profile = NULL;
+				    /*
+				     * Reset all output devices
+				     */
+				    unit->PID_I_err = unit->PID_err_old = 0.0;
+				    unit->heater_state = unit->cooler_state = unit->fan_state = 0;
+				    device_out(unit->heater_address, unit->heater_state);
+				    device_out(unit->cooler_address, unit->cooler_state);
+				    device_out(unit->fan_address, unit->fan_state);
 				}
 
 			    } else if (val && (strcmp(kwd, (char *)"PROF_STATE") == 0)) {
--- a/thermferm/thermferm.c	Thu Aug 07 22:06:18 2014 +0200
+++ b/thermferm/thermferm.c	Fri Aug 08 23:07:44 2014 +0200
@@ -53,6 +53,7 @@
 pthread_t		threads[4];
 #endif
 extern const char       UNITMODE[5][8];
+extern const char	PROFSTATE[4][6];
 
 
 int  server(void);
@@ -309,8 +310,11 @@
 	 * Safety, turn everything off
 	 */
 	unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = 0;
-	if (unit->profile && (int)unit->prof_started && (unit->mode == UNITMODE_PROFILE)) {
-	    syslog(LOG_NOTICE, "Starting unit %s profile %s", unit->name, unit->profile);
+	if (unit->mode == UNITMODE_PROFILE) {
+	    if (unit->profile)
+		syslog(LOG_NOTICE, "Starting unit %s in profile mode, no profile defined.", unit->name);
+	    else
+	    	syslog(LOG_NOTICE, "Starting unit %s in profile state %s. Target %.1f degrees", unit->name, PROFSTATE[unit->prof_state], unit->prof_target);
 	} else if (unit->mode == UNITMODE_BEER) {
 	    syslog(LOG_NOTICE, "Starting unit %s beer cooler at %.1f degrees", unit->name, unit->beer_set);
 	} else if (unit->mode == UNITMODE_FRIDGE) {
@@ -531,6 +535,8 @@
 			if (debug)
 			    fprintf(stdout, "sp=%.2f pv=%.2f err_old=%.2f err=%.2f P_err=%.2f I_err=%.2f D_err=%.2f Out=%.2f\n",
 						sp, pv, unit->PID_err_old, err, P_err, unit->PID_I_err, D_err, Out);
+			syslog(LOG_NOTICE, "sp=%.2f pv=%.2f err_old=%.2f err=%.2f P_err=%.2f I_err=%.2f D_err=%.2f Out=%.2f",
+					sp, pv, unit->PID_err_old, err, P_err, unit->PID_I_err, D_err, Out);
 			if (unit->heater_address) {
 			    if (Out >= 2)
 				unit->heater_state = 100;
--- a/www-thermferm/css/style.css	Thu Aug 07 22:06:18 2014 +0200
+++ b/www-thermferm/css/style.css	Fri Aug 08 23:07:44 2014 +0200
@@ -146,11 +146,12 @@
 
 /*
  *  +-------------panel_top--------------+
- *  |+----------------------++----------+|
- *  ||                      ||          ||
- *  ||       selector       || powerled ||
- *  ||                      ||          ||
- *  |+----------------------++----------+|
+ *  |+----------------++----------------+|
+ *  ||                ||    powerled    ||
+ *  ||    selector    |+----------------+|
+ *  ||                |+----------------+|
+ *  ||                ||  mode_control  ||
+ *  |+----------------++----------------+|
  *  +------------------------------------+
  *  +-----------panel_display------------+
  *  |+----------++----------++----------+|
@@ -179,7 +180,7 @@
 }
 
 #fermentor_selector {
-    width: 158px;
+    width: 88px;
     height: 156px;
     float: left;
 }
@@ -190,11 +191,19 @@
 }
 
 #fermentor_powerled {
-    width: 78px;
-    height: 56px;
+    width: 38px;
+    height: 36px;
     float: left;
-    text-align: center;
     margin-top: 10px;
+    margin-left: 110px;
+}
+
+#fermentor_mode_control {
+    width: 148px;
+    height: 100px;
+    float: left;
+    margin-top: 10px;
+    background-color: #ddd;
 }
 
 
--- a/www-thermferm/index.php	Thu Aug 07 22:06:18 2014 +0200
+++ b/www-thermferm/index.php	Fri Aug 08 23:07:44 2014 +0200
@@ -117,6 +117,80 @@
     unset($_POST['FanState']);
 }
 
+if (isset($_POST['Fridge']) && isset($_POST['key']) && isset($_POST['UUID'])) {
+
+    if ($_POST['key'] == "Set") {
+	$sock = open_socket();
+	if ($sock != false) {
+	    socket_write($sock, 'UNIT PUT '.$_POST['UUID'], 4096);
+	    usleep(20000);
+	    socket_write($sock, 'FRIDGE_SET,'.$_POST['Fridge'], 4096);
+	    usleep(20000);
+	    socket_write($sock, '.', 4096);
+	    /* Absorb response */
+	    while (1) {
+		$line = socket_read($sock, 4096);
+		if ($line === '')
+		    break;
+	    }
+	    socket_close($sock);
+	}
+    }
+
+    unset($_POST['Fridge']);
+    unset($_POST['key']);
+    unset($_POST['UUID']);
+}
+
+
+if (isset($_POST['Beer']) && isset($_POST['key']) && isset($_POST['UUID'])) {
+
+    if ($_POST['key'] == "Set") {
+	$sock = open_socket();
+	if ($sock != false) {
+	    socket_write($sock, 'UNIT PUT '.$_POST['UUID'], 4096);
+	    usleep(20000);
+	    socket_write($sock, 'BEER_SET,'.$_POST['Beer'], 4096);
+	    usleep(20000);
+	    socket_write($sock, '.', 4096);
+	    /* Absorb response */
+	    while (1) {
+	    $line = socket_read($sock, 4096);
+	    if ($line === '')
+		break;
+	    }
+	    socket_close($sock);
+	}
+    }
+    unset($_POST['Beer']);
+    unset($_POST['key']);
+    unset($_POST['UUID']);
+}
+
+
+if (isset($_POST['SetProfile']) && isset($_POST['key']) && isset($_POST['UUID'])) {
+
+    if ($_POST['key'] == "Set") {
+	$sock = open_socket();
+	if ($sock != false) {
+	    socket_write($sock, 'UNIT PUT '.$_POST['UUID'], 4096);
+	    usleep(20000);
+	    socket_write($sock, 'PROFILE,'.$_POST['SetProfile'], 4096);
+	    usleep(20000);
+	    socket_write($sock, '.', 4096);
+	    /* Absorb response */
+	    while (1) {
+		$line = socket_read($sock, 4096);
+		if ($line === '')
+		    break;
+	    }
+	    socket_close($sock);
+	}
+    }
+    unset($_POST['SetProfile']);
+    unset($_POST['key']);
+    unset($_POST['UUID']);
+}
 
 
 $outstr  = '<!DOCTYPE html>'.PHP_EOL;
--- a/www-thermferm/liveview.php	Thu Aug 07 22:06:18 2014 +0200
+++ b/www-thermferm/liveview.php	Fri Aug 08 23:07:44 2014 +0200
@@ -54,6 +54,8 @@
 	$set_temperature = "NA";
 	$air_temperature = "NA";
 	$beer_temperature = "NA";
+	$profile = "";
+	$prof_state = "OFF";
 	$power_led = $cooler_led = $heater_led = $fan_led = "off";
 	$heater = $cooler = $fan = "no";
 	$heater_state = $cooler_state = $fan_state = 0;
@@ -95,6 +97,12 @@
 	    if (strcmp($vals[0], "FAN_STATE") == 0) {
 		$fan_state = $vals[1];
 	    }
+	    if (strcmp($vals[0], "PROFILE") == 0) {
+		$profile = $vals[1];
+	    }
+	    if (strcmp($vals[0], "PROF_STATE") == 0) {
+		$prof_state = $vals[1];
+	    }
 	    if (($vals[0] == "BEER_SET") && ($mode == "BEER")) {
 		$set_temperature = $vals[1];
 	    }
@@ -203,9 +211,97 @@
 	$outstr .= '        <input type="hidden" name="UUID" value="'.$unit.'">'.PHP_EOL;
 	$outstr .= '       </form>'.PHP_EOL;
 	$outstr .= '      </div>'.PHP_EOL;
+
 	$outstr .= '      <div id="fermentor_powerled">'.PHP_EOL;
 	$outstr .= '       <img src="images/led_green_'.$power_led.'.png"><br>Pwr'.PHP_EOL;
 	$outstr .= '      </div>'.PHP_EOL;
+
+	$outstr .= '      <div id="fermentor_mode_control">'.PHP_EOL;
+	if ($mode == "FRIDGE") {
+	    $outstr .= '       <form id="set_fridge_'.$unr.'" action="index.php" method="post">'.PHP_EOL;
+	    $outstr .= '        <input type="text" name="Fridge" size="5" value="'.$set_temperature.'"><br>'.PHP_EOL;
+	    $outstr .= '        <input type="submit" value="Set" name="key">'.PHP_EOL;
+	    $outstr .= '        <input type="hidden" value="'.$unit.'" name="UUID">'.PHP_EOL;
+	    $outstr .= '       </form>'.PHP_EOL;
+	}
+	if ($mode == "BEER") {
+	    $outstr .= '       <form id="set_beer_'.$unr.'" action="index.php" method="post">'.PHP_EOL;
+	    $outstr .= '        <input type="text" name="Beer" size="5" value="'.$set_temperature.'">'.PHP_EOL;
+	    $outstr .= '        <input type="submit" value="Set" name="key">'.PHP_EOL;
+	    $outstr .= '        <input type="hidden" value="'.$unit.'" name="UUID">'.PHP_EOL;
+	    $outstr .= '       </form>'.PHP_EOL;
+	}
+	if ($mode == "PROFILE") {
+	    /*
+	     * First, load a list with available profiles.
+	     */
+	    $sock = open_socket();
+	    if ($sock == true) {
+	    	socket_write($sock, "PROFILE LIST", 4096);
+	    	$answer = "";
+	    	while (1) {
+		    $line = socket_read($sock, 4096);
+		    if ($line === '')
+			break;
+		    $answer .= $line;
+	    	}
+	    	socket_close($sock);
+	    	$reply = explode("\r\n", $answer);
+	    }
+
+	    /*
+	     * Show loaded profile.
+	     */
+	    if ($profile == "(null)") {
+		$prof_name = "None";
+	    }else {
+		if (startsWith($reply[0], "212")) {
+		    $i = 1;
+		    while (1) {
+			if (strcmp($reply[$i], ".") == 0)
+			    break;
+			$f = explode(",", $reply[$i]);
+			if ($f[0] == $profile) {
+			    $prof_name = $f[1];
+			    break;
+			}
+			$i++;
+		    }
+		}
+	    }
+	    $outstr .= '       <div style="color: blue; width: 148px; height: 20px; overflow: hidden;">Profile: '.$prof_name.'</div>'.PHP_EOL;
+
+	    $outstr .= '       <form id="set_profile_'.$unr.'" action="index.php" method="post">'.PHP_EOL;
+	    if ($prof_state == "OFF") {
+	    	$outstr .= '        <select name="SetProfile" style="width: 130px;">'.PHP_EOL;
+	    	$outstr .= '         <option value="">None</option>'.PHP_EOL;
+	    	if (startsWith($reply[0], "212")) {
+		    $i = 1;
+		    while (1) {
+			if (strcmp($reply[$i], ".") == 0)
+			    break;
+			$f = explode(",", $reply[$i]);
+			if ($f[2] > 0) {
+			    ($f[0] == $profile) ? $se = " selected" : $se = "";
+			    $outstr .= '         <option value="'.$f[0].'"'.$se.'>'.$f[1].'</option>'.PHP_EOL;
+			}
+			$i++;
+		    }
+	    	}
+		$outstr .= '        </select>'.PHP_EOL;
+		$outstr .= '        <input type="submit" value="Set" name="key">'.PHP_EOL;
+		if ($profile != "(null)")
+		    $outstr .= '        <input type="submit" value="Start" name="key">'.PHP_EOL;
+
+	    } else if ($prof_state == "RUN") {
+	    } else if ($prof_state == "PAUSE") {
+	    } else if ($prof_state == "DONE") {
+	    }
+	    //$outstr .= '        <input type="text" name="Beer" size="5" value="'.$set_temperature.'">'.PHP_EOL;
+	    $outstr .= '        <input type="hidden" value="'.$unit.'" name="UUID">'.PHP_EOL;
+	    $outstr .= '       </form>'.PHP_EOL;
+	}
+	$outstr .= '      </div>'.PHP_EOL;
 	$outstr .= '     </div> <!-- fermentor_panel_top -->'.PHP_EOL;
 
 	$outstr .= '     <div id="fermentor_panel_display">'.PHP_EOL;

mercurial