www/getco2pressurelog.php

Wed, 10 Aug 2022 15:40:20 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 10 Aug 2022 15:40:20 +0200
changeset 838
ce5f39b66a51
parent 600
c136dd22f662
permissions
-rw-r--r--

Switch co2pressure graph to MySQL

507
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 <?php
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 require_once('config.php');
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 if (isset($_GET["code"]))
838
ce5f39b66a51 Switch co2pressure graph to MySQL
Michiel Broek <mbroek@mbse.eu>
parents: 600
diff changeset
6 $code = $_GET["code"];
507
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 else
838
ce5f39b66a51 Switch co2pressure graph to MySQL
Michiel Broek <mbroek@mbse.eu>
parents: 600
diff changeset
8 $code = "CB0080";
507
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 /*
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 * 2014-11-15 18:39:12,TEMPERATURE,PRESSURE,UUID
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 * | | | |
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * datetime + | | |
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * temperature ------------+ | |
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 * pressure --------------------------+ |
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 * unit uuid --------------------------------+
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 */
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19
838
ce5f39b66a51 Switch co2pressure graph to MySQL
Michiel Broek <mbroek@mbse.eu>
parents: 600
diff changeset
20 $connect = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME);
ce5f39b66a51 Switch co2pressure graph to MySQL
Michiel Broek <mbroek@mbse.eu>
parents: 600
diff changeset
21 if (! $connect) {
ce5f39b66a51 Switch co2pressure graph to MySQL
Michiel Broek <mbroek@mbse.eu>
parents: 600
diff changeset
22 die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
ce5f39b66a51 Switch co2pressure graph to MySQL
Michiel Broek <mbroek@mbse.eu>
parents: 600
diff changeset
23 }
ce5f39b66a51 Switch co2pressure graph to MySQL
Michiel Broek <mbroek@mbse.eu>
parents: 600
diff changeset
24 mysqli_set_charset($connect, "utf8" );
507
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25
838
ce5f39b66a51 Switch co2pressure graph to MySQL
Michiel Broek <mbroek@mbse.eu>
parents: 600
diff changeset
26 $query = "SELECT * FROM log_co2pressure WHERE code='".$code."' ORDER BY datetime;";
ce5f39b66a51 Switch co2pressure graph to MySQL
Michiel Broek <mbroek@mbse.eu>
parents: 600
diff changeset
27 $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect));
ce5f39b66a51 Switch co2pressure graph to MySQL
Michiel Broek <mbroek@mbse.eu>
parents: 600
diff changeset
28 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
ce5f39b66a51 Switch co2pressure graph to MySQL
Michiel Broek <mbroek@mbse.eu>
parents: 600
diff changeset
29
ce5f39b66a51 Switch co2pressure graph to MySQL
Michiel Broek <mbroek@mbse.eu>
parents: 600
diff changeset
30 $logs[] = array(
ce5f39b66a51 Switch co2pressure graph to MySQL
Michiel Broek <mbroek@mbse.eu>
parents: 600
diff changeset
31 'date' => substr($row['datetime'],0,16),
ce5f39b66a51 Switch co2pressure graph to MySQL
Michiel Broek <mbroek@mbse.eu>
parents: 600
diff changeset
32 'temperature' => $row['temperature'],
ce5f39b66a51 Switch co2pressure graph to MySQL
Michiel Broek <mbroek@mbse.eu>
parents: 600
diff changeset
33 'pressure' => $row['pressure']
ce5f39b66a51 Switch co2pressure graph to MySQL
Michiel Broek <mbroek@mbse.eu>
parents: 600
diff changeset
34 );
507
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35 }
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36 header("Content-type: application/json");
17f244137a9b Add refermentation logfile and graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37 echo json_encode($logs);

mercurial