-
Notifications
You must be signed in to change notification settings - Fork 1
/
sample.html
277 lines (246 loc) · 10.6 KB
/
sample.html
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<!DOCTYPE HTML>
<html>
<head>
<title>ESP-NOW DASHBOARD</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="data:,">
<link rel="stylesheet" href="views/style.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/annyang/2.6.0/annyang.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/SpeechKITT/1.0.0/speechkitt.min.js"></script>
</head>
<body>
<div class="topnav">
<h4 class="dashead">Dashboard</h4>
<span class="username">Welcome, Mr. Kenny!</span>
</div>
<div class="half-circle">
<label class="select" for="slct">
<select id="slct" required="required">
<option value="#" selected="selected">Room 1</option>
<option value="#">Room 2</option>
</select>
<svg>
<use xlink:href="#select-arrow-down"></use>
</svg>
</label>
<!-- SVG Sprites-->
<svg class="sprites">
<symbol id="select-arrow-down" viewbox="0 0 10 6">
<polyline points="1 1 5 5 9 1"></polyline>
</symbol>
</svg>
</div>
<div class="content">
<div class="cards">
<div class="card boxcard">
<h2 class="currTime">Current Time: <span id="timeMe"></span></h2>
<div class="card lights">
<h4><i class="fas fa-thermometer-half"></i>LIGHTS</h4>
<p><label class="switch">
<input id="toggleSwitches1" onchange="toggleS1()" type="checkbox">
<span class="slider round"></span>
</label>
</p>
<h4 id="12g" ><i class="fas fa-thermometer-half"></i>OFF</h4>
<p class="packet">nodeID: 12g<span id="rt1"></span></p>
</div>
<div class="card fan">
<h4><i class="fas fa-thermometer-half"></i>FAN</h4>
<p><label class="switch">
<input id="toggleSwitches2" onchange="toggleS2()" type="checkbox">
<span class="slider round"></span>
</label>
</p>
<h4 id="12u"><i class="fas fa-thermometer-half"></i>OFF</h4>
<p class="packet">nodeID: 12u<span id="rt1"></span></p>
</div>
<div class="card temperature">
<h4><i class="fas fa-thermometer-half"></i>TEMPERATURE</h4>
<p><span class="reading"><span id="t1"></span> °C</span></p>
<p class="packet">DHT-11<span id="rt1"></span></p>
</div>
<div class="card humidity">
<h4><i class="fas fa-tint"></i>HUMIDITY</h4>
<p><span class="reading"><span id="h1"></span> %</span></p>
<p class="packet">DHT-11<span id="rh1"></span></p>
</div>
<div id="myBtn" class="card alarm">
<h4><i class="fas fa-tint"></i>+ Create New Alarm</h4>
</div>
</div>
</div>
</div>
<div id="myModal" class="modal">
<div class="modal-content">
<div class="modal-header">
<span class="close">×</span>
<h2>Set Alarm</h2>
</div>
<div class="modal-body">
<p>Please fill in the Details for the Action</p>
<label class="select" for="slctnode">
<select id="slctnode" required="required">
<option value="" disabled="disabled" selected="selected">Select Node</option>
<option value="12g">Light</option>
<option value="12u">Fan</option>
</select>
<svg>
<use xlink:href="#select-arrow-down"></use>
</svg>
</label><br/><br/>
<label class="select" for="slctaction">
<select id="slctaction" required="required">
<option value="" disabled="disabled" selected="selected">Select Action</option>
<option value="ON">Switch ON</option>
<option value="OFF">Switch OFF</option>
</select>
<svg>
<use xlink:href="#select-arrow-down"></use>
</svg>
</label><br/><br/>
<input type="datetime-local" id="alarmTime" name="alarmTime"><br/><br/>
</div>
<div onclick="alarmSend()" class="modal-footer">
<h3>Send to Server</h3>
</div>
</div>
<script>
function setDate(){
var date = new Date();
document.getElementById("timeMe").innerHTML = date.toString().slice(0,24);
setTimeout(setDate,1000);
}
setDate();
function readUpdate(){
const http = new XMLHttpRequest();
const http1 = new XMLHttpRequest();
const http2 = new XMLHttpRequest();
const light='http://localhost:4000/api/controls/read?gatewayId=2111&nodeId=12g';
const fan='http://localhost:4000/api/controls/read?gatewayId=2111&nodeId=12u';
const sensor='http://localhost:4000/api/controls/read?gatewayId=2111&nodeId=sen1';
console.log(sensor);
http.open("GET", sensor);
http.send();
http.onreadystatechange = (e) => {
let response = JSON.parse(http.responseText);
console.log('value sen1:'+response.value);
document.getElementById("t1").innerHTML=response.value;
}
http1.open("GET", light);
http1.send();
http1.onreadystatechange = (e) => {
let response = JSON.parse(http1.responseText);
console.log(response.nodeID+response.action);
if(response.action=="ON" && document.getElementById("12g").textContent=="OFF")
document.getElementById("toggleSwitches1").click();
else if(response.action=="OFF" && document.getElementById("12g").textContent=="ON")
document.getElementById("toggleSwitches1").click();
}
http2.open("GET", fan);
http2.send();
http2.onreadystatechange = (e) => {
let response = JSON.parse(http2.responseText);
console.log(response.nodeID+response.action);
if(response.action=="ON" && document.getElementById("12u").textContent=="OFF")
document.getElementById("toggleSwitches2").click();
else if(response.action=="OFF" && document.getElementById("12u").textContent=="ON")
document.getElementById("toggleSwitches2").click();
}
setTimeout(readUpdate, 5000);
}
readUpdate();
function sendRequest(gateway,node,action){
const Http = new XMLHttpRequest();
const url='http://localhost:4000/api/controls/publish?gateway='+gateway+'&node='+node+'&action='+action;
console.log(url);
Http.open("GET", url);
Http.send();
Http.onreadystatechange = (e) => {
console.log(Http.responseText)
}
}
function toggleS1(){
var btn=document.getElementById("toggleSwitches1");
if(!btn.hasAttribute('checked')){
btn.setAttribute('checked','');
document.getElementById("12g").innerHTML = 'ON';
sendRequest("2111","12g","ON");
}
else{
btn.removeAttribute('checked')
document.getElementById("12g").innerHTML = 'OFF';
sendRequest("2111","12g","OFF");
}
console.log("S1:"+btn.hasAttribute('checked'));
}
function toggleS2(){
var btn=document.getElementById("toggleSwitches2");
if(!btn.hasAttribute('checked')){
btn.setAttribute('checked','');
document.getElementById("12u").innerHTML = 'ON';
sendRequest("2111","12u","ON");
}
else{
btn.removeAttribute('checked')
document.getElementById("12u").innerHTML = 'OFF';
sendRequest("2111","12u","OFF");
}
console.log("S2:"+btn.hasAttribute('checked'));
}
var modal = document.getElementById("myModal");
var btn = document.getElementById("myBtn");
var span = document.getElementsByClassName("close")[0];
btn.onclick = function() {
modal.style.display = "block";
}
span.onclick = function() {
modal.style.display = "none";
}
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
function alarmSend(){
var node = document.getElementById("slctnode").value;
var action = document.getElementById("slctaction").value;
var alarmTime = document.getElementById("alarmTime").value;
const Http = new XMLHttpRequest();
const url='http://localhost:4000/api/controls/alarm?gateway=2111&node='+node+'&action='+action+'&time='+alarmTime;
console.log(url);
Http.open("GET", url);
Http.send();
Http.onreadystatechange = (e) => {
console.log(Http.responseText)
}
}
function speechRec(){
if (annyang) {
annyang.addCommands({
'Switch on the light': function() {
if(document.getElementById("12g").textContent=="OFF")
document.getElementById("toggleSwitches1").click();
},
'Switch on the fan': function() {
if(document.getElementById("12u").textContent=="OFF")
document.getElementById("toggleSwitches2").click();
},
'Switch off the light': function() {
if(document.getElementById("12g").textContent=="ON")
document.getElementById("toggleSwitches1").click();
},
'Switch off the fan': function() {
if(document.getElementById("12u").textContent=="ON")
document.getElementById("toggleSwitches2").click();
}
});
SpeechKITT.annyang();
SpeechKITT.setStylesheet('https://cdnjs.cloudflare.com/ajax/libs/SpeechKITT/1.0.0/themes/flat.css');
SpeechKITT.setInstructionsText("Say the Command!");
SpeechKITT.vroom();
}
}
speechRec()
</script>
</body>
</html>