-
Notifications
You must be signed in to change notification settings - Fork 1
/
api.php
173 lines (108 loc) · 2.64 KB
/
api.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
include("./config.php");
include("./functions.php");
$size = '13';
$text = '000000';
$background = 'FFFFFF';
if(isset($_GET['size'])) { $size = $_GET['size']; }
if(isset($_GET['text'])) { $text = $_GET['text']; }
if(isset($_GET['background'])) { $background = $_GET['background']; }
?>
<html>
<head>
<title>API</title>
<style>
body {
font: <?php echo $size; ?>px 'Lucida Grande', Tahoma, Verdana, sans-serif;
color: #<?php echo $text; ?>;
background: #<?php echo $background; ?>;
}
</style>
</head>
<?php
///***** Check for API key *****///
$sql = "SELECT * FROM config WHERE id !='0' LIMIT 1";
$query = mysql_query($sql);
$data = mysql_fetch_assoc($query);
if($config['api'] == '0') {
exit;
}
$key = $_GET['key'];
if($key != $data['token']) {
echo 'invalid key.';
return;
}
$action = addslashes($_GET['action']);
//http://192.168.1.77/api.php?key=Gdw34^%FHYDe&action=read_temp&sensor=28-0000040d5895
if(isset($action)) {
if($action == "read_temp") {
$sensor = addslashes($_GET['sensor']);
$temp = GetTemp($sensor);
echo "".$temp." °C";
return;
}
if($action == "read_relay") {
$relay = addslashes($_GET['relay']);
if(ReadPin($relay) == '0') {
echo 'On';
} else {
echo 'Off';
}
//echo ReadPin($relay);
return;
}
if($action == "read_all_sensors") {
echo '<table width="20%">';
$sql = "SELECT * FROM sensors WHERE id!='0'";
$query = mysql_query($sql);
while($all = mysql_fetch_assoc($query)) {
echo '<tr>';
//echo ' <td width="33%"> '.$all['address'].' </td> ';
echo ' <td width="80%"> '.$all['name'].' </td> ';
echo ' <td width="20%"> '.GetTemp($all['address']).' </td> ';
echo '</tr>';
}
echo '</table>';
return;
}
if($action == "read_all_relays") {
echo '<table width="20%">';
$sql = "SELECT * FROM relays WHERE id!='0'";
$query = mysql_query($sql);
while($all = mysql_fetch_assoc($query)) {
echo '<tr>';
//echo ' <td width="33%"> '.$all['pin'].' </td> ';
echo ' <td width="80%"> '.$all['name'].' </td> ';
echo ' <td width="20%"> '.to_state_menu($all['address']).' </td> ';
echo '</tr>';
}
echo '</table>';
return;
}
if($action == "get_pool_temp") {
$sql = "SELECT * FROM config WHERE id='1' LIMIT 1";
$query = mysql_query($sql);
$data = mysql_fetch_assoc($query);
echo $data['set_temp'];
return;
}
if($action == "set_pool_temp") {
if(isset($_GET['temp'])) {
$temp = $_GET['temp'];
mysql_query("UPDATE config SET set_temp='$temp' WHERE id='1' LIMIT 1");
echo 'Temperature Set';
}
return;
}
if($action == "write_relay") {
$relay = addslashes($_GET['relay']);
$state = addslashes($_GET['state']);
WritePin($relay,$state);
echo 'Done';
return;
}
} ////end of if(isset
?>
</font>
</body>
</html>