-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpower.html
670 lines (639 loc) · 32.4 KB
/
power.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
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
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>PIC32MZW1 cloud device control</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="stylesheets/styleSheetStart.css">
<link rel="stylesheet" href="resources/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="stylesheets/lightBulb.css">
<script src="resources/jquery/jquery.min.js"></script>
<script src="resources/propper/popper.min.js"></script>
<script src="resources/bootstrap/js/bootstrap.min.js"></script>
<script src="resources/cognito-dist/amazon-cognito-auth.min.js"></script>
<script src="resources/aws-sdk.min.js"> </script>
<script src="resources/bundle.js"></script>
<script type="text/javascript">
var thingShadows;
var connstate = false
function thingConnect() {
var clientID = 'webapp:' + new Date().getTime(); //needs to be unique
//thingName = "MZW1-01-QWERTY"
thingShadows = AwsIot.thingShadow({
clientId: clientID,
host: 'a1imh8rr7nx5v9-ats.iot.us-east-1.amazonaws.com', //can be queried using 'aws iot describe-endpoint'
protocol: 'wss',
accessKeyId: AWS.config.credentials.accessKeyId,
secretKey: AWS.config.credentials.secretAccessKey,
sessionToken: AWS.config.credentials.sessionToken
});
thingShadows.on('connect', function () {
console.log("connected")
for (i = 0; i < thingList.length; i++) {
console.log(thingList[i])
registerShadow(thingList[i])
}
$("#queryResultDiv").html("");
connstate = true;
});
}
var registeredThingList = []
function getThingShadow(thingName) {
thingShadows.get(thingName);
}
function unregisterShadow(thingName) {
index = $.inArray(thingName, registeredThingList)
if (-1 != index) {
thingShadows.unregister(thingName);
registeredThingList.splice(index, 1)
}
else {
console.error("unregistering non-registered thing")
}
}
function updateShadow(thingName, state) {
var rgbLedLampState = { "state": { "desired": { "LED": state } } };
clientTokenUpdate = thingShadows.update(thingName, rgbLedLampState);
if (null === clientTokenUpdate) {
console.error("shadow update failed for " + thingName)
return false
}
return true
}
function registerShadow(thingName) {
if (-1 == $.inArray(thingName, registeredThingList)) {
thingShadows.register(thingName, {}, function () {
registeredThingList.push(thingName)
console.log(registeredThingList)
thingShadows.get(thingName);
});
thingShadows.on('status', function (name, stat, clientToken, stateObject) {
refreshStatus(name, stateObject);
console.log(`received (${clientToken}) ` + stat + ' on ' + name + ': ' + JSON.stringify(stateObject))
})
thingShadows.on('foreignStateChange', function (name, operation, stateObject) {
refreshStatus(name, stateObject);
console.log(operation + " on " + name + JSON.stringify(stateObject));
})
thingShadows.on('close', function () {
console.log('close');
$("#queryResultDiv").html("<font color=\"#f79da1\">connection closed.</font>");
//thingShadows.unregister(thingName);
});
thingShadows.on('error', function (error) {
console.error('error', error);
});
thingShadows.on('reconnect', function () {
console.log('reconnect');
$("#queryResultDiv").html("<font color=\"#f79da1\">Reconnecting...</font>");
});
thingShadows.on('offline', function () {
console.error('offline');
$("#queryResultDiv").html("<font color=\"#f79da1\">Offline...</font>");
});
/*thingShadows.on('message', function (topic, payload) {
console.log('message', topic, payload.toString());
});*/
/*ignoreDeltas is true in register by default. So no deltas.
thingShadows.on('delta', function (thingName, stateObject) {
console.log('delta on: ' + thingName + JSON.stringify(stateObject));
});*/
thingShadows.on('timeout', function (thingName, clientToken) {
console.error("Timedout on " + thingName)
//thingShadows.get(thingName)
//handleTimeout(thingName, clientToken);
});
}
}
//MQTT connect after login
function connect() {
var clientID = 'webapp:' + new Date().getTime(); //needs to be unique
device = AwsIot.device({
clientId: clientID,
host: 'a1imh8rr7nx5v9-ats.iot.us-east-1.amazonaws.com', //can be queried using 'aws iot describe-endpoint'
protocol: 'wss',
accessKeyId: AWS.config.credentials.accessKeyId,
secretKey: AWS.config.credentials.secretAccessKey,
sessionToken: AWS.config.credentials.sessionToken
});
device.on('connect', function () {
console.info("connected")
publishMessage(device, 'MZW1-01-QWERTY/testTopic', 'demo success!')
});
function publishMessage(device, topic, msg) {
device.publish(topic, msg, { qos: 1 }, function (err) {
if (err) {
alert("failed to publish iot message!");
console.error(err);
} else {
console.info("published to demoTopic");
//showMessage("Message Published", "Topic: " + topic, "Message: " + msg);
}
});
}
}
//handle UI for sign in
var userVariable = {}
function showSignedIn(session) {
//$("#resultDiv").html("You have signed in")
idToken = session.getIdToken().getJwtToken();
if (idToken) {
userVariable.idToken = JSON.parse(JSON.stringify(idToken))
var payload = idToken.split('.')[1];
var tokenobj = JSON.parse(atob(payload));
userVariable.email = JSON.parse(JSON.stringify(tokenobj.email))
userVariable.principal = AWS.config.credentials.identityId;
userVariable.emailVerified = tokenobj.email_verified
}
else {
console.error("no idToken received for user")
auth.signOut();
showSignedOut();
}
//console.log(userVariable)
$("#emailDiv").html(userVariable.email)
$("#signInButton").html("Sign Out")
$("#deviceDetails").prop("hidden", false)
refreshDevice()
}
//handle UI for sign out
function showSignedOut() {
var userVariable = {}
$("#emailDiv").html("")
}
// Initialize a cognito auth object.
function initCognitoSDK() {
AWS.config.region = 'us-east-1'
var authData = {
ClientId: "4nhjqtd3a3kdcp72i49klg6o0f", // Your client id here
AppWebDomain: "auth.pic32mzw1.xyz",
//AppWebDomain: "pic32mzw1.auth.us-east-1.amazoncognito.com",
TokenScopesArray: ["email", "openid"], // e.g.['phone', 'email', 'profile','openid', 'aws.cognito.signin.user.admin'],
RedirectUriSignIn: "https://pic32mzw1.xyz/power.html",
RedirectUriSignOut: "https://pic32mzw1.xyz/power.html",
//RedirectUriSignIn: "http://localhost:8000",
//RedirectUriSignOut: "http://localhost:8000",
UserPoolId: "us-east-1_d2G5VS3h4", // Your user pool id here
};
var login = {};
var auth = new AmazonCognitoIdentity.CognitoAuth(authData);
auth.userhandler = {
onSuccess: function (result) {
//alert("Sign in success");
//console.info("Sign in success")
console.info("IDToken: " + result.getIdToken().getJwtToken())
$("#signInButton").html("<font color=\"red\">Signing in ...</font>")
history.pushState({}, "", "/power.html"); //clear token displayed in URL for aesthetics
var loginKey = 'cognito-idp.' + AWS.config.region + '.amazonaws.com/' + authData['UserPoolId'];
login[loginKey] = result.getIdToken().getJwtToken();
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'us-east-1:f12eed4c-559f-49a9-8564-f30acb19076d',
Logins: login
});
AWS.config.credentials.refresh((error) => {
$("#signInButton").html("Sign Out")
if (error) {
console.error(error);
auth.signOut();
showSignedOut();
} else {
//var principal = AWS.config.credentials.identityId;
//console.log("IdentityId: " + principal);
//attachPrincipalPolicy("demo-policy", principal);
showSignedIn(result)
//connect();
//thingConnect();
}
});
},
onFailure: function (err) {
console.error("Error! in initCognitoSDK");
}
};
return auth;
}
// Perform user operations.
function userButton(auth) {
var state = document.getElementById('signInButton').innerHTML;
if (state === "Sign Out") {
document.getElementById("signInButton").innerHTML = "Sign In";
auth.signOut();
showSignedOut();
} else {
auth.getSession();
}
}
var auth;
let lastCall = 0;
function regButtonClick() {
err = false
$('.cube-switch .switch').click(function () {
const now = (new Date).getTime();
if (now - lastCall < 1000) { //throttle clicks
console.error("throttled")
$("#queryResultDiv").html(`<div class="alert alert-warning alert-dismissible">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
Throttled!!
</div>`)
$("#queryResultDiv").show();
$("#queryResultDiv").delay(now - lastCall).fadeOut(400);
return;
}
thingName = this.id.replace('SW_', '');
if (true == connstate && $("#onSpan_" + thingName).hasClass('online')) {
if ($("#C" + this.id).hasClass('active')) {
deviceOn = false
}
else {
deviceOn = true
}
retval = updateShadow(thingName, deviceOn)
if (!retval) {
$("#queryResultDiv").html(`<div class="alert alert-danger alert-dismissible">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
Failed performing action
</div>`)
$("#queryResultDiv").show();
$("#queryResultDiv").delay(1000).fadeOut(400);
console.error("Failed performing action")
}
else {
$("#queryResultDiv").html(`<div class="alert alert-success alert-dismissible">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
Request submitted
</div>`)
$("#queryResultDiv").delay(800).fadeOut(400);
$("#queryResultDiv").show();
}
}
else {
console.log("device not online")
$("#queryResultDiv").html(`<div class="alert alert-warning alert-dismissible">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
Device offline
</div>`)
$("#queryResultDiv").delay(800).fadeOut(400);
$("#queryResultDiv").show();
}
lastCall = now;
});
}
function onLoad() {
$("#regSerial").val("")
$("#regFriendlyName").val("")
$(document).popover({
selector: '[data-toggle=popover]',
trigger: 'focus',
animation: true
});
//refresh page after a minute of inactivity
var time = new Date().getTime();
$(document.body).bind("mousemove keypress", function (e) {
time = new Date().getTime();
});
function refresh() {
if (new Date().getTime() - time >= 300000)
window.location.reload(true);
else
setTimeout(refresh, 10000);
}
setTimeout(refresh, 10000);
auth = initCognitoSDK();
document.getElementById("signInButton").addEventListener("click", function () {
userButton(auth);
});
var curUrl = window.location.href;
auth.parseCognitoWebResponse(curUrl);
}
function registerDevice() {
var registrationData = {}
if (false === $("#registrationForm")[0].checkValidity()) {
$("#regResultDiv").html(`<div class="alert alert-warning alert-dismissible">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
Enter a valid serial number and Name
</div>`)
return;
}
registrationData.deviceSerial = $("#regSerial").val().trim();
registrationData.deviceFriendlyName = $("#regFriendlyName").val().trim()
registrationData.principal = userVariable.principal;
//registrationData.sessionID = userVariable.idToken;
//console.info("POST data: " + JSON.stringify(registrationData))
$("#regResultDiv").html("<font color=\"green\">Requesting...</font>");
$("#registerButton").prop("disabled", true);
$.ajax({
type: 'POST',
url: 'https://api.pic32mzw1.xyz/V1/registerdevice',
contentType: "application/json",
dataType: 'json',
data: JSON.stringify(registrationData),
headers: { "Auth-Token": userVariable.idToken },
success: function (data) {
//console.info("post successful. Data: " + JSON.stringify(data))
if (typeof data.errorMessage !== 'undefined') {
$("#regResultDiv").html(`<div class="alert alert-danger alert-dismissible">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<strong>Registration failed. Contact admin </strong>
</div>`)
$("#regSerial").val("")
$("#regFriendlyName").val("")
}
if (typeof data.body !== 'undefined') {
if (true === data.body.Error) {
$("#regResultDiv").html(`<div class="alert alert-danger alert-dismissible">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
${data.body.ErrorMessage}
</div>`)
$("#regSerial").val("")
$("#regFriendlyName").val("")
}
else {
$("#regResultDiv").html(`<div class="alert alert-success alert-dismissible">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<strong>Success!!</strong> Registered to ${userVariable.email}
</div>`)
$("#regResultDiv").show()
$("#regResultDiv").delay(3000).fadeOut(400);
$("#regSerial").val("")
$("#regFriendlyName").val("")
}
}
},
complete: function () {
$("#registerButton").prop("disabled", false);
refreshDevice();
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
console.error("Registration Failed")
$("#regResultDiv").html("Registration request failed. Please retry -- <font color=\"red\"><b>" + textStatus + "</b></font>");
auth.signOut()
return;
}
});
}
function powerQuery(thingName) {
var registrationData = {}
registrationData.deviceSerial = thingName;
registrationData.principal = userVariable.principal;
$(`#PQB_${thingName}`).prop("disabled", true)
$("#powerQueryDiv").html("")
$.ajax({
type: 'POST',
url: 'https://fgpbr9edn4.execute-api.us-east-1.amazonaws.com/V1',
contentType: "application/json",
dataType: 'json',
data: JSON.stringify(registrationData),
headers: { "Auth-Token": userVariable.idToken },
success: function (data) {
console.log(data)
if (undefined!=data.reported.power){
data.reported.power.current = parseInt(data.reported.power.current)*10
$("#powerQueryDiv").html(`<H5><u>${thingName}</u></H5>
<table class="table">
<TR><TD>Power</TD><td class="text-center"><strong><font color="green">${data.reported.power.power} W</font></strong></td></TR>
<tr><TD>Voltage</TD><td class="text-center"><strong><font color="green">${data.reported.power.voltage} V</font></strong></td></tr>
<tr><TD>Current</TD><td class="text-center"><strong><font color="green">${data.reported.power.current} mA</font></strong></td></tr>
</table>`)
// $("#powerQueryDiv").html("<pre>"+JSON.stringify(data.reported.power,undefined,2)+"</pre>")
}
else{
$("#powerQueryDiv").html("Device does not report power")
}
},
complete: function () {
$(`#PQB_${thingName}`).prop("disabled", false)
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
console.error("Registration Failed")
$("#queryResultDiv").html("Registration request failed. Please retry -- <font color=\"red\"><b>" + textStatus + "</b></font>");
//auth.signOut()
return;
}
});
}
function removeDevice(thingName) {
unregisterShadow(thingName)
var registrationData = {}
registrationData.deviceSerial = thingName;
registrationData.principal = userVariable.principal;
//registrationData.sessionID = userVariable.idToken;
//console.info("POST data: " + JSON.stringify(registrationData))
$(`#RC_${thingName}`).prop("disabled", true)
$("#queryResultDiv").html("<font color=\"#f79da1\">Requesting...</font>");
$.ajax({
type: 'POST',
url: 'https://api.pic32mzw1.xyz/V1/unregisterdevice',
contentType: "application/json",
dataType: 'json',
data: JSON.stringify(registrationData),
headers: { "Auth-Token": userVariable.idToken },
success: function (data) {
//console.info("post successful. Data: " + JSON.stringify(data))
if (typeof data.errorMessage !== 'undefined') {
$("#queryResultDiv").html(`<div class="alert alert-danger alert-dismissible">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<strong>un-registration failed. Contact admin </strong>
</div>`)
refreshDevice();
}
if (typeof data.body !== 'undefined') {
if (true === data.body.Error) {
$("#queryResultDiv").html(`<div class="alert alert-danger alert-dismissible">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
${data.body.ErrorMessage}
</div>`)
refreshDevice();
}
else {
$("#queryResultDiv").html(`<div class="alert alert-success alert-dismissible">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<strong>Success!!</strong> Device Unregistered ${userVariable.email}
</div>`)
$("#regSerial").val("")
$("#regFriendlyName").val("")
refreshDevice();
}
}
},
complete: function () {
$(`#RC_${thingName}`).prop("disabled", false)
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
console.error("Registration Failed")
$("#queryResultDiv").html("Registration request failed. Please retry -- <font color=\"red\"><b>" + textStatus + "</b></font>");
//auth.signOut()
return;
}
});
}
function refreshStatus(name, stateObject) {
//console.log(stateObject)
if (typeof stateObject.state.reported !== 'undefined') {
//online Indicator
if (stateObject.state.reported.online) {
$(`#Online_${name}`).html(`<span id="onSpan_${name}" class="text-center mt-2 unselectable online" tabindex="-1" data-toggle="popover" data-trigger="focus" data-placement="auto"
title="Online"> <font color="#00ff27">⬤</font></span>`)
}
else {
$(`#Online_${name}`).html(`<span id="onSpan_${name}" class="text-center mt-2 unselectable offline" tabindex="-1" data-toggle="popover" data-trigger="focus" data-placement="auto"
title="Offline"><font color="#ffc83d;">⚠</font></span>`)
}
//light status indicator
if (typeof stateObject.state.reported.LED !== 'undefined') {
if (stateObject.state.reported.LED) {
//light up the on screen device and turn switch ON
$("#CSW_" + name).addClass('active');
$("#LSW_" + name + "2").css({ 'opacity': '1' });
}
else {
//switch off the on screen device and turn switch off
$("#CSW_" + name).removeClass('active');
$("#LSW_" + name + "2").css({ 'opacity': '0' });
}
}
}
}
function refreshThingTable() {
$('#deviceTable tbody').empty()
for (i = 0; i < thingList.length; i++) {
if (true == connstate) {
unregisterShadow(thingList[i])
}
$('#deviceTable tbody').append(`<tr class="child" id=TR_${thingList[i]}>
<td style="width: 30%">
<div href="" class="cube-switch ml-2" id=CSW_${thingList[i]}>
<span class="switch" id=SW_${thingList[i]}>
<span class="switch-state off unselectable"> <font color=#FF6060>Off</font></span>
<span class="switch-state on unselectable"><font color=#A1FFA1>On</font></span>
</span>
</div>
<span class="text-light text-center mt-2 unselectable offline" tabindex="-1" data-toggle="popover" data-trigger="focus" data-placement="auto"
title="Serial" data-content="${thingList[i]}" >${thingObject[i].attributes.friendlyName}</span>
<div id="Online_${thingList[i]}"><font color="yellow" size="2em">⇩ fetching status</div>
</td>
<td style="width: 30%">
<div id="LSW_${thingList[i]}" class="light-bulb off ui-draggable">
<div id="LSW_${thingList[i]}2" class="light-bulb2" style="opacity: 0; "></div>
<button type="button" class="close" id="RC_${thingList[i]}" onclick=removeDevice("${thingList[i]}")>
<span class="text-white" aria-hidden="true">× </span>
</button>
<button type="button" id="PQB_${thingList[i]}" class="btn btn-primary btn-sm" onclick=powerQuery("${thingList[i]}")>QueryPowerNumbers</button>
</div>
</td>
</tr>`)
if (true == connstate) {
registerShadow(thingList[i])
}
}
regButtonClick()
}
var thingList = []
var thingObject = []
function refreshDevice() {
var queryData = {}
//queryData.sessionID = userVariable.idToken;
$("#queryResultDiv").html("<font color=\"#f79da1\">Refreshing...</font>");
thingList = []
thingObject = []
refreshThingTable()
$.ajax({
type: 'POST',
url: 'https://api.pic32mzw1.xyz/V1/getuserdevices ',
contentType: "application/json",
dataType: 'json',
data: JSON.stringify(queryData),
headers: { "Auth-Token": userVariable.idToken },
success: function (data) {
//console.info("post successful. Data: " + JSON.stringify(data))
if (typeof data.errorMessage !== 'undefined') {
$("#queryResultDiv").html(`<div class="alert alert-danger alert-dismissible">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<strong>Refresh failed. Contact admin if problem persists </strong>
</div>`)
}
if (typeof data.body !== 'undefined') {
if (200 != data.statusCode) {
$("#queryResultDiv").html(`<div class="alert alert-warning alert-dismissible">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
No devices found</div>`)
}
else if (true === data.body.Error) {
$("#queryResultDiv").html(`<div class="alert alert-danger alert-dismissible">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
${data.body.ErrorMessage}
</div>`)
}
else if (typeof data.body.things !== 'undefined') {
thingList = []
thingObject = []
thingObject = JSON.parse(JSON.stringify(data.body.things))
for (i = 0; i < data.body.things.length; i++) {
thingList.push(data.body.things[i].thingName)
}
$("#queryResultDiv").html("");
thingConnect()
refreshThingTable();
}
}
},
complete: function (data) {
if (!connstate && thingList.length) { //policy will be setup if at least a device is registered
thingConnect()
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
console.error("Refresh Failed Failed")
$("#queryResultDiv").html("Device refresh failed. Please retry -- <font color=\"red\"><b>" + textStatus + "</b></font>");
//auth.signOut()
return;
}
});
}
</script>
</head>
<body onload="onLoad()">
<div class="container">
<div class="row">
<div class="col mt-5 mb-5">
<a href="/"> <img src="/resources/img/mchpLogo.png" alt="Logo" class="img-responsive" align=left></a>
<h1 class="text-md-center mt-5" style="font-size: 5.0vmin;">
Power Control Demo Page
</h1>
</div>
</div>
<div class="row">
<div class="col-sm-8"></div>
<div class="col-sm-4 userEmail" id="emailDiv"></div>
</div>
<div class="row" id="deviceDetails" hidden="true">
<div class="col-sm-8" style="background-color: rgb(70, 72, 75);">
<p class="text-center mt-3 font-weight-bold text-light">Control your device </p>
<div>
<table class="table table-hover" id="deviceTable">
<tbody>
</tbody>
</table>
</div>
<div class="text-right mt-3 mb-3">
<button type="button" class="btn btn-warning top-left-text" onclick="refreshDevice()">Refresh</button>
</div>
<div id="queryResultDiv" class="bottom-left-text"></div>
</div>
<div class="col-sm-4" style="background-color:lavenderblush">
<div id="powerQueryDiv"></div>
</div>
</div>
<div class="row" id="startButtons">
<div class="col"></div>
<div class="button">
<a class="nav-tabs" id="signInButton" href="javascript:void(0)" title="Sign in">SignIn / SignUp</a>
<div id="resultDiv"></div>
</div>
<div class="col"></div>
</div>
</div>
<div class="footer" id="pageFooter">
<p>contact [email protected] to report issues</p>
</div>
</body>
</html>