www/getispindellog.php

branch
stable
changeset 665
4d01937ae7af
parent 627
f1a7c14d5601
child 837
b5e2ff72cc73
equal deleted inserted replaced
521:9d1aa6f3a4da 665:4d01937ae7af
1 <?php
2
3 require_once('config.php');
4
5 if (isset($_GET["code"]))
6 $code = $_GET["code"] . ' ' . $_GET["name"];
7 else
8 $code = "CB0081 Keuls";
9
10 $filename = 'log/ispindel/' . $code . '.log';
11 if (! file_exists($filename)) {
12 header("Content-type: application/json");
13 echo '{}';
14 exit;
15 }
16
17
18 /*
19 * 2014-11-15 18:39:12,TEMPERATURE,PLATO,SG,BATTERY,ANGLE,INVERVAL,UUID
20 * | | | | |
21 * datetime + | | | |
22 * temperature ------------+ | | |
23 * density plato --------------------+ | |
24 * density sg ----------------------------+ |
25 * battery ------------------------------------+
26 */
27 $handle = @fopen($filename, "r");
28 if ($handle) {
29 $lines = 0;
30 while (($buffer = fgets($handle, 4096)) !== false) {
31
32 $buffer = preg_replace( "/\r|\n/", "", $buffer);
33 $row = explode(",", $buffer);
34 $lines++;
35
36 $logs[] = array(
37 'date' => $row[0],
38 'temperature' => $row[1],
39 'plato' => $row[2],
40 'sg' => $row[3],
41 'battery' => $row[4]
42 );
43 }
44 if (!feof($handle)) {
45 echo "Error: unexpected fgets() fail\n";
46 }
47 fclose($handle);
48 }
49 header("Content-type: application/json");
50 echo json_encode($logs);

mercurial