www-thermferm/getstate.php

Sat, 09 Aug 2014 11:29:02 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 09 Aug 2014 11:29:02 +0200
changeset 196
4d7a96c5d1ff
parent 193
4136193a0c22
child 225
b18b06c17a80
permissions
-rw-r--r--

Code cleanup

<?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";

$answer = send_cmd('UNIT GET '.$uuid);
$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] ? '<img src="images/led_green_on.png">' : '<img src="images/led_green_off.png">';
	if ($f[0] == "HEATER_STATE")
		$led2 = $f[1] ? '<img src="images/led_green_on.png">' : '<img src="images/led_green_off.png">';
	if ($f[0] == "FAN_STATE")
		$led3 = $f[1] ? '<img src="images/led_green_on.png">' : '<img src="images/led_green_off.png">';
	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);
?>

mercurial