www-thermferm/getstate.php

changeset 709
5b6d7b640e52
parent 708
13555c27b592
child 710
abe60578d695
equal deleted inserted replaced
708:13555c27b592 709:5b6d7b640e52
1 <?php
2 /*****************************************************************************
3 * Copyright (C) 2014-2019
4 *
5 * Michiel Broek <mbroek at mbse dot eu>
6 *
7 * This file is part of ThermFerm
8 *
9 * This is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2, or (at your option) any
12 * later version.
13 *
14 * ThermFerm is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with ThermFerm; see the file COPYING. If not, write to the Free
21 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
22 *****************************************************************************/
23
24 require_once('utilities.php');
25
26 if (isset($_GET["uuid"]))
27 $uuid = $_GET["uuid"];
28 else
29 $uuid = "e53858c3-a97e-4b07-85e9-524257909f45";
30
31 $answer = send_cmd('UNIT GET '.$uuid);
32 $arr = explode("\r\n", $answer);
33
34 $air_temperature = "NA";
35 $air_state = "NA";
36 $beer_temperature = "NA";
37 $beer_state = "NA";
38 $chiller_temperature = "NA";
39 $chiller_state = "NA";
40 $target_temperature_lo = "NA";
41 $target_temperature_hi = "NA";
42 $led1 = $led2 = $led3 = $sw1 = $sw2 = $sw3 = $alarmled = "";
43 $fridge_set = "NA";
44 $beer_set = "NA";
45 $heater = $cooler = $chiller = $fan = $psu = $door = "no";
46 $prof_state = "OFF";
47 $mode = "NA";
48 $cooler_state = "NA";
49 $heater_state = "NA";
50 $fan_state = "NA";
51
52 if (startsWith($arr[0], "213")) {
53 $j = 1;
54 while (1) {
55 if (strcmp($arr[$j], ".") == 0)
56 break;
57 $f = explode(",", $arr[$j]);
58
59 if ($f[0] == "AIR_STATE")
60 $air_state = $f[1];
61 if (($f[0] == "AIR_TEMPERATURE") && ($air_state == "YES"))
62 $air_temperature = $f[1];
63 if ($f[0] == "BEER_STATE")
64 $beer_state = $f[1];
65 if (($f[0] == "BEER_TEMPERATURE") && ($beer_state == "YES"))
66 $beer_temperature = $f[1];
67 if ($f[0] == "CHILLER_STATE")
68 $chiller_state = $f[1];
69 if (($f[0] == "CHILLER_TEMPERATURE") && ($chiller_state == "YES"))
70 $chiller_temperature = $f[1];
71 if ($f[0] == "MODE")
72 $mode = $f[1];
73 if (($f[0] == "COOLER_ADDRESS") && (strcmp($f[1], "(null)")))
74 $cooler = "yes";
75 if ($f[0] == "COOLER_STATE") {
76 $cooler_state = $f[1];
77 $led1 = $f[1] ? '<div class="LEDgreen_on"></div>' : '<div class="LEDgreen_off"></div>';
78 }
79 if (($f[0] == "HEATER_ADDRESS") && (strcmp($f[1], "(null)")))
80 $heater = "yes";
81 if ($f[0] == "HEATER_STATE") {
82 $heater_state = $f[1];
83 $led2 = $f[1] ? '<div class="LEDgreen_on"></div>' : '<div class="LEDgreen_off"></div>';
84 }
85 if (($f[0] == "FAN_ADDRESS") && (strcmp($f[1], "(null)")))
86 $fan = "yes";
87 if ($f[0] == "FAN_STATE") {
88 $fan_state = $f[1];
89 $led3 = $f[1] ? '<div class="LEDgreen_on"></div>' : '<div class="LEDgreen_off"></div>';
90 }
91 if (($f[0] == "PSU_ADDRESS") && (strcmp($f[1], "(null)")))
92 $psu = "yes";
93 if (($f[0] == "DOOR_ADDRESS") && (strcmp($f[1], "(null)")))
94 $door = "yes";
95 if (($f[0] == "BEER_SET_LO") && ($mode == "BEER"))
96 $target_temperature_lo = $f[1];
97 if (($f[0] == "BEER_SET_HI") && ($mode == "BEER"))
98 $target_temperature_hi = $f[1];
99 if (($f[0] == "FRIDGE_SET_LO") && ($mode == "FRIDGE"))
100 $target_temperature_lo = $f[1];
101 if (($f[0] == "FRIDGE_SET_HI") && ($mode == "FRIDGE"))
102 $target_temperature_hi = $f[1];
103 if (($f[0] == "PROF_TARGET_LO") && ($mode == "PROFILE"))
104 $target_temperature_lo = $f[1];
105 if (($f[0] == "PROF_TARGET_HI") && ($mode == "PROFILE"))
106 $target_temperature_hi = $f[1];
107 if (($f[0] == "PROF_STATE") && ($mode == "PROFILE"))
108 $prof_state = 'State: '.$f[1];
109 if ($f[0] == "ALARM")
110 $alarmled = $f[1] ? '<div class="LEDred_on"></div>' : '<div class="LEDred_off"></div>';
111 $j++;
112 }
113 }
114
115
116 /*
117 * Create the value for the mode select radio buttons
118 */
119 strcmp($mode, "OFF") ? $se = "" : $se = " checked";
120 $modestr = ' <input type="radio" name="mode" onchange="this.form.submit()" class="select" value="OFF"'.$se.'>Off<br>'.PHP_EOL;
121 strcmp($mode, "NONE") ? $se = "" : $se = " checked";
122 $modestr .= ' <input type="radio" name="mode" onchange="this.form.submit()" class="select" value="NONE"'.$se.'>None<br>'.PHP_EOL;
123 (strcmp($heater, "no") || strcmp($cooler, "no")) ? $dis = "" : $dis = " disabled";
124 strcmp($mode, "FRIDGE") ? $se = "" : $se = " checked";
125 $modestr .= ' <input type="radio" name="mode" onchange="this.form.submit()" class="select" value="FRIDGE"'.$se.$dis.'>Fridge<br>'.PHP_EOL;
126 strcmp($mode, "BEER") ? $se = "" : $se = " checked";
127 $modestr .= ' <input type="radio" name="mode" onchange="this.form.submit()" class="select" value="BEER"'.$se.$dis.'>Beer<br>'.PHP_EOL;
128 strcmp($mode, "PROFILE") ? $se = "" : $se = " checked";
129 $modestr .= ' <input type="radio" name="mode" onchange="this.form.submit()" class="select" value="PROFILE"'.$se.$dis.'>Profile'.PHP_EOL;
130
131
132 /*
133 * Create the values for the on/off switches
134 */
135 (($mode == "NONE") && ($cooler == "yes")) ? $dis = "" : $dis = " disabled";
136 ($cooler_state == "0") ? $ch = " checked" : $ch = "";
137 $sw1 = ' <input type="radio" name="CoolerState" onchange="this.form.submit()" value="0"'.$dis.$ch.'>Off<br>'.PHP_EOL;
138 ($cooler_state == "100") ? $ch = " checked" : $ch = "";
139 $sw1 .= ' <input type="radio" name="CoolerState" onchange="this.form.submit()" value="100"'.$dis.$ch.'>On'.PHP_EOL;
140
141 (($mode == "NONE") && ($heater == "yes")) ? $dis = "" : $dis = " disabled";
142 ($heater_state == "0") ? $ch = " checked" : $ch = "";
143 $sw2 = ' <input type="radio" name="HeaterState" onchange="this.form.submit()" value="0"'.$dis.$ch.'>Off<br>'.PHP_EOL;
144 ($heater_state == "100") ? $ch = " checked" : $ch = "";
145 $sw2 .= ' <input type="radio" name="HeaterState" onchange="this.form.submit()" value="100"'.$dis.$ch.'>On'.PHP_EOL;
146
147 (($mode == "NONE") && ($fan== "yes")) ? $dis = "" : $dis = " disabled";
148 ($fan_state == "0") ? $ch = " checked" : $ch = "";
149 $sw3 = ' <input type="radio" name="FanState" onchange="this.form.submit()" value="0"'.$dis.$ch.'>Off<br>'.PHP_EOL;
150 ($fan_state == "100") ? $ch = " checked" : $ch = "";
151 $sw3 .= ' <input type="radio" name="FanState" onchange="this.form.submit()" value="100"'.$dis.$ch.'>On'.PHP_EOL;
152
153
154
155 $reply = array (
156 'air_temperature' => $air_temperature,
157 'beer_temperature' => $beer_temperature,
158 'chiller_temperature' => $chiller_temperature,
159 'target_temperature_lo' => $target_temperature_lo,
160 'target_temperature_hi' => $target_temperature_hi,
161 'mode' => $modestr,
162 'led1' => $led1,
163 'led2' => $led2,
164 'led3' => $led3,
165 'sw1' => $sw1,
166 'sw2' => $sw2,
167 'sw3' => $sw3,
168 'profile_state' => $prof_state,
169 'alarm' => $alarmled
170 );
171
172
173 echo json_encode($reply);
174 ?>

mercurial