-
Notifications
You must be signed in to change notification settings - Fork 0
/
flower-data.php
74 lines (64 loc) · 2.44 KB
/
flower-data.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Flower Sensor Data</title>
<?php include "./header.php" ?>
</head>
<body>
<div style="padding-left:16px">
<h2>Flower Sensor Data</h2>
<p>The sensor being used for PHT is the MS8607</p>
<p>Planned: Sorting, Pages, Entries Per Page</p>
</div>
<?php
//ini_set('display_errors', 1);
//ini_set('display_startup_errors', 1);
//error_reporting(E_ALL);
//require_once '/vars.php';
$servername = getenv('SQLHOSTNAME');
$dbname = "sensorData";
$username = getenv('SQLUSER');
// REPLACE with Database user password
$password = getenv('SQLPASS');
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT `ID`, `Sensor`, `Temperature(C)`, `Humidity(%)`, `Timestamp` FROM Flowers ORDER BY id DESC";
echo '<table cellspacing="5" cellpadding="5" style="padding-left:7px">
<tr>
<td><b>ID</b></td>
<td><b>Sensor</b></td>
<td><b>Temperature(F)</b></td>
<td><b>Humidity(%)</b></td>
<td><b>Timestamp</b></td>
</tr>';
if ($result = $conn->query($sql)) {
while ($row = $result->fetch_assoc()) {
$row_id = $row["ID"];
$row_sensor = $row["Sensor"];
$row_Temperature = $row["Temperature(C)"];
$row_Humidity = $row["Humidity(%)"];
$row_reading_time = $row["Timestamp"];
$row_Temperature = ($row_Temperature * (9.0/5.0)) + 32;
//$row_Pressure = ($row_Pressure / 1000.0);
// Uncomment to set timezone to - 1 hour (you can change 1 to any number)
//$row_reading_time = date("Y-m-d H:i:s", strtotime("$row_reading_time - 1 hours"));
// Uncomment to set timezone to + 4 hours (you can change 4 to any number)
//$row_reading_time = date("Y-m-d H:i:s", strtotime("$row_reading_time + 4 hours"));
echo '<tr>
<td>' . $row_id . '</td>
<td>' . $row_sensor . '</td>
<td>' . $row_Temperature . '</td>
<td>' . $row_Humidity . '</td>
<td>' . $row_reading_time . '</td>
</tr>';
}
$result->free();
}
$conn->close();
?>
</table>
</body>
</html>