Wed, 16 Jul 2014 13:42:14 +0200
Added buttons
100 | 1 | <?php |
2 | /***************************************************************************** | |
3 | * Copyright (C) 2014 | |
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 | ||
25 | require_once('utilities.php'); | |
26 | ||
27 | ||
28 | ||
29 | function showunit($unit) | |
30 | { | |
31 | $outstr = ''; | |
102
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
32 | $air_state = $beer_state = 1; |
100 | 33 | |
34 | $sock = open_socket(); | |
35 | if ($sock == false) { | |
36 | return ''; | |
37 | } | |
38 | ||
39 | socket_write($sock, "UNIT " . $unit, 4096); | |
40 | $answer = ""; | |
41 | while (1) { | |
42 | $line = socket_read($sock, 4096); | |
43 | if ($line === '') | |
44 | break; | |
45 | $answer .= $line; | |
46 | } | |
47 | socket_close($sock); | |
48 | ||
49 | $sock = open_socket(); | |
50 | if ($sock == false) { | |
51 | return ''; | |
52 | } | |
53 | ||
54 | socket_write($sock, "LIST UNIT", 4096); | |
55 | $answer = ""; | |
56 | while (1) { | |
57 | $line = socket_read($sock, 4096); | |
58 | if ($line === '') | |
59 | break; | |
60 | $answer .= $line; | |
61 | } | |
62 | socket_close($sock); | |
63 | $arr = explode("\r\n", $answer); | |
64 | ||
65 | if (startsWith($arr[0], "213")) { | |
66 | ||
67 | $outstr .= ' <div id="fermentor">'.PHP_EOL; | |
68 | ||
69 | foreach($arr as $l) { | |
70 | $vals = explode(",", $l); | |
71 | if (strcmp($vals[0], "NAME") == 0) { | |
72 | /* | |
73 | * The name is allways first, so when we have it | |
74 | * emit the formatting. | |
75 | */ | |
76 | $outstr .= ' <div id="fermentor_head">'.PHP_EOL; | |
77 | $outstr .= ' ' . $vals[1] .PHP_EOL; | |
78 | $outstr .= ' </div>'.PHP_EOL; | |
79 | $outstr .= ' <div id="fermentor_pict">'.PHP_EOL; | |
80 | $outstr .= ' <img src="images/Fermenter_60l.gif">'.PHP_EOL; | |
81 | $outstr .= ' </div>'.PHP_EOL; | |
82 | $outstr .= ' <div id="fermentor_control">'.PHP_EOL; | |
83 | } | |
84 | if (strcmp($vals[0], "MODE") == 0) { | |
85 | $outstr .= ' mode ' . $vals[1] . '<br>' .PHP_EOL; | |
86 | } | |
102
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
87 | if (strcmp($vals[0], "AIR_STATE") == 0) { |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
88 | $air_state = $vals[1]; |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
89 | } |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
90 | if (strcmp($vals[0], "AIR_TEMPERATURE") == 0) { |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
91 | if ($air_state == 0) |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
92 | $outstr .= ' air temperature ' . $vals[1] . '<br>' .PHP_EOL; |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
93 | else |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
94 | $outstr .= ' air temperature N/A<br>' .PHP_EOL; |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
95 | } |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
96 | if (strcmp($vals[0], "BEER_STATE") == 0) { |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
97 | $beer_state = $vals[1]; |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
98 | } |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
99 | if (strcmp($vals[0], "BEER_TEMPERATURE") == 0) { |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
100 | if ($beer_state == 0) |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
101 | $outstr .= ' beer temperature ' . $vals[1] . '<br>' .PHP_EOL; |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
102 | else |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
103 | $outstr .= ' beer temperature N/A<br>' .PHP_EOL; |
e37b9c571a56
Units can display the temperature
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
104 | } |
100 | 105 | } |
106 | $outstr .= ' </div>'.PHP_EOL; | |
112 | 107 | $outstr .= ' <div id="fermentor_edit">'.PHP_EOL; |
108 | $outstr .= ' <button id="fermentor_setup" class="ui-state-default">Edit fermentor</button>'.PHP_EOL; | |
109 | $outstr .= ' </div>'.PHP_EOL; | |
110 | $outstr .= ' </div> <!-- fermentor -->'.PHP_EOL; | |
100 | 111 | } |
112 | ||
113 | return $outstr; | |
114 | } | |
115 | ||
116 | ||
117 | ||
118 | function liveview() | |
119 | { | |
120 | $outstr = PHP_EOL; | |
121 | ||
122 | $sock = open_socket(); | |
123 | if ($sock !== false) { | |
124 | socket_write($sock, "LIST", 4096); | |
125 | ||
126 | /* | |
127 | * Multiple reads until the remote closed the connection | |
128 | */ | |
129 | $answer = ""; | |
130 | while (1) { | |
131 | $line = socket_read($sock, 4096); | |
132 | if ($line === '') | |
133 | break; | |
134 | $answer .= $line; | |
135 | } | |
136 | socket_close($sock); | |
137 | $arr = explode("\r\n", $answer); | |
138 | ||
139 | if (startsWith($arr[0], "212")) { | |
140 | $i = 1; | |
141 | while (1) { | |
142 | if (strcmp($arr[$i], ".") == 0) | |
143 | break; | |
144 | $parts = explode(",", $arr[$i]); | |
145 | $outstr .= showunit($parts[1]); | |
146 | $i++; | |
147 | } | |
148 | } | |
149 | } | |
150 | ||
151 | return $outstr; | |
152 | } | |
153 | ||
154 | ||
155 | ||
156 | ?> |