-
Notifications
You must be signed in to change notification settings - Fork 1
/
gate_view.php
207 lines (178 loc) · 6.05 KB
/
gate_view.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="Josh Campbell">
<link rel="shortcut icon" href="/bootstrap/assets/ico/favicon.png">
<title>IoT Gate Operator Addon</title>
<!-- Bootstrap core CSS -->
<link href="/bootstrap/css/bootstrap.css" rel="stylesheet">
<link href="/bootstrap/slider/css/slider.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="/bootstrap/css/main.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="/bootstrap/assets/js/html5shiv.js"></script>
<script src="/bootstrap/assets/js/respond.min.js"></script>
<![endif]-->
<style>
.button {
position: relative;
border: none;
color: #FFFFFF;
text-align: center;
-webkit-transition-duration: 0.4s; /* Safari */
transition-duration: 0.4s;
text-decoration: none;
overflow: hidden;
cursor: pointer;
}
.button:after {
content: "";
background: #90EE90;
display: block;
position: absolute;
padding-top: 300%;
padding-left: 350%;
margin-left: -40px!important;
margin-top: -120%;
opacity: 0;
transition: all 0.8s
}
.button:active:after {
padding: 0;
margin: 0;
opacity: 1;
transition: 0s
}
</style>
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<!--<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">-->
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">IoT Gate Operator Addon</a>
</div>
<div class="collapse navbar-collapse">
<!--
<ul class="nav navbar-nav">
<li class="active"><a href="http://ajillion.com/projects">Home</a></li>
<li class="active"><a href="http://ajillion.com/projects">Admin</a></li>
</ul>-->
</div>
</div>
</div>
<div class="container">
<div class="text-center" style="padding-top:5px; padding-left:15px; padding-right:15px; ">
<button type="button" class="button btn btn-lg btn-success btn-block bigger-button" id="open_gate">Open Gate</button><br>
<button type="button" class="button btn btn-lg btn-primary btn-block" id="latch30m_gate">Latch Open for 30 min</button><br>
<button type="button" class="button btn btn-lg btn-primary btn-block" id="latch8h_gate">Latch Open for 8 hours</button><br>
<button type="button" class="button btn btn-lg btn-warning btn-block" id="close_gate">Close Now</button><br>
<div class="jumbotron alert alert-info" role="alert">
<strong>The gate is:</strong> <span id="status"><?=$data['gatestate']?></span> <img class="m-0 p-0" id="status-img" src="/images/dual-ring-loader.gif" alt="..." height="32" width="32"><br>
Last opened <span id="last_opened"><?=$data['last_opened']?></span><br>
Controller Status: <span id="device_status" style="color:green"><?=$data['device_status']?></span>
</div>
</div>
</div><!-- /.container -->
<script src="/bootstrap/slider/js/modernizr.js" type="text/javascript"></script>
<script src="/bootstrap/assets/js/jquery.js" type="text/javascript"></script>
<script src="/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<script>
$(document).ready(function(){
$("#status-img").hide();
resetStatus();
})
function sendJSON(JSONout){
var url = 'https://agent.electricimp.com/-xWQ-bU_8bJ-';
$.post(url, JSONout);
}
$("#open_gate").click(function() {
var JSONout = '{"c":"btn","val":{"cmd":"open"}}';
sendJSON(JSONout);
//$("#status").text("Opening");
//$("#status-img").show();
resetStatus();
});
$("#latch30m_gate").click(function() {
var JSONout = '{"c":"btn","val":{"cmd":"latch30m"}}';
sendJSON(JSONout);
//$("#status").text("Opening");
//$("#status-img").show();
resetStatus();
});
$("#latch8h_gate").click(function() {
var JSONout = '{"c":"btn","val":{"cmd":"latch8h"}}';
sendJSON(JSONout);
//$("#status").text("Opening");
//$("#status-img").show();
resetStatus();
});
$("#close_gate").click(function() {
var JSONout = '{"c":"btn","val":{"cmd":"close"}}';
sendJSON(JSONout);
//$("#status").text("Closing");
//$("#status-img").show();
resetStatus();
});
function resetStatus() {
// Target url
var target = 'http://projects.ajillion.com/get_gate_state';
// Request
var data = {
agent : 'app'
};
// Send ajax post request
$.ajax({
url: target,
dataType: 'json',
type: 'POST',
data: data,
success: function(data, textStatus, XMLHttpRequest)
{
switch(data.gatestate) {
case 0:
$("#status").text('Closed');
$("#status-img").hide();
break;
case 1:
$("#status").text('Opening');
$("#status-img").show();
break;
case 2:
$("#status").text('Open');
$("#status-img").hide();
break;
case 3:
$("#status").text('Closing');
$("#status-img").show();
break;
default:
$("#status").text('Error');
$("#status-img").hide();
}
$("#last_opened").text(data.last_opened);
var device_status = (data.device_state.devicestate ? "Online" : "Offline");
if (data.device_state.devicestate == 0) device_status = device_status + data.device_offline_timestamp;
var device_status_color = (data.device_state.devicestate ? "green" : "red");
$("#device_status").text(device_status);
$('#device_status').attr('style','color:' + device_status_color);
},
error: function(XMLHttpRequest, textStatus, errorThrown)
{
// Error message
$("#status").text('Server Error');
}
});
setTimeout(resetStatus, 3000);
}
</script>
</body>
</html>