-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
301 lines (253 loc) · 14.2 KB
/
index.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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
<!DOCTYPE html>
<html lang="en">
<head>
<style>
body {
font-family: Tahoma, Geneva, sans-serif;
}
div {
display: inline;
}
</style>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="A web interface for MQTT over Websockets">
<meta name="author" content="Fabian Affolter">
<title>AWS IoT Raspberry Sensor Demo</title>
<!-- jQuery -->
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<!-- Bootstrap core CSS -->
<link href="https://cdn.bootcss.com/toastr.js/latest/css/toastr.min.css" rel="stylesheet">
<script src="https://cdn.bootcss.com/toastr.js/latest/toastr.min.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdn.bootcss.com/highlight.js/9.12.0/highlight.min.js"></script>
<script src="https://cdn.bootcss.com/bootstrap-switch/3.3.4/js/bootstrap-switch.js"></script>
<link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link href="https://unpkg.com/bootstrap-switch/dist/css/bootstrap3/bootstrap-switch.css" rel="stylesheet">
<script src="js/main.js"></script>
<script src="js/aws-sdk.min.js"></script>
<script src="js/iot.js"></script>
<script src="js/moment.js"></script>
<script type="text/javascript" src="js/cryptojslib/rollups/sha256.js"></script>
<script type="text/javascript" src="js/cryptojslib/rollups/hmac-sha256.js"></script>
<script type="text/javascript" src="js/paho-mqtt-js/mqttws31.js"></script>
<script>
var raspberryPi;
$(document).ready(function() {
$(".modal").show();
raspberryPi = new IoTThing();
raspberryPi.buildConnection();
raspberryPi.client.on('connected', function(){
console.log('connected');
console.log(raspberryPi.thingName)
raspberryPi.client.subscribe(raspberryPi.thingName +'/sensor/data');
});
raspberryPi.client.on('subscribeFailed', function(e){
console.log('subscribeFailed ' + e);
});
raspberryPi.client.on('subscribeSucess', function(){
console.log('subscribeSucess');
// raspberryPi.getData();
//$(".modal").hide();
});
raspberryPi.client.on('publishFailed', function(e){
console.log('publishFailed');
});
raspberryPi.client.on('messageArrived', function(msg){
console.log('messageArrived '+ msg);
var raspberryState = JSON.parse(msg.payloadString).state.reported;
if(raspberryState.mois!=undefined){
updateStats(raspberryState);
}
});
$('#robotIsOn').click(function() {
if($('#robotIsOn').prop('checked')){
$('#robotIsOn').prop('checked',false);
raspberryPi.sendData("on");
}
else{
$('#robotIsOn').prop('checked',true);
raspberryPi.sendData("off");
}
});
$('#subthres').click(function() {
var setthreshould = $('#moisthres').val();
if(setthreshould!=null&&setthreshould>0 && setthreshould<100){
raspberryPi.sendData(setthreshould);
$('#moisthres').val('');
//toastr["warning"]('Changing to '+ setthreshould +' temp...')
}else{
//toastr["warning"]('非法输入!')
}
});
$('#switchoff').click(function() {
raspberryPi.sendData(99999);
//toastr["warning"]('Applying to power off...')
});
$('#switchon').click(function() {
raspberryPi.sendData(0);
//toastr["warning"]('Applying to power on...')
});
$('.bootstrap-switch-off').click(function(){
console.log('click close')
})
})
</script>
<script type="text/javascript">
$('#status').html('Connected to AWS IoT');
$('#topic').html('AWS IoT Demo');
var entry = new Array();
var livingTemp = new Array();
var tempstatus = "OFF"
function updateStats(message) {
var topic = 'topic>>>>';
console.log(message);
//console.log("Topic: " + topic + ", Message payload: " + payload);
//$('#message').html(topic + ', ' + payload);
//var message = topic.split('/');
// var area = message[1];
//var state = message[2];
//var timestamp = Math.round((new Date()).getTime() / 1000);
$('#value1').html('(亮度: ' + message.light + ')');
$('#label1').text(message.light);
if (message.light >200) {
$('#label1').removeClass('label-danger').addClass('label-success');
} else {
$('#label1').removeClass('label-success').addClass('label-danger');
}
$('#value2').html('(空气湿度: ' + message.mois + ')');
$('#label2').text(message.mois);
if (message.mois>30&&message.mois<400) {
$('#label2').removeClass('label-danger').addClass('label-success');
} else {
$('#label2').removeClass('label-success').addClass('label-danger');
}
if(message.threshould>0 & message.threshould < 100){
$('#livingTempSensor').html('(阈值: ' + message.threshould + ')');
$('#livingTempLabel').text(message.threshould);
}
else{
$('#livingTempSensor').html('(阈值: 手动)');
$('#livingTempLabel').text('手动控制模式已启动');
}
$('#livingTempLabel').removeClass('').addClass('label-default');
var status = message.status;
$('#status').html('(二极管状态: ' + status + ')');
$('#label3').text(status);
if(tempstatus!=status){
tempstatus = status;
if(status=="ON") toastr["warning"]('二极管已经被打开.')
else toastr["success"]('The switch is closed')
}
if(status=="OFF") {
$('#label3').removeClass('label-danger').addClass('label-success');
$('#watering').hide(2000);
} else {
$('#label3').removeClass('label-success').addClass('label-danger');
$('#watering').show(1500);
}
var payload =message.temp
if(payload!=undefined){
$('#basementTempSensor').html('(温度: ' + payload + ')');
if (payload >= 25) {
$('#basementTempLabel').text(payload + '°C - too hot');
$('#basementTempLabel').removeClass('label-warning label-success label-info label-primary').addClass('label-danger');
} else if (payload >= 21) {
$('#basementTempLabel').text(payload + '°C - hot');
$('#basementTempLabel').removeClass('label-danger label-success label-info label-primary').addClass('label-warning');
} else if (payload >= 18) {
$('#basementTempLabel').text(payload + '°C - normal');
$('#basementTempLabel').removeClass('label-danger label-warning label-info label-primary').addClass('label-success');
} else if (payload >= 15) {
$('#basementTempLabel').text(payload + '°C - low');
$('#basementTempLabel').removeClass('label-danger label-warning label-success label-primary').addClass('label-info');
} else{
$('#basementTempLabel').text(payload + '°C - too low');
$('#basementTempLabel').removeClass('label-danger label-warning label-success label-info').addClass('label-primary');
}
}
}
$(document).ready(function() {
// var host = window.document.location.host.replace(/:.*/, '');
// var ws = new WebSocket('ws://' + host + ':80');
// ws.onmessage = function (event) {
// var resdata = JSON.stringify(event.data)
// var resdata = JSON.parse(resdata)
// console.log(event.data)
// console.log(typeof(event.data))
// if(typeof(event.data)=='string'){
// updateStats(JSON.parse(event.data));
// }
// };
});
</script>
</head>
<body>
<div id="wrap">
<div>
<div class="page-header"><h2><b> AWS IoT Raspberry Pi Demo</b></h2></div>
<div id="watering" style="display: none !important;" >
<br>
<div class="alert alert-warning" role="alert">二极管已经被打开.</div>
<br>
</div>
<div class="panel-body">
<table class="table table-striped">
<tr>
<td width="40%" style="vertical-align:middle;"><h3>Temperature</h3><small id="basementTempSensor">(no value recieved)</small></td>
<td style="vertical-align:middle;"><span class="basementTempSparkline"></span></td>
<td width="30%" style="vertical-align:middle;"><h4> <span id="basementTempLabel" class="label">Offline</span></h4></td>
</tr>
<tr>
<td width="40%" style="vertical-align:middle;"><h3>Light</h3><small id="value1">(no value recieved)</small></td>
<td style="vertical-align:middle;"></td>
<td width="30%" style="vertical-align:middle;"><h4> <span id="label1" class="label">Offline</span></h4></td>
</tr>
<tr>
<td width="40%" style="vertical-align:middle;"><h3>Moisture</h3><small id="value2">(no value recieved)</small></td>
<td style="vertical-align:middle;"></td>
<td width="30%" style="vertical-align:middle;"><h4> <span id="label2" class="label">Offline</span></h4></td>
</tr>
<tr>
<td width="40%" style="vertical-align:middle;"><h3>Threshould</h3><small id="livingTempSensor">(no value recieved)</small></td>
<td style="vertical-align:middle;"><div id="livingTempChart" style="height:80px; width:180px;"></div></td>
<td width="30%" style="vertical-align:middle;"><h4> <span id="livingTempLabel" class="label">Offline</span></h4></td>
</tr>
<tr>
<td width="40%" style="vertical-align:middle;"><h3>Switch</h3><small id="status">(no value recieved)</small></td>
<td style="vertical-align:middle;"></td>
<td width="30%" style="vertical-align:middle;"><h4> <span id="label3" class="label">Offline</span></h4></td>
</tr>
</table>
<div>
<form class="form-inline" onsubmit="return false">
<div class="form-group">
<label class="sr-only" for="exampleInputAmount">Please input your desire threshould value:</label>
<div class="input-group">
<div class="input-group-addon">自动调节模式:(threshould)</div>
<input type="text" class="form-control" id="moisthres" placeholder="Input Value">
<div class="input-group-addon">(°C 温度)</div>
</div>
</div>
<button type="submit" id ="subthres" class="btn btn-primary">Submit</button>
</form>
<!-- Indicates a successful or positive action -->
</div>
<p></p>
<!-- Indicates a successful or positive action -->
<button type="button" id = "switchoff" class="btn btn-success">OFF</button>
<!-- Indicates a dangerous or potentially negative action -->
<button type="button" id = "switchon" class="btn btn-danger">ON</button>
</div>
<p></p>
<div class="panel-body">
<div class="row">
<!--<div class="col-md-6"><b>Latest MQTT message: </b> <small id="message">no message recieved</small></div>
<div class="col-md-6"><b>Status: </b> <small id='status'></small></div> -->
</div>
</div>
<div class="footer">
<small><p class="text-center">© <a href="mailto:[email protected]?subject=IoTDeviceFAQ">2017, Amazon Web Services, Inc.</a>All rights reserved.</p></small>
</div>
</body>
</html>