Wed, 30 Jul 2014 23:06:46 +0200
Update LCD even when unit is off
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 | function open_socket() | |
26 | { | |
27 | $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); | |
28 | ||
29 | if (!($sock === false)) { | |
127
f2f45c44942f
Added the maintenance 1-Wire display tab
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
30 | // if (socket_connect($sock, "rpi02", 6554)) { |
100 | 31 | if (socket_connect($sock, "localhost", 6554)) { |
32 | socket_set_option($sock, SOL_SOCKET, SO_RCVTIMEO, array('sec' => 15, 'usec' => 0)); | |
33 | } else { | |
34 | socket_close($sock); | |
35 | } | |
36 | } | |
37 | return $sock; | |
38 | } | |
39 | ||
40 | ||
41 | ||
42 | function startsWith($haystack, $needle) | |
43 | { | |
44 | return !strncmp($haystack, $needle, strlen($needle)); | |
45 | } | |
46 | ||
47 | ||
134
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
48 | |
137
e4518fd9b626
Profiles can be managed via the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
134
diff
changeset
|
49 | function build_header($heading) |
134
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
50 | { |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
51 | $outstr = '<!DOCTYPE html>'.PHP_EOL; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
52 | $outstr .= '<html>'.PHP_EOL; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
53 | $outstr .= ' <head>'.PHP_EOL; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
54 | $outstr .= ' <meta http-equiv="content-type" content="text/html; charset=utf-8" />'.PHP_EOL; |
137
e4518fd9b626
Profiles can be managed via the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
134
diff
changeset
|
55 | $outstr .= ' <title>'.$heading.'</title>'.PHP_EOL; |
134
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
56 | $outstr .= ' <link type="text/css" href="css/style.css" rel="stylesheet" media="all" />'.PHP_EOL; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
57 | $outstr .= ' </head>'.PHP_EOL; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
58 | $outstr .= ' <body class="default">'.PHP_EOL; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
59 | $outstr .= ' <div id="jqxWidget">'.PHP_EOL; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
60 | $outstr .= ' <div id="header">'.PHP_EOL; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
61 | $outstr .= ' <form action="maintenance.php" style="margin:30px; float:right">'.PHP_EOL; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
62 | $outstr .= ' <input type="submit" class="jqx-button" value="Maintenance Panel" />'.PHP_EOL; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
63 | $outstr .= ' </form>'.PHP_EOL; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
64 | $outstr .= ' </div> <!-- header -->'.PHP_EOL; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
65 | $outstr .= ' <div id="content">'.PHP_EOL; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
66 | |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
67 | return $outstr; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
68 | } |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
69 | |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
70 | |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
71 | |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
72 | function build_footer() |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
73 | { |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
74 | $outstr = ' </div> <!-- content -->'.PHP_EOL; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
75 | $outstr .= ' </div> <!-- jqxWidget -->'.PHP_EOL; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
76 | $outstr .= ' </body>'.PHP_EOL; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
77 | $outstr .= '</html>'.PHP_EOL; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
78 | |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
79 | return $outstr; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
80 | } |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
81 | |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
82 | |
137
e4518fd9b626
Profiles can be managed via the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
134
diff
changeset
|
83 | |
e4518fd9b626
Profiles can be managed via the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
134
diff
changeset
|
84 | /* |
e4518fd9b626
Profiles can be managed via the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
134
diff
changeset
|
85 | * Goto URL. Works also after headers have been sent. |
e4518fd9b626
Profiles can be managed via the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
134
diff
changeset
|
86 | */ |
e4518fd9b626
Profiles can be managed via the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
134
diff
changeset
|
87 | function load($url) { |
e4518fd9b626
Profiles can be managed via the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
134
diff
changeset
|
88 | echo' |
e4518fd9b626
Profiles can be managed via the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
134
diff
changeset
|
89 | <script> |
e4518fd9b626
Profiles can be managed via the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
134
diff
changeset
|
90 | if (top.location != self.location) { |
e4518fd9b626
Profiles can be managed via the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
134
diff
changeset
|
91 | top.location = "'.$url.'" |
e4518fd9b626
Profiles can be managed via the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
134
diff
changeset
|
92 | } |
e4518fd9b626
Profiles can be managed via the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
134
diff
changeset
|
93 | {location.href="'.$url.'";} |
e4518fd9b626
Profiles can be managed via the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
134
diff
changeset
|
94 | </script>'; |
e4518fd9b626
Profiles can be managed via the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
134
diff
changeset
|
95 | } |
e4518fd9b626
Profiles can be managed via the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
134
diff
changeset
|
96 | |
155
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
97 | |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
98 | /* |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
99 | * Send command |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
100 | */ |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
101 | function send_cmd($cmd) { |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
102 | $sock = open_socket(); |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
103 | if ($sock != false) { |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
104 | /* |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
105 | * Send command and absorb the result. |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
106 | */ |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
107 | socket_write($sock, $cmd, 4096); |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
108 | while (1) { |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
109 | $line = socket_read($sock, 4096); |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
110 | if ($line === '') |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
111 | break; |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
112 | } |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
113 | socket_close($sock); |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
114 | } |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
115 | } |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
116 | |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
117 |