-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
151 lines (127 loc) · 3.31 KB
/
functions.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
142
143
144
145
146
147
148
149
150
151
<?php
// functions.php
// Bulk of code and functions used throughout the system
// If you want to use a current temperatre from alternative source, edit the getTemp() function below.
include("config.php");
// Enable debugging
error_reporting(E_ALL);
ini_set('display_errors', true);
function getTemp() {
global $bbcWeatherID;
$url = "http://open.live.bbc.co.uk/weather/feeds/en/" . $bbcWeatherID . "/observations.rss";
$context = stream_context_create(array('http' => array('header' => 'Accept: application/xml')));
$xml = file_get_contents($url, false, $context);
$xml = simplexml_load_string($xml);
//echo "<pre>";
//print_r($xml);
//echo "</pre>";
$k = $xml->channel->item->title;
preg_match('/, (\d+)/', $k, $matches);
return $matches[1];
}
function getNextChange() {
$dowMap = array('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun');
if (isBoostActive())
return "Boost end " . getBoostRemaining() . " min";
// Start from current point to end of week
$minskip = date("i");
$hourskip = date("G");
$dayskip = date("N")-1;
for ($day = 0; $day < 7; $day++)
for ($hour = 0; $hour <= 23; $hour++)
for ($min = 0; $min <= 60; $min=$min+15)
if ($day >= $dayskip && $hour >= $hourskip && $min >= $minskip){
$minskip=0;
$hourskip=0;
$dayskip=0;
$file = "schedule/" . $day . "-" . $hour . "-" . $min;
//echo $file . "\n";
if($min==0) $min="00";
if (isHeatingActive()){
if (!file_exists($file))
return "Off at $hour:$min";
}
else {
if (file_exists($file))
return "On at $hour:$min";
}
}
// Start from beginning of week to current point
$minskip = date("i");
$hourskip = date("G");
$dayskip = date("N")-1;
for ($day = 0; $day < 7; $day++)
for ($hour = 0; $hour <= 23; $hour++)
for ($min = 0; $min <= 60; $min=$min+15)
if ($day <= $dayskip && $hour <= $hourskip && $min <= $minskip) {
$minskip=0;
$hourskip=0;
$dayskip=0;
$file = "schedule/" . $day . "-" . $hour . "-" . $min;
if($min==0) $min="00";
if (isHeatingActive()) {
if (!file_exists($file))
return "Off at $hour:$min (" . $dowMap[$day] . ")";
}
else {
if (file_exists($file))
return "On at $hour:$min (" . $dowMap[$day] . ")";
}
}
}
function isHeatingActive() {
global $gpioFile, $gpioOn;
$gpioStatus = file_get_contents($gpioFile);
if($gpioStatus==$gpioOn)
return true;
else
return false;
}
function getHeatingStatus() {
if (isHeatingActive())
return "On";
else
return "Off";
}
function getHeatingColor() {
if (isHeatingActive())
return "label-warning";
else
return "label-default";
}
function isBoostActive() {
if (file_exists("schedule/boost"))
return true;
else
return false;
}
function getBoostStatus() {
if (isBoostActive())
return "Active";
else
return "Inactive";
}
function getBoostColor() {
if (isBoostActive())
return "label-warning";
else
return "label-default";
}
function getBoostRemaining() {
if (file_exists("schedule/boost")) {
$startTime = file_get_contents("schedule/boost");
$now = date("U");
$runtime = $now - $startTime;
global $boostTime;
$boostTime = $boostTime*60;
$result = ($boostTime - $runtime)/60;
return round($result);
}
else
return 0;
}
function getTempCold() {
$temp = file_get_contents("schedule/tempCold");
return $temp;
}
?>