www/getispindellog.php

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

mercurial