-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
452 lines (406 loc) · 11.9 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
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
<style>
html, body {margin: 0; height: 100%; overflow: hidden; overscroll-behavior: contain;}
#mainDiv {
width: 100%;
height: 100%;
display: flex;
align-items: center;
background: linear-gradient(360deg, #068, #FFF);
}
#backgroundCnvs {
position: absolute;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
transform: scale(1.2);
z-index: 1;
}
#dataDiv {
position: relative;
border: 1px solid #dfdfdf;
background: linear-gradient(360deg, #DDD, #FFF);
width: 330px;
height: 465px;
margin: 0 auto;
z-index: 2;
}
.titleText {
display: inline-block;
margin: 0 auto;
padding-top: 20px;
padding-left: 40px;
font-family: Verdana, Geneva, sans-serif;
font-size: 11px;
font-weight: bold;
color: #555;
}
.titleText2 {
padding-left:0;
font-size: 18px;
padding-top: 150px;
}
.titleText3 {
margin-top: 60px;
font-size: 14px;
padding-left: 0px;
padding-bottom: 24px;
}
#refreshBtn {
font-size: 10px;
font-weight: 700;
margin-left: 55px;
padding: 2px;
font-family: Verdana,Geneva,sans-serif;
cursor: pointer;
}
#refreshBtn:active {
background-color: #999;
color: white;
border-radius: 4px;
}
#connectionList {
height: 300px;
max-height: 300px;
background: white;
border: 1px solid #999;
width: 250px;
margin: 0 auto;
overflow-y: auto;
cursor: pointer;
}
.connectionItem {
border-bottom: 1px solid #ccc;
padding: 2px;
font-family: Verdana, Geneva, sans-serif;
font-size: 12px;
color: #666;
user-select: none;
}
.selectedConnection {
background-color: #abe5f9;
}
#pwDiv {
background: white;
max-height: 270px;
width: 250px;
margin: 0 auto;
border: 1px solid #999;
}
.loadingRing {
display: inline-block;
width: 100%;
height: 100%;
margin: 0 auto;
}
.loadingRing:after {
content: " ";
display: block;
width: 64px;
position: absolute;
height: 64px;
top: 40%;
left: 36%;
border-radius: 50%;
border: 6px solid #cef;
border-color: #cef transparent #cef transparent;
animation: loading-ring 1.2s linear infinite;
}
@keyframes loading-ring {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
#loadingDiv {
background-color: #7777776b;
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
z-index: 100;
}
.overlayDiv {
display: none;
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
border-radius: 8px;
text-align: center;
z-index: 100;
}
#connectedDiv {
background-color: white;
}
#errorDiv {
background-color: rgba(105, 105, 105, 0.65);
}
#errorModal {
width: 100%;
height: 50%;
top: 25%;
position: absolute;
background: rgb(247, 96, 96);
}
#buttonsDiv {
width: 100%;
padding-top: 10px;
margin: 0 auto;
text-align: center;
}
#saveDiv {
display: inline-block;
}
#versionDiv {
font-size: 8px;
font-family: "Lucida Console", Monaco, monospace;
position: absolute;
bottom: 0;
width: 100%;
text-align: center;
}
#showHide {
position: absolute;
right: 44px;
padding-top: 3px;
font-family: Verdana, Geneva, sans-serif;
font-size: 9px;
font-weight: bold;
background: white;
cursor: pointer;
}
input[type=button] {
background-color: #666;
border: 1px solid #CCC;
color: white;
padding: 8px 16px;
text-decoration: none;
margin: 4px 2px;
cursor: pointer;
outline: none;
border-radius: 25px;
}
input[type=button]:hover {
background-color: #777;
}
input[type=button]:active {
background-color: #AAA;
border-color: #4CAF50;
}
input[type=button]:disabled {
background-color: #CCC;
border-color: #DDD;
}
input[type=password] {
width: 85%;
background: transparent;
border: transparent;
outline: 0px;
}
input[type=text] {
width: 85%;
background: transparent;
border: transparent;
outline: 0px;
font-family: Verdana, Geneva, sans-serif;
font-size: 12px;
}
</style>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<html>
<head>
<title>PeggyConfig</title>
</head>
<body>
<div id="mainDiv">
<canvas id='backgroundCnvs'></canvas>
<div id='dataDiv'>
<div id='connectedDiv' class="overlayDiv">
<span class="titleText titleText2">WiFi connected successfully!<br>Portal shutting down.</span>
</div>
<div id='errorDiv' class="overlayDiv">
<div id="errorModal">
<span class="titleText titleText3">Invalid credentials.<br> Try again!</span>
<div>
<input id='connectBtn' value='Close' type='button' onclick="showError(false)"/>
</div>
</div>
</div>
<div id='loadingDiv'>
<div class="loadingRing"></div>
</div>
<div>
<label for="connList" class="titleText">AVAILABLE NETWORKS</label>
<span id="refreshBtn" onclick="initPage()">Refresh</span>
</div>
<div id='connectionList'></div>
<label for="loginPw" class="titleText">PASSWORD</label>
<div id="pwDiv">
<input id='loginPw' type='password'/>
<span id='showHide' onclick="showHidePw()">SHOW</span>
</div>
<div id='buttonsDiv'>
<div id='saveDiv'>
<input id='connectBtn' value='Connect' type='button' onclick="connect()"/>
</div>
</div>
<div id='versionDiv'>
<span id='versionNumber'>Powered by PeggyConfig</span>
</div>
</div>
</div>
</body>
</html>
<script>
var _availableWifi = [];
var _selectedWifi = undefined;
var _manualSSID = false;
initPage();
function initPage() {
showLoading(true);
try {
sendGET('AvailableWifi', function(response) {
if (response != "") {
_availableWifi = response.split(";");
createWifiList();
} else {
_manualSSID = true;
}
showLoading(false);
});
} catch {
console.log("NO RESPONSE FROM MCU.")
showLoading(false);
}
}
function showHidePw() {
if (document.getElementById('showHide').innerText == 'SHOW') {
document.getElementById('showHide').innerText = 'HIDE'
document.getElementById("loginPw").type ='text';
} else {
document.getElementById('showHide').innerText = 'SHOW'
document.getElementById("loginPw").type = 'password';
}
}
function showLoading(x) {
if(x) {
document.getElementById('loadingDiv').style.display = 'block';
} else {
document.getElementById('loadingDiv').style.display = 'none';
}
}
function setError(id, val) {
if(val){
document.getElementById(id).style.outline = 0;
document.getElementById(id).style.borderColor = "red";
document.getElementById("dataDiv").style.boxShadow = '0 0 12px 4px red';
} else{
document.getElementById(id).style.outline = "";
document.getElementById(id).style.borderColor = "";
document.getElementById("dataDiv").style.boxShadow = '';
}
}
function showConnected() {
document.getElementById('connectedDiv').style.display = 'block';
document.getElementById("dataDiv").style.boxShadow = '0 0 12px 4px green';
}
function showError(x) {
if(x) {
document.getElementById('errorDiv').style.display = 'block';
} else {
document.getElementById('errorDiv').style.display = 'none';
}
}
function connect() {
showLoading(true);
if (checkForm()) {
var content = {
SSID: _availableWifi[_selectedWifi],
PASSWORD: document.getElementById('loginPw').value
};
sendPOST(JSON.stringify(content), function(status){
if (status == "True") {
showError(false);
showConnected();
} else {
showError(true);
}
showLoading(false)
});
} else {
showLoading(false);
}
}
function checkForm() {
var status = true;
if (_selectedWifi == undefined) {
setError("connectionList", true);
status = false
} else {
setError("connectionList", false);
}
if (document.getElementById('loginPw').value == "") {
setError("pwDiv", true);
status = false
} else {
setError("pwDiv", false);
}
return status;
}
function sendPOST(content, callback) {
var xhr = new XMLHttpRequest();
xhr.open("POST",'/dataIn',true)
xhr.setRequestHeader('Content-Type', 'application/octet-stream');
xhr.send(content);
xhr.onload = function()
{
if(typeof callback === 'function'){
callback(xhr.statusText);
}
};
}
function sendGET(content, callback) {
var xhr = new XMLHttpRequest();
xhr.open( "GET", '/' + content);
xhr.send( null );
xhr.onload = function()
{
if(typeof callback === 'function'){
callback(xhr.responseText);
}
};
}
function createWifiList() {
var connectionList = "";
if(_availableWifi == null) {
return;
}
for (var x = 0; x<_availableWifi.length; x ++ ) {
if (_availableWifi[x] == "") {
continue;
}
var wifiName = _availableWifi[x];
if(wifiName.length > 20) {
wifiName = wifiName.substring(0, 17) + "...";
}
connectionList += "<div class='connectionItem' id='conn" + x + "' onclick='selectWifiConnection("+ x +")'>";
connectionList += "<div class='connectionName'>" + wifiName + "</div>";
connectionList += "</div>";
}
var content = document.getElementById("connectionList").innerHTML = connectionList;
}
function selectWifiConnection(x) {
if (_selectedWifi != undefined) {
var connection = document.getElementById("conn" + _selectedWifi);
connection.classList.remove("selectedConnection");
}
_selectedWifi = x;
var connection = document.getElementById("conn" + _selectedWifi);
connection.classList.add("selectedConnection");
}
</script>