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.

<?php

require_once('config.php');

if (isset($_GET["code"]))
	$code = $_GET["code"];
else
	$code = "CB0111";

$connect = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME);
if (! $connect) {
        die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
}
mysqli_set_charset($connect, "utf8" );

function HydroCorrection($mg, $tr, $tc)
{
    $trf = $tr * 1.8 + 32;
    $tcf = $tc * 1.8 + 32;

    return $mg * ((1.00130346 - 1.34722124E-4 * $trf + 2.04052596E-6 * $trf * $trf - 2.32820948E-9 * $trf * $trf * $trf) /
                  (1.00130346 - 1.34722124E-4 * $tcf + 2.04052596E-6 * $tcf * $tcf - 2.32820948E-9 * $tcf * $tcf * $tcf));
}

$query = "SELECT * FROM log_ispindel WHERE code='".$code."' ORDER BY datetime;";
$result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect));
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {

    $SG = HydroCorrection($row['sg'], $row['temperature'], 20.0);
    $logs[] = array(
	'date' => substr($row['datetime'],0,16),
	'temperature' => $row['temperature'],
	'plato' => $row['plato'],
	'sg' => $SG,
	'battery' => $row['battery']
    );
}
header("Content-type: application/json");
echo json_encode($logs);

mercurial