Fri, 01 Aug 2014 21:40:02 +0200
Ajax screen updates now use a single call to the server
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 | |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
37 | socket_write($sock, 'UNIT '.$uuid, 4096); |
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 | $sock = open_socket(); |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
48 | if ($sock == false) { |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
49 | echo ""; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
50 | return; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
51 | } |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
52 | |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
53 | socket_write($sock, 'LIST UNIT', 4096); |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
54 | $answer = ""; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
55 | while (1) { |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
56 | $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
|
57 | if ($line === '') |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
58 | break; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
59 | $answer .= $line; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
60 | } |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
61 | socket_close($sock); |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
62 | |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
63 | $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
|
64 | |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
65 | $air_temperature = "NA"; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
66 | $air_state = "NA"; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
67 | $beer_temperature = "NA"; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
68 | $beer_state = "NA"; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
69 | $target_temperature = "NA"; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
70 | $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
|
71 | $fridge_set = "NA"; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
72 | $beer_set = "NA"; |
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 | 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
|
75 | $j = 1; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
76 | while (1) { |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
77 | 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
|
78 | break; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
79 | $f = explode(",", $arr[$j]); |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
80 | |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
81 | 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
|
82 | $air_state = $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] == "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
|
84 | $air_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] == "BEER_STATE") |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
86 | $beer_state = $f[1]; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
87 | 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
|
88 | $beer_temperature = $f[1]; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
89 | if ($f[0] == "MODE") |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
90 | $mode = $f[1]; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
91 | 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
|
92 | $led1 = $f[1]; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
93 | 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
|
94 | $led2 = $f[1]; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
95 | 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
|
96 | $led3 = $f[1]; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
97 | 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
|
98 | $target_temperature = $f[1]; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
99 | 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
|
100 | $target_temperature = $f[1]; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
101 | 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
|
102 | $target_temperature = $f[1]; |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
103 | $j++; |
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 | |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
107 | |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
108 | $reply = array ( |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
109 | 'air_temperature' => $air_temperature, |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
110 | 'beer_temperature' => $beer_temperature, |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
111 | 'target_temperature' => $target_temperature, |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
112 | 'mode' => $mode, |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
113 | 'led1' => $led1, |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
114 | 'led2' => $led2, |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
115 | 'led3' => $led3, |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
116 | 'sw1' => $sw1, |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
117 | 'sw2' => $sw2, |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
118 | 'sw3' => $sw3 |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
119 | ); |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
120 | |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
121 | |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
122 | echo json_encode($reply); |
15f92e5eecef
Ajax screen updates now use a single call to the server
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
123 | ?> |