-
Notifications
You must be signed in to change notification settings - Fork 1
/
temp2mcf.php
87 lines (76 loc) · 2.23 KB
/
temp2mcf.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
<?php
//File to read
$file = '/sys/devices/w1_bus_master1/28-0316624a1eff/w1_slave';
$file2 = '/sys/devices/w1_bus_master1/28-03166241fcff/w1_slave';
//Read the file line by line
$lines = file($file);
$lines2 = file($file2);
//Get the temp from second line
$temp = explode('=', $lines[1]);
$temp2 = explode('=', $lines2[1]);
//Setup some nice formatting (i.e. 21,3)
$temp_c = number_format($temp[1] / 1000, 1, '.', '');
$temp_f = ($temp_c * 9.0) / 5.0 + 32.0;
$temp_c2 = number_format($temp2[1] / 1000, 1, '.', '');
$temp_f2 = ($temp_c2 * 9.0) / 5.0 + 32.0;
$doorStateArray = [
0 => "closed",
1 => "open",
];
$doorStatus = $doorStateArray[trim(shell_exec("gpio -g read 18"))];
if ($_GET['format'] === 'json') {
$jsonArray = [
'temp_c' => $temp_c,
'temp_f' => $temp_f,
'temp_c2' => $temp_c2,
'temp_f2' => $temp_f2,
'doorState' => $doorStatus,
];
echo json_encode($jsonArray);
} else {
?>
<head>
<meta http-equiv="refresh" content="1"/>
<style>
.title {
font-family: calibri sans-serif;
font-size: 25pt;
font-weight: bold
}
.temp {
font-family: arial sans-serif;
font-size: 33pt;
}
.celsius {
color: blue
}
.fahrenheit {
color: green
}
.open {
color: green;
}
.closed {
color: red;
}
</style>
</head>
<p class="title">
The current outside temperature is<br/>
<span class="temp celsius"><?= $temp_c ?> C</span><br/>
<span class="temp fahrenheit"><?= $temp_f ?> F</span><br/>
</p>
<p class="title">
The current indoor temperature is<br/>
<span class="temp celsius"><?= $temp_c2 ?> C</span><br/>
<span class="temp fahrenheit"><?= $temp_f2 ?> F</span><br/>
</p>
<p class="title">
The garage door is
<span class="<?php echo(($doorStatus == "open") ? "open" : "closed") ?>"><?= $doorStatus ?></span>
</p>
<a href="http://192.168.1.41/123.html">
<button>Back</button>
</a>
<?php
}