www-thermferm/getlog.php

Tue, 22 Jul 2014 23:14:19 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Tue, 22 Jul 2014 23:14:19 +0200
changeset 123
597688feda2f
child 191
c74bbc24a1c8
permissions
-rw-r--r--

Now uses the real data for the chart

123
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 <?php
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 /*****************************************************************************
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 * Copyright (C) 2014
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 *
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 * Michiel Broek <mbroek at mbse dot eu>
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 *
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 * This file is part of ThermFerm
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 *
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * This is free software; you can redistribute it and/or modify it
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * under the terms of the GNU General Public License as published by the
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * Free Software Foundation; either version 2, or (at your option) any
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 * later version.
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 *
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * ThermFerm is distributed in the hope that it will be useful, but
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 * General Public License for more details.
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 *
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 * along with ThermFerm; see the file COPYING. If not, write to the Free
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22 *****************************************************************************/
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24 require_once('utilities.php');
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26 $unit = $_GET["unit"];
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28 $sock = open_socket();
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29 if ($sock == false) {
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30 echo "";
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31 return;
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32 }
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34 socket_write($sock, "UNIT " . $unit, 4096);
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35 $answer = "";
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36 while (1) {
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37 $line = socket_read($sock, 4096);
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 if ($line === '')
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39 break;
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40 $answer .= $line;
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41 }
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42 socket_close($sock);
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44 $sock = open_socket();
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45 if ($sock == false) {
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46 echo "";
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47 return;
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48 }
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50 socket_write($sock, "LIST LOG", 4096);
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51 $answer = "";
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52 while (1) {
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
53 $line = socket_read($sock, 4096);
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54 if ($line === '')
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
55 break;
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
56 $answer .= $line;
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57 }
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
58 socket_close($sock);
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59 $arr = explode("\r\n", $answer);
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62 //$data[] = array('Date','Mode','Air','Beer','Target','Heater','Cooler','Fan','Door');
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
63 $row = '[';
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
64
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
65 /* We don't use json_encode because it doesn't work for our purpose */
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
66 if (startsWith($arr[0], "212")) {
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67 $j = 1;
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68 while (1) {
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69 if (strcmp($arr[$j], ".") == 0)
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
70 break;
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
71 if ($j > 1)
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72 $row .= ',';
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73 $f = explode(",", $arr[$j]);
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74 $row .= '{"Date":"'.$f[0].'","Mode":"'.$f[1].'","Air":"'.$f[2].'","Beer":"'.$f[3].'","Target":"'.$f[4].'",';
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75 $row .= '"Heater":"'.$f[5].'","Cooler":"'.$f[6].'","Fan":"'.$f[7].'","Door":"'.$f[8].'"}';
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
76 $j++;
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
77 }
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
78 }
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
79
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
80 $row .= ']';
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81 echo $row;
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
82
597688feda2f Now uses the real data for the chart
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
83 ?>

mercurial