www-thermferm/liveview.php

Sat, 16 May 2015 17:39:30 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 16 May 2015 17:39:30 +0200
changeset 362
c92651a54969
parent 360
0f3fe4fa0977
child 374
20999ef6d487
permissions
-rw-r--r--

Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0

<?php
/*****************************************************************************
 * Copyright (C) 2014-2015
 *   
 * Michiel Broek <mbroek at mbse dot eu>
 *
 * This file is part of ThermFerm
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2, or (at your option) any
 * later version.
 *
 * ThermFerm is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with ThermFerm; see the file COPYING.  If not, write to the Free
 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 *****************************************************************************/


require_once('utilities.php');



function showunit($unit, $unr, $name)
{
    global $my_style;

    $outstr = '    <!--  showunit(' . $unit . ', ' . $unr . ', ' . $name . ')  -->' . PHP_EOL;
    $air_state = $beer_state = 1;
    $answer = send_cmd("UNIT GET ".$unit);
    $arr = explode("\r\n", $answer);

    if (startsWith($arr[0], "213")) {

	$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;

	foreach($arr as $l) {
	    $vals = explode(",", $l);
	    if (strcmp($vals[0], "MODE") == 0) {
		$mode = $vals[1];
		if (strcmp($mode, "OFF"))
		    $power_led = "on";
	    }
	    if (strcmp($vals[0], "AIR_STATE") == 0) {
		$air_state = $vals[1];
	    }
	    if ((strcmp($vals[0], "AIR_TEMPERATURE") == 0) && ($air_state == 0)) {
		$air_temperature = $vals[1];
	    }
	    if (strcmp($vals[0], "BEER_STATE") == 0) {
		$beer_state = $vals[1];
	    }
	    if ((strcmp($vals[0], "BEER_TEMPERATURE") == 0) && ($beer_state == 0)) {
		$beer_temperature = $vals[1];
	    }
	    if ((strcmp($vals[0], "HEATER_ADDRESS") == 0) && (strcmp($vals[1], "(null)"))) {
		$heater = "yes";
	    }
	    if (strcmp($vals[0], "HEATER_STATE") == 0) {
		$heater_state = $vals[1];
	    }
	    if ((strcmp($vals[0], "COOLER_ADDRESS") == 0) && (strcmp($vals[1], "(null)"))) {
		$cooler = "yes";
	    }
	    if (strcmp($vals[0], "COOLER_STATE") == 0) {
		$cooler_state = $vals[1];
	    }
	    if ((strcmp($vals[0], "FAN_ADDRESS") == 0) && (strcmp($vals[1], "(null)"))) {
		$fan = "yes";
	    }
	    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];
	    }
	    if (($vals[0] == "FRIDGE_SET") && ($mode == "FRIDGE")) {
		$set_temperature = $vals[1];
	    }
	    if (($vals[0] == "PROF_TARGET") && ($mode == "PROFILE")) {
		$set_temperature = $vals[1];
	    }
	}

	$outstr .= '    <script type="text/javascript">'.PHP_EOL;
	$outstr .= '     $(document).ready(function () {'.PHP_EOL;

	$outstr .= '       function getExportServer'.$unr.'() {'.PHP_EOL;
	$outstr .= '         return "http://www.jqwidgets.com/export_server/export.php";'.PHP_EOL;
	$outstr .= '       }'.PHP_EOL;
	$outstr .= '       var source'.$unr.' ='.PHP_EOL;
	$outstr .= '       {'.PHP_EOL;
	$outstr .= '          datatype: "json",'.PHP_EOL;
	$outstr .= '          datafields: ['.PHP_EOL;
	$outstr .= '             { name: "Date", type: "date", format: "yyyy-MM-ddTHH:mm" },'.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: "HeatUse", type: "int" },'.PHP_EOL;
	$outstr .= '             { name: "CoolUse", type: "int" },'.PHP_EOL;
	$outstr .= '             { name: "Room", type: "float" }'.PHP_EOL;
	$outstr .= '          ],'.PHP_EOL;
	$outstr .= '          url: \'getlog.php?unit='.$unit.'\''.PHP_EOL;
	$outstr .= '       };'.PHP_EOL;

	$outstr .= '       var dataAdapter'.$unr.' = new $.jqx.dataAdapter(source'.$unr.','.PHP_EOL;
	$outstr .= '       {'.PHP_EOL;
	$outstr .= '          autoBind: true,'.PHP_EOL;
	$outstr .= '          async: false,'.PHP_EOL;
	$outstr .= '          downloadComplete: function () { },'.PHP_EOL;
	$outstr .= '          loadComplete: function () { },'.PHP_EOL;
	$outstr .= '          loadError: function () { }'.PHP_EOL;
	$outstr .= '       });'.PHP_EOL;

	$outstr .= '       var settings'.$unr.' = {'.PHP_EOL;
	$outstr .= '         title: "'.$name.' history",'.PHP_EOL;
	$outstr .= '         description: "",'.PHP_EOL;
	$outstr .= '         padding: { left: 5, top: 5, right: 5, bottom: 5 },'.PHP_EOL;
	$outstr .= '         titlePadding: { left: 0, top: 0, right: 0, bottom: 10 },'.PHP_EOL;
	$outstr .= '         source: dataAdapter'.$unr.','.PHP_EOL;
	$outstr .= '         categoryAxis:'.PHP_EOL;
	$outstr .= '           {'.PHP_EOL;
	$outstr .= '             dataField: \'Date\','.PHP_EOL;
	$outstr .= '             textRotationAngle: 45,'.PHP_EOL;
	$outstr .= '             showGridLines: false'.PHP_EOL;
	$outstr .= '           },'.PHP_EOL;
	$outstr .= '         colorScheme: \'scheme01\','.PHP_EOL;
	$outstr .= '         seriesGroups:'.PHP_EOL;
	$outstr .= '           [{'.PHP_EOL;
	$outstr .= '             type: "line",'.PHP_EOL;
	$outstr .= '             valueAxis:'.PHP_EOL;
	$outstr .= '             {'.PHP_EOL;
	$outstr .= '               minValue: 0,'.PHP_EOL;
	$outstr .= '               maxValue: 100,'.PHP_EOL;
	$outstr .= '               displayValueAxis: false,'.PHP_EOL;
	$outstr .= '               description: "Heat/Cool %"'.PHP_EOL;
	$outstr .= '             },'.PHP_EOL;
	$outstr .= '             series: ['.PHP_EOL;
	$outstr .= '               { dataField: "CoolUse", lineWidth: 1, displayText: "Cool %", opacity: 0.5 },'.PHP_EOL;
	$outstr .= '               { dataField: "HeatUse", lineWidth: 1, displayText: "Heat %", opacity: 0.5 }'.PHP_EOL;
	$outstr .= '             ]'.PHP_EOL;
	$outstr .= '            },'.PHP_EOL;
	$outstr .= '            {'.PHP_EOL;
	$outstr .= '             type: \'spline\','.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", lineWidth: 1, displayText: "Air" },'.PHP_EOL;
	$outstr .= '               { dataField: "Beer", lineWidth: 2, displayText: "Beer" },'.PHP_EOL;
	$outstr .= '               { dataField: "Target", lineWidth: 1, displayText: "Target", opacity: 0.7 },'.PHP_EOL;
	$outstr .= '               { dataField: "Room", lineWidth: 1, displayText: "Room", opacity: 0.5 }'.PHP_EOL;
	$outstr .= '             ]'.PHP_EOL;
	$outstr .= '           }]'.PHP_EOL;
	$outstr .= '       };'.PHP_EOL;
	/* Direct draw for the first time */
	$outstr .= '       $("#fermentor_chart_'.$unit.'").jqxChart(settings'.$unr.');'.PHP_EOL;
	/* Regular updates of the chart */
