www/getispindellog.php

changeset 580
9cd6873bda75
child 601
112c278be803
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/www/getispindellog.php	Sun Jan 05 20:00:39 2020 +0100
@@ -0,0 +1,45 @@
+<?php
+
+require_once('config.php');
+
+if (isset($_GET["code"]))
+	$code = $_GET["code"] . ' ' . $_GET["name"];
+else
+	$code = "TB0091 Kwik";
+
+$filename = 'log/ispindel/' . $code . '.log';
+
+/*
+ * 2014-11-15 18:39:12,TEMPERATURE,PLATO,SG,BATTERY,ANGLE,INVERVAL,UUID
+ *          |              |         |    |    |
+ * datetime +              |         |    |    |
+ * temperature ------------+         |    |    |
+ * density plato --------------------+    |    |
+ * density sg ----------------------------+    |
+ * battery ------------------------------------+
+ */
+$handle = @fopen($filename, "r");
+if ($handle) {
+	$lines = 0;
+	while (($buffer = fgets($handle, 4096)) !== false) {
+
+		$buffer = preg_replace( "/\r|\n/", "", $buffer);
+		$row = explode(",", $buffer);
+		$lines++;
+
+		$logs[] = array(
+			'date' => $row[0],
+			'temperature' => $row[1],
+			'plato' => $row[2],
+			'sg' => $row[3],
+			'battery' => $row[4]
+		);
+	}
+	if (!feof($handle)) {
+		echo "Error: unexpected fgets() fail\n";
+	}
+	fclose($handle);
+}
+header("Content-type: application/json");
+echo json_encode($logs);
+//echo $lines . ' lines' . PHP_EOL;

mercurial