-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviewRoom.html
More file actions
492 lines (375 loc) · 11.7 KB
/
viewRoom.html
File metadata and controls
492 lines (375 loc) · 11.7 KB
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="robots" content="noindex, nofollow">
<meta name="googlebot" content="noindex, nofollow">
<!-- <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script> -->
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="/resources/demos/external/jquery-mousewheel/jquery.mousewheel.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css" href="chui.css">
<style type="text/css">
</style>
<title></title>
<script type='text/javascript'>//<![CDATA[
$(function() {
var gaugeOptions = {
chart: {
type: 'solidgauge'
},
title: null,
pane: {
center: ['50%', '85%'],
size: '140%',
startAngle: -90,
endAngle: 90,
background: {
backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || '#EEE',
innerRadius: '60%',
outerRadius: '100%',
shape: 'arc'
}
},
tooltip: {
enabled: false
},
// the value axis
yAxis: {
stops: [
[0.3, '#DF5353'], // red
[0.5, '#DDDF0D'], // yellow
[0.9, '#55BF3B'] // green
],
lineWidth: 0,
minorTickInterval: null,
tickPixelInterval: 400,
tickWidth: 0,
title: {
y: -70
},
labels: {
y: 16
}
},
plotOptions: {
solidgauge: {
dataLabels: {
y: 5,
borderWidth: 0,
useHTML: true
}
}
}
};
// The humidity gauge
$('#container-humidity').highcharts(Highcharts.merge(gaugeOptions, {
yAxis: {
min: 0,
max: 100,
title: {
text: 'Humidity'
}
},
credits: {
enabled: false
},
series: [{
name: 'Humidity',
data: [50],
dataLabels: {
format: '<div style="text-align:center"><span style="font-size:25px;color:' +
((Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black') + '">{y}</span><br/>' +
'<span style="font-size:12px;color:silver">%</span></div>'
},
tooltip: {
valueSuffix: ' %'
}
}]
}));
//the temp gauge
$('#container').highcharts({
chart: {
type: 'gauge',
plotBackgroundColor: null,
plotBackgroundImage: null,
plotBorderWidth: 0,
plotShadow: false
},
title: {
text: 'Temp'
},
pane: {
startAngle: -150,
endAngle: 150,
background: [{
backgroundColor: {
linearGradient: {
x1: 0,
y1: 0,
x2: 0,
y2: 1
},
stops: [
[0, '#FFF'],
[1, '#333']
]
},
borderWidth: 0,
outerRadius: '109%'
}, {
backgroundColor: {
linearGradient: {
x1: 0,
y1: 0,
x2: 0,
y2: 1
},
stops: [
[0, '#333'],
[1, '#FFF']
]
},
borderWidth: 1,
outerRadius: '107%'
}, {
// default background
}, {
backgroundColor: '#DDD',
borderWidth: 0,
outerRadius: '105%',
innerRadius: '103%'
}]
},
// the value axis
yAxis: {
min: 50,
max: 90,
minorTickInterval: 'auto',
minorTickWidth: 1,
minorTickLength: 10,
minorTickPosition: 'inside',
minorTickColor: '#666',
tickPixelInterval: 30,
tickWidth: 2,
tickPosition: 'inside',
tickLength: 10,
tickColor: '#666',
labels: {
step: 2,
rotation: 'auto'
},
title: {
text: 'F'
},
plotBands: [{
from: 65,
to: 72,
color: '#55BF3B' // green
}, {
from: 72,
to: 80,
color: '#DDDF0D' // yellow
}, {
from: 80,
to: 90,
color: '#DF5353' // red
}]
},
series: [{
name: 'Temp',
data: [50],
tooltip: {
valueSuffix: ' F'
}
}]
},
// Add some life
function(chart) {
var xmlhttp = new XMLHttpRequest();
var urltemp = "http://api.thingspeak.com/channels/youchannel/field/4.json";
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var myArr = JSON.parse(xmlhttp.responseText);
console.log("opened");
currentTemp = myArr["feeds"][99]["field4"];
console.log(myArr["feeds"][99]["field4"]);
var point = chart.series[0].points[0];
point.update(Math.round(currentTemp));
}
};
xmlhttp.open("GET", urltemp, true);
xmlhttp.send();
var chart2 = $('#container-humidity').highcharts(),
point,
newVal,
inc;
if (chart2) {
point2 = chart2.series[0].points[0];
// inc = Math.round((Math.random() - 0.5) * 100);
// newVal = point2.y + inc;
var xmlhttphum = new XMLHttpRequest();
var urlhum = "http://api.thingspeak.com/channels/youchannel/field/2.json";
xmlhttphum.onreadystatechange = function() {
if (xmlhttphum.readyState == 4 && xmlhttp.status == 200) {
var myArrhum = JSON.parse(xmlhttphum.responseText);
console.log("opened hum");
currentHum = myArrhum["feeds"][99]["field2"];
console.log(myArrhum["feeds"][99]["field2"]);
newVal = (Math.round(myArrhum["feeds"][99]["field2"]));
// var point = chart.series[0].points[0];
point2.update(Math.round(newVal));
}
};
xmlhttphum.open("GET", urlhum, true);
xmlhttphum.send();
}
if (!chart.renderer.forExport) {
setInterval(function() {
var xmlhttp = new XMLHttpRequest();
var urltemp = "http://api.thingspeak.com/youchannel/75529/field/4.json";
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var myArr = JSON.parse(xmlhttp.responseText);
console.log("opened");
currentTemp = myArr["feeds"][99]["field4"];
console.log(myArr["feeds"][99]["field4"]);
var point = chart.series[0].points[0];
point.update(Math.round(currentTemp));
}
};
xmlhttp.open("GET", urltemp, true);
xmlhttp.send();
var chart2 = $('#container-humidity').highcharts(),
point,
newVal,
inc;
if (chart2) {
point2 = chart2.series[0].points[0];
// inc = Math.round((Math.random() - 0.5) * 100);
// newVal = point2.y + inc;
var xmlhttphum = new XMLHttpRequest();
var urlhum = "http://api.thingspeak.com/channels/youchannel/field/2.json";
xmlhttphum.onreadystatechange = function() {
if (xmlhttphum.readyState == 4 && xmlhttp.status == 200) {
var myArrhum = JSON.parse(xmlhttphum.responseText);
console.log("opened hum");
currentHum = myArrhum["feeds"][99]["field2"];
console.log(myArrhum["feeds"][99]["field2"]);
newVal = (Math.round(myArrhum["feeds"][99]["field2"]));
// var point = chart.series[0].points[0];
point2.update(Math.round(newVal));
}
};
xmlhttphum.open("GET", urlhum, true);
xmlhttphum.send();
}
}, 60000);
}
});
});
//]]>
</script>
</head>
<body>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/highcharts-more.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/solid-gauge.js"></script>
<div id="container" style="min-width: 310px; max-width: 400px; height: 300px; margin: 0 auto"></div>
<div style="width: 600px; height: 400px; margin: 0 auto">
<center>
<button id="login">Change desired temp</button>
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.2.26.min.js"></script>
<script type="text/javascript">
var appId = '999'; // Change this for your Facebook app ID
var roleArn = 'arn:aws:iam::999:role/yourRole'; // This is your AWS IAM role
var AWSregion = 'us-west-2'; //change if you're not using Oregon region
var myBucket = 'yourbucket'; //the S3 bucket
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({appId: appId});
document.getElementById('login').onclick = function() {
FB.login(function (response) {
if (response.authResponse) { // logged in
AWS.config.region = AWSregion;
AWS.config.credentials = new AWS.WebIdentityCredentials({
RoleArn: roleArn,
ProviderId: 'graph.facebook.com',
WebIdentityToken: response.authResponse.accessToken
});
console.log(AWS.config.credentials);
console.log(response.authResponse.userID);
FBuserID = response.authResponse.userID
epochtime = Math.floor(new Date() / 1000);
var chosentemp = $("#olympics").val();
console.log(chosentemp);
var dynamodb = new AWS.DynamoDB();
params = {TableName: 'temps', Item: { /* required */
'time': { N: epochtime.toString()}, 'temp': {N: chosentemp}, 'userid': {S: FBuserID}}};
dynamodb.putItem(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
if (chosentemp > 50 && chosentemp < 90)
{
console.log ("Good temp");
var s3 = new AWS.S3();
params = {
Bucket: myBucket, /* required */
Key: 'destemp', /* required */
Body: chosentemp, //the temp
Metadata: { 'userID': FBuserID},
ACL: 'public-read'
}
;
s3.putObject(params, function(err, data) {
if (err)
{console.log(err, err.stack);
alert("Cannot update desired temp. You're likely not a valid Facebook user.");
} // an error occurred
else { console.log(data);
alert("Desired temperature updated.");
} // successful response
});
}
else
{
console.log ("Bad temp");
alert("Come on! That temperature is just crazy.");
}
console.log('You are now logged in.');
} else {
console.log('There was a problem logging you in.');
}
});
};
};
// Load the FB JS SDK asynchronously
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "http://connect.facebook.net/en_US/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<label for="olympics">Desired temp:</label>
<input id="olympics" type="number" value = "68">
<script>
$.widget("tj.olympicspicker", $.ui.spinner, {
options: {
min: 50,
max: 90,
step: 1
}
});
$("input").olympicspicker();
</script>
</center>
<div id="container-humidity" style="width: 300px; height: 200px; margin: 0 auto"></div>
<div id="container2" style="min-width: 310px; max-width: 400px; height: 300px; margin: 0 auto">
<iframe width="450" height="260" style="border: 1px solid #cccccc;" src="http://api.thingspeak.com/channels/youchannel/charts/4?width=450&height=260&results=300&dynamic=true"></iframe>
</div>
</body>
</html>