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

171
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 <?php
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 /*****************************************************************************
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 * Copyright (C) 2014
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 *
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 * Michiel Broek <mbroek at mbse dot eu>
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 *
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 * This file is part of ThermFerm
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 *
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * This is free software; you can redistribute it and/or modify it
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * under the terms of the GNU General Public License as published by the
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * Free Software Foundation; either version 2, or (at your option) any
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 * later version.
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 *
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * ThermFerm is distributed in the hope that it will be useful, but
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 * General Public License for more details.
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 *
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 * along with ThermFerm; see the file COPYING. If not, write to the Free
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22 *****************************************************************************/
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24 require_once('utilities.php');
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26 if (isset($_GET["uuid"]))
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 $uuid = $_GET["uuid"];
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28 else
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29 $uuid = "0e261929-486d-4117-897a-2b23509157c6";
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30
196
4d7a96c5d1ff Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 193
diff changeset
31 $answer = send_cmd('UNIT GET '.$uuid);
171
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32 $arr = explode("\r\n", $answer);
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34 $air_temperature = "NA";
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35 $air_state = "NA";
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36 $beer_temperature = "NA";
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37 $beer_state = "NA";
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 $target_temperature = "NA";
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39 $led1 = $led2 = $led3 = $sw1 = $sw2 = $sw3 = 0;
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40 $fridge_set = "NA";
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41 $beer_set = "NA";
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43 if (startsWith($arr[0], "213")) {
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44 $j = 1;
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45 while (1) {
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46 if (strcmp($arr[$j], ".") == 0)
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47 break;
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48 $f = explode(",", $arr[$j]);
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50 if ($f[0] == "AIR_STATE")
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51 $air_state = $f[1];
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52 if (($f[0] == "AIR_TEMPERATURE") && ($air_state == "OK"))
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
53 $air_temperature = $f[1];
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54 if ($f[0] == "BEER_STATE")
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
55 $beer_state = $f[1];
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
56 if (($f[0] == "BEER_TEMPERATURE") && ($beer_state == "OK"))
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57 $beer_temperature = $f[1];
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
58 if ($f[0] == "MODE")
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59 $mode = $f[1];
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60 if ($f[0] == "COOLER_STATE")
193
4136193a0c22 Auto refresh LED's state added.
Michiel Broek <mbroek@mbse.eu>
parents: 175
diff changeset
61 $led1 = $f[1] ? '<img src="images/led_green_on.png">' : '<img src="images/led_green_off.png">';
171
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62 if ($f[0] == "HEATER_STATE")
193
4136193a0c22 Auto refresh LED's state added.
Michiel Broek <mbroek@mbse.eu>
parents: 175
diff changeset
63 $led2 = $f[1] ? '<img src="images/led_green_on.png">' : '<img src="images/led_green_off.png">';
171
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
64 if ($f[0] == "FAN_STATE")
193
4136193a0c22 Auto refresh LED's state added.
Michiel Broek <mbroek@mbse.eu>
parents: 175
diff changeset
65 $led3 = $f[1] ? '<img src="images/led_green_on.png">' : '<img src="images/led_green_off.png">';
171
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
66 if (($f[0] == "BEER_SET") && ($mode == "BEER"))
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67 $target_temperature = $f[1];
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68 if (($f[0] == "FRIDGE_SET") && ($mode == "FRIDGE"))
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69 $target_temperature = $f[1];
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
70 if (($f[0] == "PROF_TARGET") && ($mode == "PROFILE"))
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
71 $target_temperature = $f[1];
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72 $j++;
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73 }
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74 }
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
76
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
77 $reply = array (
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
78 'air_temperature' => $air_temperature,
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
79 'beer_temperature' => $beer_temperature,
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
80 'target_temperature' => $target_temperature,
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81 'mode' => $mode,
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
82 'led1' => $led1,
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
83 'led2' => $led2,
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
84 'led3' => $led3,
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
85 'sw1' => $sw1,
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
86 'sw2' => $sw2,
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
87 'sw3' => $sw3
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
88 );
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
89
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
90
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
91 echo json_encode($reply);
15f92e5eecef Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
92 ?>

mercurial