Wed, 30 Jul 2014 23:06:46 +0200
Update LCD even when unit is off
<?php /***************************************************************************** * Copyright (C) 2014 * * 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) { global $my_style; $outstr = ''; $air_state = $beer_state = 1; $sock = open_socket(); if ($sock == false) { return ''; } socket_write($sock, "UNIT " . $unit, 4096); $answer = ""; while (1) { $line = socket_read($sock, 4096); if ($line === '') break; $answer .= $line; } socket_close($sock); $sock = open_socket(); if ($sock == false) { return ''; } socket_write($sock, "LIST UNIT", 4096); $answer = ""; while (1) { $line = socket_read($sock, 4096); if ($line === '') break; $answer .= $line; } socket_close($sock); $arr = explode("\r\n", $answer); if (startsWith($arr[0], "213")) { $set_temperature = "N/A"; $air_temperature = "N/A"; $beer_temperature = "N/A"; $power_led = $cooler_led = $heater_led = $fan_led = "off"; $heater = $cooler = $fan = "no"; 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") == 0) && (strcmp($vals[1], "YES"))) { $heater = "yes"; } if ((strcmp($vals[0], "COOLER") == 0) && (strcmp($vals[1], "YES"))) { $cooler = "yes"; } if ((strcmp($vals[0], "FAN") == 0) && (strcmp($vals[1], "YES"))) { $fan = "yes"; } } $outstr .= ' <script type="text/javascript">'.PHP_EOL; $outstr .= ' $(document).ready(function () {'.PHP_EOL; $outstr .= ' var source'.$unr.' ='.PHP_EOL; $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\' },'.PHP_EOL; $outstr .= ' { name: \'Cooler\' },'.PHP_EOL; $outstr .= ' { name: \'Fan\' },'.PHP_EOL; $outstr .= ' { name: \'Door\' }'.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: "Fermentation temperature",'.PHP_EOL; $outstr .= ' description: "",'.PHP_EOL; $outstr .= ' padding: { left: 5, top: 5, right: 5, bottom: 5 },'.PHP_EOL; $outstr .= ' titlePadding: { left: 90, 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 .= ' columnsGapPercent: 30,'.PHP_EOL; $outstr .= ' seriesGapPercent: 0,'.PHP_EOL; $outstr .= ' valueAxis:'.PHP_EOL; $outstr .= ' {'.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 .= ' ]'.PHP_EOL; $outstr .= ' }]'.PHP_EOL; $outstr .= ' };'.PHP_EOL; $outstr .= ' $("#fermentor_chart_'.$unit.'").jqxChart(settings'.$unr.');'.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; strcmp($mode, "OFF") ? $se = "" : $se = " checked"; $outstr .= ' <input type="radio" name="mode" onchange="this.form.submit()" value="OFF"'.$se.'>Off<br>'.PHP_EOL; strcmp($mode, "NONE") ? $se = "" : $se = " checked"; $outstr .= ' <input type="radio" name="mode" onchange="this.form.submit()" 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()" value="FRIDGE"'.$se.$dis.'>Fridge<br>'.PHP_EOL; strcmp($mode, "BEER") ? $se = "" : $se = " checked"; $outstr .= ' <input type="radio" name="mode" onchange="this.form.submit()" value="BEER"'.$se.$dis.'>Beer<br>'.PHP_EOL; strcmp($mode, "PROFILE") ? $se = "" : $se = " checked"; $outstr .= ' <input type="radio" name="mode" onchange="this.form.submit()" value="PROFILE"'.$se.$dis.'>Profile'.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 .= ' <img src="images/led_green_'.$power_led.'.png"><br>Pwr'.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 .= ' '.$set_temperature.'<br>Set'.PHP_EOL; $outstr .= ' </div>'.PHP_EOL; $outstr .= ' <div id="fermentor_display2">'.PHP_EOL; $outstr .= ' '.$air_temperature.'<br>Air'.PHP_EOL; $outstr .= ' </div>'.PHP_EOL; $outstr .= ' <div id="fermentor_display3">'.PHP_EOL; $outstr .= ' '.$beer_temperature.'<br>Beer'.PHP_EOL; $outstr .= ' </div>'.PHP_EOL; $outstr .= ' </div> <!-- fermentor_panel_display -->'.PHP_EOL; $outstr .= ' <div id="fermentor_panel_control">'.PHP_EOL; $outstr .= ' <div id="fermentor_led1">'.PHP_EOL; $outstr .= ' <img src="images/led_green_'.$cooler_led.'.png"><br>Cool'.PHP_EOL; $outstr .= ' </div>'.PHP_EOL; $outstr .= ' <div id="fermentor_led2">'.PHP_EOL; $outstr .= ' <img src="images/led_green_'.$heater_led.'.png"><br>Heat'.PHP_EOL; $outstr .= ' </div>'.PHP_EOL; $outstr .= ' <div id="fermentor_led3">'.PHP_EOL; $outstr .= ' <img src="images/led_green_'.$fan_led.'.png"><br>Fan'.PHP_EOL; $outstr .= ' </div>'.PHP_EOL; $outstr .= ' <div id="fermentor_toggle1">'.PHP_EOL; $outstr .= ' <form action="index.php" method="post">'.PHP_EOL; strcmp($mode, "NONE") ? $dis = " disabled" : $dis = ""; $ch = " checked"; $outstr .= ' <input type="radio" name="cooler" onchange="this.form.submit()" value="OFF"'.$dis.$ch.'>Off<br>'.PHP_EOL; $outstr .= ' <input type="radio" name="cooler" onchange="this.form.submit()" value="ON"'.$dis.'>On'.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; strcmp($mode, "NONE") ? $dis = " disabled" : $dis = ""; $outstr .= ' <input type="radio" name="heater" onchange="this.form.submit()" value="OFF"'.$dis.$ch.'>Off<br>'.PHP_EOL; $outstr .= ' <input type="radio" name="heater" onchange="this.form.submit()" value="ON"'.$dis.'>On'.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; strcmp($mode, "NONE") ? $dis = " disabled" : $dis = ""; $outstr .= ' <input type="radio" name="fan" onchange="this.form.submit()" value="OFF"'.$dis.$ch.'>Off<br>'.PHP_EOL; $outstr .= ' <input type="radio" name="fan" onchange="this.form.submit()" value="ON"'.$dis.'>On'.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> <!-- fermentor -->'.PHP_EOL; } return $outstr; } function liveview() { $outstr = PHP_EOL; $sock = open_socket(); if ($sock !== false) { socket_write($sock, "LIST", 4096); /* * Multiple reads until the remote closed the connection */ $answer = ""; while (1) { $line = socket_read($sock, 4096); if ($line === '') break; $answer .= $line; } socket_close($sock); $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); $i++; } } $outstr .= ' </div> <!-- jqxTabs -->'.PHP_EOL; } return $outstr; } ?>