# HG changeset patch # User Michiel Broek # Date 1406922002 -7200 # Node ID 15f92e5eecef415f0892a9a6fd0e8d2586b1ec2a # Parent 3cb99272b84b730d1be0394bad3ce35b21d94793 Ajax screen updates now use a single call to the server diff -r 3cb99272b84b -r 15f92e5eecef www-thermferm/getdata.php --- a/www-thermferm/getdata.php Fri Aug 01 16:13:55 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ - - * - * 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'); - -$what = $_GET['what']; -$uuid = $_GET["uuid"]; - -$sock = open_socket(); -if ($sock == false) { - echo ""; - return; -} - -socket_write($sock, 'GET '.$what.' '.$uuid, 4096); -$answer = ""; -while (1) { - $line = socket_read($sock, 4096); - if ($line === '') - break; - $answer .= $line; -} -socket_close($sock); - -$arr = explode(",", $answer); - - -echo $arr[1]; - -?> diff -r 3cb99272b84b -r 15f92e5eecef www-thermferm/getstate.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/www-thermferm/getstate.php Fri Aug 01 21:40:02 2014 +0200 @@ -0,0 +1,123 @@ + + * + * 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'); + +if (isset($_GET["uuid"])) + $uuid = $_GET["uuid"]; +else + $uuid = "0e261929-486d-4117-897a-2b23509157c6"; + +$sock = open_socket(); +if ($sock == false) { + echo ""; + return; +} + +socket_write($sock, 'UNIT '.$uuid, 4096); +$answer = ""; +while (1) { + $line = socket_read($sock, 4096); + if ($line === '') + break; + $answer .= $line; +} +socket_close($sock); + +$sock = open_socket(); +if ($sock == false) { + echo ""; + 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); + +$air_temperature = "NA"; +$air_state = "NA"; +$beer_temperature = "NA"; +$beer_state = "NA"; +$target_temperature = "NA"; +$led1 = $led2 = $led3 = $sw1 = $sw2 = $sw3 = 0; +$fridge_set = "NA"; +$beer_set = "NA"; + +if (startsWith($arr[0], "213")) { + $j = 1; + while (1) { + if (strcmp($arr[$j], ".") == 0) + break; + $f = explode(",", $arr[$j]); + + if ($f[0] == "AIR_STATE") + $air_state = $f[1]; + if (($f[0] == "AIR_TEMPERATURE") && ($air_state == "OK")) + $air_temperature = $f[1]; + if ($f[0] == "BEER_STATE") + $beer_state = $f[1]; + if (($f[0] == "BEER_TEMPERATURE") && ($beer_state == "OK")) + $beer_temperature = $f[1]; + if ($f[0] == "MODE") + $mode = $f[1]; + if ($f[0] == "COOLER_STATE") + $led1 = $f[1]; + if ($f[0] == "HEATER_STATE") + $led2 = $f[1]; + if ($f[0] == "FAN_STATE") + $led3 = $f[1]; + if (($f[0] == "BEER_SET") && ($mode == "BEER")) + $target_temperature = $f[1]; + if (($f[0] == "FRIDGE_SET") && ($mode == "FRIDGE")) + $target_temperature = $f[1]; + if (($f[0] == "PROF_TARGET") && ($mode == "PROFILE")) + $target_temperature = $f[1]; + $j++; + } +} + + +$reply = array ( + 'air_temperature' => $air_temperature, + 'beer_temperature' => $beer_temperature, + 'target_temperature' => $target_temperature, + 'mode' => $mode, + 'led1' => $led1, + 'led2' => $led2, + 'led3' => $led3, + 'sw1' => $sw1, + 'sw2' => $sw2, + 'sw3' => $sw3 +); + + +echo json_encode($reply); +?> diff -r 3cb99272b84b -r 15f92e5eecef www-thermferm/liveview.php --- a/www-thermferm/liveview.php Fri Aug 01 16:13:55 2014 +0200 +++ b/www-thermferm/liveview.php Fri Aug 01 21:40:02 2014 +0200 @@ -160,18 +160,13 @@ $outstr .= ' }]'.PHP_EOL; $outstr .= ' };'.PHP_EOL; $outstr .= ' $("#fermentor_chart_'.$unit.'").jqxChart(settings'.$unr.');'.PHP_EOL; - $outstr .= ' var target_refresh_'.$unr.' = setInterval('.PHP_EOL; - $outstr .= ' function () {'.PHP_EOL; - $outstr .= ' $("#load_target_'.$unr.'").load("getdata.php?uuid='.$unit.'&what=TARGET").fadeIn("slow");'.PHP_EOL; - $outstr .= ' }, 65000);'.PHP_EOL; - $outstr .= ' var air_refresh_'.$unr.' = setInterval('.PHP_EOL; - $outstr .= ' function () {'.PHP_EOL; - $outstr .= ' $("#load_air_'.$unr.'").load("getdata.php?uuid='.$unit.'&what=AIR").fadeIn("slow");'.PHP_EOL; - $outstr .= ' }, 10001);'.PHP_EOL; - $outstr .= ' var beer_refresh_'.$unr.' = setInterval('.PHP_EOL; - $outstr .= ' function () {'.PHP_EOL; - $outstr .= ' $("#load_beer_'.$unr.'").load("getdata.php?uuid='.$unit.'&what=BEER").fadeIn("slow");'.PHP_EOL; - $outstr .= ' }, 10100);'.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 .= ' });'.PHP_EOL; + $outstr .= ' }, 10000);'.PHP_EOL; $outstr .= ' });'.PHP_EOL; $outstr .= ' '.PHP_EOL; $outstr .= '
'.PHP_EOL;