Tue, 05 Aug 2014 15:44:29 +0200
Removing units thread
<?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'); 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 GET '.$uuid, 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); ?>