OSU ENGR 103 Project
Thermometer Reading
0) {
// Open file to display data
$myfile = fopen("data/data.txt", "r") or die("Unable to open file!");
$data = json_decode(file_get_contents("./data/data.txt"), true);
// Get last reading & what time it was at
$currentTemp = htmlspecialchars($data["current"]) . "ºF";
$secAgo = $data["lastTemp"];
// Give last temp if < 5 min old
if(time() - $secAgo < 60 * 5) {
// Print file contents
echo $currentTemp;
} else {
echo "--";
}
// Close file
fclose($myfile);
} else {
echo "--";
}
?>
Current temperature
0) {
// Open file to display data
$myfile = fopen("data/data.txt", "r") or die("Unable to open file!");
$data = json_decode(file_get_contents("./data/data.txt"), true);
// Get last reading & what time it was at
$minimum = htmlspecialchars($data["minimum"]) . "ºF";
// Print file contents
echo $minimum;
// Close file
fclose($myfile);
} else {
echo "--";
}
?>
Minimum
0) {
// Open file to display data
$myfile = fopen("data/data.txt", "r") or die("Unable to open file!");
$data = json_decode(file_get_contents("./data/data.txt"), true);
// Get last reading & what time it was at
$average = htmlspecialchars($data["fullAverage"]) . "ºF";
// Print file contents
echo $average;
// Close file
fclose($myfile);
} else {
echo "--";
}
?>
Average
0) {
// Open file to display data
$myfile = fopen("data/data.txt", "r") or die("Unable to open file!");
$data = json_decode(file_get_contents("./data/data.txt"), true);
// Get last reading & what time it was at
$maximum = htmlspecialchars($data["maximum"]) . "ºF";
// Print file contents
echo $maximum;
// Close file
fclose($myfile);
} else {
echo "--";
}
?>
Maximum