www/getispindellog.php

Wed, 06 Dec 2023 20:26:00 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 06 Dec 2023 20:26:00 +0100
changeset 855
2d328a2a4025
parent 848
542bdc7f6522
permissions
-rw-r--r--

Fixed init scripts names in Makefile. Update crontasks to use the database to check the log entries for products.

580
9cd6873bda75 Fixed ispindel_death. Added ispindel log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 <?php
9cd6873bda75 Fixed ispindel_death. Added ispindel log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2
9cd6873bda75 Fixed ispindel_death. Added ispindel log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 require_once('config.php');
9cd6873bda75 Fixed ispindel_death. Added ispindel log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4
9cd6873bda75 Fixed ispindel_death. Added ispindel log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 if (isset($_GET["code"]))
837
b5e2ff72cc73 Switch ispindel graph to MySQL
Michiel Broek <mbroek@mbse.eu>
parents: 627
diff changeset
6 $code = $_GET["code"];
580
9cd6873bda75 Fixed ispindel_death. Added ispindel log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 else
837
b5e2ff72cc73 Switch ispindel graph to MySQL
Michiel Broek <mbroek@mbse.eu>
parents: 627
diff changeset
8 $code = "CB0111";
580
9cd6873bda75 Fixed ispindel_death. Added ispindel log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9
837
b5e2ff72cc73 Switch ispindel graph to MySQL
Michiel Broek <mbroek@mbse.eu>
parents: 627
diff changeset
10 $connect = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME);
b5e2ff72cc73 Switch ispindel graph to MySQL
Michiel Broek <mbroek@mbse.eu>
parents: 627
diff changeset
11 if (! $connect) {
b5e2ff72cc73 Switch ispindel graph to MySQL
Michiel Broek <mbroek@mbse.eu>
parents: 627
diff changeset
12 die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
601
112c278be803 All graph displays now check if the log excists.
Michiel Broek <mbroek@mbse.eu>
parents: 580
diff changeset
13 }
837
b5e2ff72cc73 Switch ispindel graph to MySQL
Michiel Broek <mbroek@mbse.eu>
parents: 627
diff changeset
14 mysqli_set_charset($connect, "utf8" );
580
9cd6873bda75 Fixed ispindel_death. Added ispindel log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15
848
542bdc7f6522 Backported battery capacity calculation and temperature compensation for iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 837
diff changeset
16 function HydroCorrection($mg, $tr, $tc)
542bdc7f6522 Backported battery capacity calculation and temperature compensation for iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 837
diff changeset
17 {
542bdc7f6522 Backported battery capacity calculation and temperature compensation for iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 837
diff changeset
18 $trf = $tr * 1.8 + 32;
542bdc7f6522 Backported battery capacity calculation and temperature compensation for iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 837
diff changeset
19 $tcf = $tc * 1.8 + 32;
542bdc7f6522 Backported battery capacity calculation and temperature compensation for iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 837
diff changeset
20
542bdc7f6522 Backported battery capacity calculation and temperature compensation for iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 837
diff changeset
21 return $mg * ((1.00130346 - 1.34722124E-4 * $trf + 2.04052596E-6 * $trf * $trf - 2.32820948E-9 * $trf * $trf * $trf) /
542bdc7f6522 Backported battery capacity calculation and temperature compensation for iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 837
diff changeset
22 (1.00130346 - 1.34722124E-4 * $tcf + 2.04052596E-6 * $tcf * $tcf - 2.32820948E-9 * $tcf * $tcf * $tcf));
542bdc7f6522 Backported battery capacity calculation and temperature compensation for iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 837
diff changeset
23 }
542bdc7f6522 Backported battery capacity calculation and temperature compensation for iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 837
diff changeset
24
837
b5e2ff72cc73 Switch ispindel graph to MySQL
Michiel Broek <mbroek@mbse.eu>
parents: 627
diff changeset
25 $query = "SELECT * FROM log_ispindel WHERE code='".$code."' ORDER BY datetime;";
b5e2ff72cc73 Switch ispindel graph to MySQL
Michiel Broek <mbroek@mbse.eu>
parents: 627
diff changeset
26 $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect));
b5e2ff72cc73 Switch ispindel graph to MySQL
Michiel Broek <mbroek@mbse.eu>
parents: 627
diff changeset
27 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
580
9cd6873bda75 Fixed ispindel_death. Added ispindel log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28
848
542bdc7f6522 Backported battery capacity calculation and temperature compensation for iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 837
diff changeset
29 $SG = HydroCorrection($row['sg'], $row['temperature'], 20.0);
837
b5e2ff72cc73 Switch ispindel graph to MySQL
Michiel Broek <mbroek@mbse.eu>
parents: 627
diff changeset
30 $logs[] = array(
b5e2ff72cc73 Switch ispindel graph to MySQL
Michiel Broek <mbroek@mbse.eu>
parents: 627
diff changeset
31 'date' => substr($row['datetime'],0,16),
b5e2ff72cc73 Switch ispindel graph to MySQL
Michiel Broek <mbroek@mbse.eu>
parents: 627
diff changeset
32 'temperature' => $row['temperature'],
b5e2ff72cc73 Switch ispindel graph to MySQL
Michiel Broek <mbroek@mbse.eu>
parents: 627
diff changeset
33 'plato' => $row['plato'],
848
542bdc7f6522 Backported battery capacity calculation and temperature compensation for iSpindel.
Michiel Broek <mbroek@mbse.eu>
parents: 837
diff changeset
34 'sg' => $SG,
837
b5e2ff72cc73 Switch ispindel graph to MySQL
Michiel Broek <mbroek@mbse.eu>
parents: 627
diff changeset
35 'battery' => $row['battery']
b5e2ff72cc73 Switch ispindel graph to MySQL
Michiel Broek <mbroek@mbse.eu>
parents: 627
diff changeset
36 );
580
9cd6873bda75 Fixed ispindel_death. Added ispindel log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37 }
9cd6873bda75 Fixed ispindel_death. Added ispindel log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 header("Content-type: application/json");
9cd6873bda75 Fixed ispindel_death. Added ispindel log graph.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39 echo json_encode($logs);

mercurial