-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetTemp.php
54 lines (47 loc) · 1.54 KB
/
setTemp.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
<?php
include_once("config.php");
/*
A beirja a faljba a beallitott homersekletet.
*/
$id = filter_input(INPUT_POST, 'id', FILTER_SANITIZE_SPECIAL_CHARS);
$temp = filter_input(INPUT_POST, 'temp', FILTER_SANITIZE_SPECIAL_CHARS);
$type = filter_input(INPUT_POST, 'type', FILTER_SANITIZE_SPECIAL_CHARS);
$message1 = "";
$header = "Content-Type: application/json";
header($header);
if ($type === "settemp") {
$sensors['tempsensors'][$id]['settemp'] = floatval($temp);
}
if ($type === "mintemp") {
$sensors['tempsensors'][$id]['mintemp'] = floatval($temp);
}
if ($type === "maxtemp") {
$sensors['tempsensors'][$id]['maxtemp'] = floatval($temp);
}
if ($type === "off") {
$sensors['tempsensors'][$id]['power'] = false;
}
if ($type === "on") {
$sensors['tempsensors'][$id]['power'] = true;
}
if ($id === "boilerpower" && $type === "On") {
exec('/usr/local/bin/gpio write 0 1');
exec($exec);
$sensors['boiler']['power'] = false;
$message1 = 'Off';
}
if ($id === "boilerpower" && $type === "Off") {
exec('/usr/local/bin/gpio write 0 0');
exec($exec);
$sensors['boiler']['power'] = true;
$message1 = 'On';
}
$message = "Change ".$type." for sensor ".$id." to ".floatval($temp);
pitemplog($message);
file_put_contents($sensorsUrl, json_encode($sensors, JSON_PRETTY_PRINT));
$success = true;
$results = array(
"success" => $success,
"message1" => $message1,
);
print json_encode($results);