11 if (! $connect) { |
11 if (! $connect) { |
12 die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); |
12 die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); |
13 } |
13 } |
14 mysqli_set_charset($connect, "utf8" ); |
14 mysqli_set_charset($connect, "utf8" ); |
15 |
15 |
|
16 function HydroCorrection($mg, $tr, $tc) |
|
17 { |
|
18 $trf = $tr * 1.8 + 32; |
|
19 $tcf = $tc * 1.8 + 32; |
|
20 |
|
21 return $mg * ((1.00130346 - 1.34722124E-4 * $trf + 2.04052596E-6 * $trf * $trf - 2.32820948E-9 * $trf * $trf * $trf) / |
|
22 (1.00130346 - 1.34722124E-4 * $tcf + 2.04052596E-6 * $tcf * $tcf - 2.32820948E-9 * $tcf * $tcf * $tcf)); |
|
23 } |
|
24 |
16 $query = "SELECT * FROM log_ispindel WHERE code='".$code."' ORDER BY datetime;"; |
25 $query = "SELECT * FROM log_ispindel WHERE code='".$code."' ORDER BY datetime;"; |
17 $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect)); |
26 $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect)); |
18 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { |
27 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { |
19 |
28 |
|
29 $SG = HydroCorrection($row['sg'], $row['temperature'], 20.0); |
20 $logs[] = array( |
30 $logs[] = array( |
21 'date' => substr($row['datetime'],0,16), |
31 'date' => substr($row['datetime'],0,16), |
22 'temperature' => $row['temperature'], |
32 'temperature' => $row['temperature'], |
23 'plato' => $row['plato'], |
33 'plato' => $row['plato'], |
24 'sg' => $row['sg'], |
34 'sg' => $SG, |
25 'battery' => $row['battery'] |
35 'battery' => $row['battery'] |
26 ); |
36 ); |
27 } |
37 } |
28 header("Content-type: application/json"); |
38 header("Content-type: application/json"); |
29 echo json_encode($logs); |
39 echo json_encode($logs); |