www-thermferm/getlog.php

changeset 123
597688feda2f
child 191
c74bbc24a1c8
equal deleted inserted replaced
122:e57043423e72 123:597688feda2f
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 require_once('utilities.php');
25
26 $unit = $_GET["unit"];
27
28 $sock = open_socket();
29 if ($sock == false) {
30 echo "";
31 return;
32 }
33
34 socket_write($sock, "UNIT " . $unit, 4096);
35 $answer = "";
36 while (1) {
37 $line = socket_read($sock, 4096);
38 if ($line === '')
39 break;
40 $answer .= $line;
41 }
42 socket_close($sock);
43
44 $sock = open_socket();
45 if ($sock == false) {
46 echo "";
47 return;
48 }
49
50 socket_write($sock, "LIST LOG", 4096);
51 $answer = "";
52 while (1) {
53 $line = socket_read($sock, 4096);
54 if ($line === '')
55 break;
56 $answer .= $line;
57 }
58 socket_close($sock);
59 $arr = explode("\r\n", $answer);
60
61
62 //$data[] = array('Date','Mode','Air','Beer','Target','Heater','Cooler','Fan','Door');
63 $row = '[';
64
65 /* We don't use json_encode because it doesn't work for our purpose */
66 if (startsWith($arr[0], "212")) {
67 $j = 1;
68 while (1) {
69 if (strcmp($arr[$j], ".") == 0)
70 break;
71 if ($j > 1)
72 $row .= ',';
73 $f = explode(",", $arr[$j]);
74 $row .= '{"Date":"'.$f[0].'","Mode":"'.$f[1].'","Air":"'.$f[2].'","Beer":"'.$f[3].'","Target":"'.$f[4].'",';
75 $row .= '"Heater":"'.$f[5].'","Cooler":"'.$f[6].'","Fan":"'.$f[7].'","Door":"'.$f[8].'"}';
76 $j++;
77 }
78 }
79
80 $row .= ']';
81 echo $row;
82
83 ?>

mercurial