Tue, 05 Aug 2014 15:44:29 +0200
Removing units thread
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 | |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
31 | $sock = open_socket(); |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
32 | if ($sock == false) { |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
33 | echo ""; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
34 | return; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
35 | } |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
36 | |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
171
diff
changeset
|
37 | socket_write($sock, 'UNIT GET '.$uuid, 4096); |
171
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
38 | $answer = ""; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
39 | while (1) { |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
40 | $line = socket_read($sock, 4096); |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
41 | if ($line === '') |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
42 | break; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
43 | $answer .= $line; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
44 | } |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
45 | socket_close($sock); |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
46 | |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
47 | $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
|
48 | |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
49 | $air_temperature = "NA"; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
50 | $air_state = "NA"; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
51 | $beer_temperature = "NA"; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
52 | $beer_state = "NA"; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
53 | $target_temperature = "NA"; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
54 | $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
|
55 | $fridge_set = "NA"; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
56 | $beer_set = "NA"; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
57 | |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
58 | 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
|
59 | $j = 1; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
60 | while (1) { |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
61 | 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
|
62 | break; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
63 | $f = explode(",", $arr[$j]); |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
64 | |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
65 | 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
|
66 | $air_state = $f[1]; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
67 | 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
|
68 | $air_temperature = $f[1]; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
69 | 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
|
70 | $beer_state = $f[1]; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
71 | 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
|
72 | $beer_temperature = $f[1]; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
73 | if ($f[0] == "MODE") |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
74 | $mode = $f[1]; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
75 | if ($f[0] == "COOLER_STATE") |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
76 | $led1 = $f[1]; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
77 | if ($f[0] == "HEATER_STATE") |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
78 | $led2 = $f[1]; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
79 | if ($f[0] == "FAN_STATE") |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
80 | $led3 = $f[1]; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
81 | 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
|
82 | $target_temperature = $f[1]; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
83 | 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
|
84 | $target_temperature = $f[1]; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
85 | 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
|
86 | $target_temperature = $f[1]; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
87 | $j++; |
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 | |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
92 | $reply = array ( |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
93 | 'air_temperature' => $air_temperature, |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
94 | 'beer_temperature' => $beer_temperature, |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
95 | 'target_temperature' => $target_temperature, |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
96 | 'mode' => $mode, |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
97 | 'led1' => $led1, |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
98 | 'led2' => $led2, |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
99 | 'led3' => $led3, |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
100 | 'sw1' => $sw1, |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
101 | 'sw2' => $sw2, |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
102 | 'sw3' => $sw3 |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
103 | ); |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
104 | |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
105 | |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
106 | echo json_encode($reply); |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
107 | ?> |