-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
141 lines (111 loc) · 5.06 KB
/
index.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Dashboard</title>
<?php include "./header.php" ?>
<style>
.dot {
height: 100px;
width: 100px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
}
</style>
</head>
<body>
<div style="padding-left:16px">
<h2>Nothing Yet!</h2>
<p></p>
<p>Some things have changed since I set up my TLS certificate. I moved to cloudflare as my domain provider, I use <a href="https://doc.traefik.io/traefik/" target="_blank">traefik<a> for my reverse proxy. It lets me dynamically (havent figure that out yet) set routes to specific services, it also handles creation and renewal of TLS certificates automatically. Some more behind the scenes stuff. 2/12/24<br>
</p>
</div>
<?php
$servername = getenv('SQLHOSTNAME');
// REPLACE with your Database name
$dbname = "sensorData";
// REPLACE with Database user
$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 `Temperature(C)`, `Pressure(bar)`, `Humidity(%)`, `PM1`, `PM2.5`, `PM10`, `Timestamp` FROM Exterior ORDER BY `Timestamp` DESC LIMIT 1";
if ($result = $conn->query($sql)) {
while ($row = $result->fetch_assoc()) {
$row_Temperature = $row["Temperature(C)"];
$row_Pressure = $row["Pressure(bar)"];
$row_Humidity = $row["Humidity(%)"];
$row_PM01 = $row["PM1"];
$row_PM25 = $row["PM2.5"];
$row_PM10 = $row["PM10"];
$row_reading_time = $row["Timestamp"];
$row_Pressure = ($row_Pressure / 1000.0);
}
echo '<div style="padding-left:16px">
<br><br><h4>Current Air Quality</h4>
<p>PM2.5 AQI: ' . AQIPM25($row_PM25) .'</p>
<p>PM10 AQI: ' . AQIPM10($row_PM10) .'</p>
</div>';
}
function AQIPM25($PM25){
$PM25 = floor($PM25);
if($PM25 <= 12.0){//GOOD
return round((((50-0)/(12.0-0))*($PM25 - 0.0)+0));
} elseif($PM25 > 12.0 && $PM25 <= 35.4){//MODERATE
return round((((100-51)/(35.4-12.1))*($PM25 - 12.1)+51));
} elseif($PM25 > 35.4 && $PM25 <= 55.4){//UNHEALTHY FOR SENSITIVE
return round((((150-101)/(55.4-35.5))*($PM25 - 35.5)+101));
} elseif($PM25 > 55.4 && $PM25 <= 150.4){//UNHEALTHY
return round((((200-151)/(150.4-55.5))*($PM25 - 55.5)+151));
}elseif($PM25 > 150.5 && $PM25 <= 250.4){//VERY UNHEALTHY
return round((((300-201)/(250.4-150.5))*($PM25 - 150.5)+201));
}elseif($PM25 > 250.5 && $PM25 <= 500.4){//HAZARDOUS
return round((((500-301)/(500.4-250.5))*($PM25 - 250.5)+301));
}elseif($PM25 > 500.4 && $PM25 < 99999.9){//TOO HIGH
return round((((999-501)/(99999.9-500.5))*($PM25 - 500.5)+500.5));
}
}
function AQIPM10($PM10){
$PM10 = floor($PM10);
if($PM10 <= 54.0){//GOOD
return round((((50-0)/(54-0))*($PM10 - 0.0)+0));
} elseif($PM10 > 54 && $PM10 <= 154){//MODERATE
return round((((100-51)/(154-55))*($PM10 - 55)+51));
} elseif($PM10 > 155 && $PM10 <= 254){//UNHEALTHY FOR SENSITIVE
return round((((150-101)/(254-155))*($PM10 - 155)+101));
} elseif($PM10 > 255 && $PM10 <= 354){//UNHEALTHY
return round((((200-151)/(354-255))*($PM10 - 255)+151));
}elseif($PM10 > 355 && $PM10 <= 424){//VERY UNHEALTHY
return round((((300-201)/(424-355))*($PM10 - 355)+201));
}elseif($PM10 > 425 && $PM10 <= 604){//HAZARDOUS
return round((((500-301)/(604-425))*($PM10 - 425)+301));
}elseif($PM10 > 605 && $PM10 < 99999.9){//TOO HIGH
return round((((999-501)/(99999.9-605))*($PM10 - 605)+500.5));
}
}
function AQIO3($PM10){
$PM10 = floor($PM10);
if($PM10 <= 54.0){//GOOD
return round((((50-0)/(54-0))*($PM10 - 0.0)+0));
} elseif($PM10 > 54 && $PM10 <= 154){//MODERATE
return round((((100-51)/(154-55))*($PM10 - 55)+51));
} elseif($PM10 > 155 && $PM10 <= 254){//UNHEALTHY FOR SENSITIVE
return round((((150-101)/(254-155))*($PM10 - 155)+101));
} elseif($PM10 > 255 && $PM10 <= 354){//UNHEALTHY
return round((((200-151)/(354-255))*($PM10 - 255)+151));
}elseif($PM10 > 355 && $PM10 <= 424){//VERY UNHEALTHY
return round((((300-201)/(424-355))*($PM10 - 355)+201));
}elseif($PM10 > 425 && $PM10 <= 604){//HAZARDOUS
return round((((500-301)/(604-425))*($PM10 - 425)+301));
}elseif($PM10 > 605 && $PM10 < 99999.9){//TOO HIGH
return round((((999-501)/(99999.9-605))*($PM10 - 605)+500.5));
}
}
?>
<!--span class="dot"></span//-->
</body>
</html>