//	$outstr .= '       setInterval(function(){'.PHP_EOL;
//	$outstr .= '         $("#fermentor_chart_'.$unit.'").jqxChart("update");'.PHP_EOL;
//	$outstr .= '       }, 3000);'.PHP_EOL;

	$outstr .= '       $("#print_'.$unr.'").click(function () {'.PHP_EOL;
	$outstr .= '         var content = $("#fermentor_chart_'.$unit.'")[0].outerHTML;'.PHP_EOL;
	$outstr .= '         var newWindow = window.open("", "", "width=750, height=400"),'.PHP_EOL;
	$outstr .= '         document = newWindow.document.open(),'.PHP_EOL;
	$outstr .= '         pageContent ='.PHP_EOL;
	$outstr .= '         \'<!DOCTYPE html>\' +'.PHP_EOL;
	$outstr .= '         \'<html>\' +'.PHP_EOL;
	$outstr .= '         \'<head>\' +'.PHP_EOL;
	$outstr .= '         \'<link rel="stylesheet" href="jqwidgets/styles/jqx.base.css" type="text/css" />\' +'.PHP_EOL;
	$outstr .= '         \'<meta charset="utf-8" />\' +'.PHP_EOL;
	$outstr .= '         \'<title>jQWidgets Chart</title>\' +'.PHP_EOL;
	$outstr .= '         \'</head>\' +'.PHP_EOL;
	$outstr .= '         \'<body>\' + content + \'</body></html>\';'.PHP_EOL;
	$outstr .= '         document.write(pageContent);'.PHP_EOL;
	$outstr .= '         document.close();'.PHP_EOL;
	$outstr .= '         newWindow.print();'.PHP_EOL;
	$outstr .= '       });'.PHP_EOL;
	$outstr .= '       $("#print_'.$unr.'").jqxButton({ width: 100, height: 25, theme: "ui-redmond" });'.PHP_EOL;

	$outstr .= '       $("#pngButton_'.$unr.'").click(function () {'.PHP_EOL;
			      	// call the export server to create a PNG image
	$outstr .= '       	$("#fermentor_chart_'.$unit.'").jqxChart("saveAsPNG", "Chart_'.$name.'.png", getExportServer'.$unr.'());'.PHP_EOL;
	$outstr .= '       });'.PHP_EOL;
	$outstr .= '       $("#pngButton_'.$unr.'").jqxButton({ width: 100, height: 25, theme: "ui-redmond" });'.PHP_EOL;

	$outstr .= '       setInterval(function(){'.PHP_EOL;
	$outstr .= '         $.getJSON("getstate.php?uuid='.$unit.'", function(data) {'.PHP_EOL;
	$outstr .= '           $("#load_air_'.$unr.'").html(data.air_temperature);'.PHP_EOL;
	$outstr .= '           $("#load_beer_'.$unr.'").html(data.beer_temperature);'.PHP_EOL;
	$outstr .= '           $("#load_target_'.$unr.'").html(data.target_temperature);'.PHP_EOL;
	$outstr .= '           $("#load_select_'.$unr.'").html(data.mode);'.PHP_EOL;
	$outstr .= '           $("#load_led1_'.$unr.'").html(data.led1);'.PHP_EOL;
	$outstr .= '           $("#load_led2_'.$unr.'").html(data.led2);'.PHP_EOL;
	$outstr .= '           $("#load_led3_'.$unr.'").html(data.led3);'.PHP_EOL;
	$outstr .= '           $("#load_sw1_'.$unr.'").html(data.sw1);'.PHP_EOL;
	$outstr .= '           $("#load_sw2_'.$unr.'").html(data.sw2);'.PHP_EOL;
	$outstr .= '           $("#load_sw3_'.$unr.'").html(data.sw3);'.PHP_EOL;
	if ($mode == "PROFILE")
	    $outstr .= '           $("#prof_state_'.$unr.'").html(data.profile_state);'.PHP_EOL;
        $outstr .= '         });'.PHP_EOL;
	$outstr .= '       }, 10000);'.PHP_EOL;
	$outstr .= '     });'.PHP_EOL;
	$outstr .= '    </script>'.PHP_EOL;
	$outstr .= '    <div id="fermentor">'.PHP_EOL;
	$outstr .= '     <div id="fermentor_chart_'.$unit.'" style="width:720px; height:377px; float:left"></div>'.PHP_EOL;

	$outstr .= '     <div id="fermentor_panel_top">'.PHP_EOL;
	$outstr .= '      <div id="fermentor_selector">'.PHP_EOL;
	$outstr .= '       <form id="select_'.$unr.'" action="index.php" method="post">'.PHP_EOL;
	$outstr .= '      <div id="load_select_'.$unr.'">'.PHP_EOL;
	strcmp($mode, "OFF") ? $se = "" : $se = " checked";
	$outstr .= '        <input type="radio" name="mode" onchange="this.form.submit()" class="select" value="OFF"'.$se.'>Off<br>'.PHP_EOL;
	strcmp($mode, "NONE") ? $se = "" : $se = " checked";
	$outstr .= '        <input type="radio" name="mode" onchange="this.form.submit()" class="select" value="NONE"'.$se.'>None<br>'.PHP_EOL;
	(strcmp($heater, "no") || strcmp($cooler, "no")) ? $dis = "" : $dis = " disabled";
	strcmp($mode, "FRIDGE") ? $se = "" : $se = " checked";
	$outstr .= '        <input type="radio" name="mode" onchange="this.form.submit()" class="select" value="FRIDGE"'.$se.$dis.'>Fridge<br>'.PHP_EOL;
	strcmp($mode, "BEER") ? $se = "" : $se = " checked";
	$outstr .= '        <input type="radio" name="mode" onchange="this.form.submit()" class="select" value="BEER"'.$se.$dis.'>Beer<br>'.PHP_EOL;
	strcmp($mode, "PROFILE") ? $se = "" : $se = " checked";
	$outstr .= '        <input type="radio" name="mode" onchange="this.form.submit()" class="select" value="PROFILE"'.$se.$dis.'>Profile'.PHP_EOL;
	$outstr .= '       </div>'.PHP_EOL;
	$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 .= '       <div class="LEDblue_'.$power_led.'"></div>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.
	     */
	    $answer = send_cmd("PROFILE LIST");
	    $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: 23px; overflow: hidden;">Profile: '.$prof_name.'</div>'.PHP_EOL;
	    $outstr .= '       <div id="prof_state_'.$unr.'" style="color: blue; width: 148px; height: 23px; overflow: hidden;">State: '.$prof_state.'</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 (startsWith($prof_state, "RUN")) {
		$outstr .= '        <input type="hidden" value="'.$profile.'" name="SetProfile">'.PHP_EOL;
		$outstr .= '        <input type="submit" value="Pause" name="key">'.PHP_EOL;
		$outstr .= '        <input type="submit" value="Abort" name="key">'.PHP_EOL;
	    } else if ($prof_state == "PAUSE") {
		$outstr .= '        <input type="hidden" value="'.$profile.'" name="SetProfile">'.PHP_EOL;
		$outstr .= '        <input type="submit" value="Resume" name="key">'.PHP_EOL;
		$outstr .= '        <input type="submit" value="Abort" name="key">'.PHP_EOL;
	    } else if ($prof_state == "DONE") {
		$outstr .= '        <input type="hidden" value="'.$profile.'" name="SetProfile">'.PHP_EOL;
		$outstr .= '        <input type="submit" value="Off" name="key">'.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;
	$outstr .= '      <div id="fermentor_display1">'.PHP_EOL;
	$outstr .= '       <div id="load_target_'.$unr.'" class="dtemp">'.$set_temperature.'</div>Set'.PHP_EOL;
	$outstr .= '      </div>'.PHP_EOL;
	$outstr .= '      <div id="fermentor_display2">'.PHP_EOL;
	$outstr .= '       <div id="load_air_'.$unr.'" class="dtemp">'.$air_temperature.'</div>Air'.PHP_EOL;
	$outstr .= '      </div>'.PHP_EOL;
	$outstr .= '      <div id="fermentor_display3">'.PHP_EOL;
	$outstr .= '       <div id="load_beer_'.$unr.'" class="dtemp">'.$beer_temperature.'</div>Beer'.PHP_EOL;
	$outstr .= '      </div>'.PHP_EOL;
	$outstr .= '     </div> <!-- fermentor_panel_display -->'.PHP_EOL;

	$outstr .= '     <div id="fermentor_panel_control">'.PHP_EOL;
	if ($cooler_state)
	    $cooler_led = "on";
	$outstr .= '      <div id="fermentor_led1">'.PHP_EOL;
	$outstr .= '       <div id="load_led1_'.$unr.'"><div class="LEDgreen_'.$cooler_led.'"></div></div>Cool'.PHP_EOL;
	$outstr .= '      </div>'.PHP_EOL;
	if ($heater_state)
	    $heater_led = "on";
	$outstr .= '      <div id="fermentor_led2">'.PHP_EOL;
	$outstr .= '       <div id="load_led2_'.$unr.'"><div class="LEDgreen_'.$heater_led.'"></div></div>Heat'.PHP_EOL;
	$outstr .= '      </div>'.PHP_EOL;
	if ($fan_state)
	    $fan_led = "on";
	$outstr .= '      <div id="fermentor_led3">'.PHP_EOL;
	$outstr .= '       <div id="load_led3_'.$unr.'"><div class="LEDgreen_'.$fan_led.'"></div></div>Fan'.PHP_EOL;
	$outstr .= '      </div>'.PHP_EOL;

	$outstr .= '      <div id="fermentor_toggle1">'.PHP_EOL;
	$outstr .= '       <form action="index.php" method="post">'.PHP_EOL;
	(($mode == "NONE") && ($cooler == "yes")) ? $dis = "" : $dis = " disabled";
	($cooler_state == "0") ? $ch = " checked" : $ch = "";
	$outstr .= '        <div id="load_sw1_'.$unr.'">'.PHP_EOL;
	$outstr .= '         <input type="radio" name="CoolerState" onchange="this.form.submit()" value="0"'.$dis.$ch.'>Off<br>'.PHP_EOL;
	($cooler_state == "100") ? $ch = " checked" : $ch = "";
	$outstr .= '         <input type="radio" name="CoolerState" onchange="this.form.submit()" value="100"'.$dis.$ch.'>On'.PHP_EOL;
	$outstr .= '        </div>'.PHP_EOL;
	$outstr .= '        <input type="hidden" name="UUID" value="'.$unit.'">'.PHP_EOL;
	$outstr .= '       </form>'.PHP_EOL;
	$outstr .= '      </div>'.PHP_EOL;

	$outstr .= '      <div id="fermentor_toggle2">'.PHP_EOL;
	$outstr .= '       <form action="index.php" method="post">'.PHP_EOL;
	(($mode == "NONE") && ($heater == "yes")) ? $dis = "" : $dis = " disabled";
	($heater_state == "0") ? $ch = " checked" : $ch = "";
	$outstr .= '        <div id="load_sw2_'.$unr.'">'.PHP_EOL;
	$outstr .= '         <input type="radio" name="HeaterState" onchange="this.form.submit()" value="0"'.$dis.$ch.'>Off<br>'.PHP_EOL;
	($heater_state == "100") ? $ch = " checked" : $ch = "";
	$outstr .= '         <input type="radio" name="HeaterState" onchange="this.form.submit()" value="100"'.$dis.$ch.'>On'.PHP_EOL;
	$outstr .= '        </div>'.PHP_EOL;
	$outstr .= '        <input type="hidden" name="UUID" value="'.$unit.'">'.PHP_EOL;
	$outstr .= '       </form>'.PHP_EOL;
	$outstr .= '      </div>'.PHP_EOL;

	$outstr .= '      <div id="fermentor_toggle3">'.PHP_EOL;
	$outstr .= '       <form action="index.php" method="post">'.PHP_EOL;
	(($mode == "NONE") && ($fan== "yes")) ? $dis = "" : $dis = " disabled";
	($fan_state == "0") ? $ch = " checked" : $ch = "";
	$outstr .= '        <div id="load_sw3_'.$unr.'">'.PHP_EOL;
	$outstr .= '         <input type="radio" name="FanState" onchange="this.form.submit()" value="0"'.$dis.$ch.'>Off<br>'.PHP_EOL;
	($fan_state == "100") ? $ch = " checked" : $ch = "";
	$outstr .= '         <input type="radio" name="FanState" onchange="this.form.submit()" value="100"'.$dis.$ch.'>On'.PHP_EOL;
	$outstr .= '        </div>'.PHP_EOL;
	$outstr .= '        <input type="hidden" name="UUID" value="'.$unit.'">'.PHP_EOL;
	$outstr .= '       </form>'.PHP_EOL;
	$outstr .= '      </div>'.PHP_EOL;
	$outstr .= '     </div> <!-- fermentor_panel_control -->'.PHP_EOL;

	$outstr .= '     <div id="fermentor_panel_buttons">'.PHP_EOL;
	$outstr .= '     <div style="margin-top: 2px; margin-left: 10px;">'.PHP_EOL;
	$outstr .= '      <input style="float: left;" id="print_'.$unr.'" type="button" value="Print Graph" />'.PHP_EOL;
	$outstr .= '      <input style="float: left; margin-left: 15px;" id="pngButton_'.$unr.'" type="button" value="Save Graph" />'.PHP_EOL;
	$outstr .= '     </div>'.PHP_EOL;
	$outstr .= '     </div> <!-- fermentor_panel_buttons -->'.PHP_EOL;

	$outstr .= '    </div> <!-- fermentor -->'.PHP_EOL;
    }

    return $outstr;
}



function liveview()
{
    $outstr  = PHP_EOL;

    $answer = send_cmd("LIST");
    if (strlen($answer)) {
	$arr = explode("\r\n", $answer);

	$outstr .= '   <div id="jqxTabs">'.PHP_EOL;
	$outstr .= '    <ul>'.PHP_EOL;
	if (startsWith($arr[0], "212")) {
	    $i = 1;
	    while (1) {
		if (strcmp($arr[$i], ".") == 0)
			break;
		$parts = explode(",", $arr[$i]);
		$outstr .= '     <li style="margin-left: 20px;">'.$parts[1].'</li>'.PHP_EOL;
		$i++;
	    }
	}
	$outstr .= '    </ul>'.PHP_EOL;

	if (startsWith($arr[0], "212")) {
	    $i = 1;
	    while (1) {
		if (strcmp($arr[$i], ".") == 0)
		    break;
		$parts = explode(",", $arr[$i]);
		$outstr .= showunit($parts[0], $i, $parts[1]);
		$i++;
	    }
	}
	$outstr .= '   </div> <!-- jqxTabs -->'.PHP_EOL;
    }

    return $outstr;
}


?>

mercurial