-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwifi.html
More file actions
356 lines (342 loc) · 15.9 KB
/
Copy pathwifi.html
File metadata and controls
356 lines (342 loc) · 15.9 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
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0, user-scalable=no'>
<title>Wi-Fi</title>
</head>
<style>
.bi-wifi-1 {
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-wifi-1" viewBox="0 0 16 16"><path d="M11.046 10.454c.226-.226.185-.605-.1-.75A6.5 6.5 0 0 0 8 9c-1.06 0-2.062.254-2.946.704-.285.145-.326.524-.1.75l.015.015c.16.16.407.19.611.09A5.5 5.5 0 0 1 8 10c.868 0 1.69.201 2.42.56.203.1.45.07.611-.091zM9.06 12.44c.196-.196.198-.52-.04-.66A2 2 0 0 0 8 11.5a2 2 0 0 0-1.02.28c-.238.14-.236.464-.04.66l.706.706a.5.5 0 0 0 .707 0l.708-.707z"/></svg>');
background-repeat: no-repeat;
background-size: contain;
display:inline-block;
height: 2rem;
width: 2rem;
border: 0px solid;
border-radius: .25rem;
vertical-align: middle;
background-color: white;
}
.bi-wifi-2 {
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-wifi-2" viewBox="0 0 16 16"><path d="M13.229 8.271c.216-.216.194-.578-.063-.745A9.46 9.46 0 0 0 8 6c-1.905 0-3.68.56-5.166 1.526a.48.48 0 0 0-.063.745.525.525 0 0 0 .652.065A8.46 8.46 0 0 1 8 7a8.46 8.46 0 0 1 4.577 1.336c.205.132.48.108.652-.065m-2.183 2.183c.226-.226.185-.605-.1-.75A6.5 6.5 0 0 0 8 9c-1.06 0-2.062.254-2.946.704-.285.145-.326.524-.1.75l.015.015c.16.16.408.19.611.09A5.5 5.5 0 0 1 8 10c.868 0 1.69.201 2.42.56.203.1.45.07.611-.091zM9.06 12.44c.196-.196.198-.52-.04-.66A2 2 0 0 0 8 11.5a2 2 0 0 0-1.02.28c-.238.14-.236.464-.04.66l.706.706a.5.5 0 0 0 .708 0l.707-.707z"/></svg>');
background-repeat: no-repeat;
background-size: contain;
display:inline-block;
height: 2rem;
width: 2rem;
border: 0px solid;
border-radius: .25rem;
vertical-align: middle;
background-color: white;
}
.bi-wifi-3 {
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-wifi" viewBox="0 0 16 16"><path d="M15.384 6.115a.485.485 0 0 0-.047-.736A12.44 12.44 0 0 0 8 3C5.259 3 2.723 3.882.663 5.379a.485.485 0 0 0-.048.736.52.52 0 0 0 .668.05A11.45 11.45 0 0 1 8 4c2.507 0 4.827.802 6.716 2.164.205.148.49.13.668-.049"/><path d="M13.229 8.271a.482.482 0 0 0-.063-.745A9.46 9.46 0 0 0 8 6c-1.905 0-3.68.56-5.166 1.526a.48.48 0 0 0-.063.745.525.525 0 0 0 .652.065A8.46 8.46 0 0 1 8 7a8.46 8.46 0 0 1 4.576 1.336c.206.132.48.108.653-.065m-2.183 2.183c.226-.226.185-.605-.1-.75A6.5 6.5 0 0 0 8 9c-1.06 0-2.062.254-2.946.704-.285.145-.326.524-.1.75l.015.015c.16.16.407.19.611.09A5.5 5.5 0 0 1 8 10c.868 0 1.69.201 2.42.56.203.1.45.07.61-.091zM9.06 12.44c.196-.196.198-.52-.04-.66A2 2 0 0 0 8 11.5a2 2 0 0 0-1.02.28c-.238.14-.236.464-.04.66l.706.706a.5.5 0 0 0 .707 0l.707-.707z"/></svg>');
background-repeat: no-repeat;
background-size: contain;
display:inline-block;
height: 2rem;
width: 2rem;
border: 0px solid;
border-radius: .25rem;
vertical-align: middle;
background-color: white;
}
.bi-lock {
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-lock" viewBox="0 0 16 16"><path d="M8 1a2 2 0 0 1 2 2v4H6V3a2 2 0 0 1 2-2zm3 6V3a3 3 0 0 0-6 0v4a2 2 0 0 0-2 2v5a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2zM5 8h6a1 1 0 0 1 1 1v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V9a1 1 0 0 1 1-1z"/></svg>');
background-repeat: no-repeat;
background-size: contain;
display:inline-block;
height: 2rem;
width: 2rem;
border: 0px solid;
border-radius: .25rem;
vertical-align: middle;
background-color: white;
}
body {
text-align: center;
font: 1.2rem "Open Sans", Helvetica, Arial, sans-serif;
}
.portal {
display:inline-block;
min-width:400px;
max-width:400px;
}
h1 { text-align: center; font: 1.4rem 'Open Sans', Helvetica, Arial, sans-serif; }
h2 { text-align: center; font: 1.2rem 'Open Sans', Helvetica, Arial, sans-serif; }
input {
text-align: left;
font: 1.2rem 'Open Sans', Helvetica, Arial, sans-serif;
padding: 0.5rem;
width: 90%;
margin: 0.5rem auto;
}
button {
border: 0;
border-radius: 0.3rem;
background: #0dcaf0;
padding: 0px 1rem;
font: 1.2rem 'Open Sans', Helvetica, Arial, sans-serif;
line-height: 2.4rem;
transition-duration: 0.4s;
cursor: pointer;
}
button:hover {
color: white;
background: #0e70a4;
}
table {
width: 100%;
border-collapse: collapse;
font: 1.2rem "Open Sans", Helvetica, Arial, sans-serif;
}
td {
text-align: left;
vertical-align: middle;
border: 0px solid;
}
.ssid-block {
padding: 10px 0px 10px 10px;
text-align: left;
font: 1.2rem "Tahoma", Helvetica, Arial, sans-serif;
}
.info-block{
padding: 0px 10px;
width:90px;
text-align:right;
}
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place for top */
z-index: 1; /* Sit on top */
left: 0; /* Use full window */
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}
.modal-header {
padding: 2px 10px;
background-color: #5cb85c;
}
/* Modal Content/Box */
.modal-content {
min-width:400px;
max-width:400px;
position: relative;
top: 5%;
background-color: #fefefe;
margin: 0% auto; /* 0% from the top and centered */
padding: 0px;
border: 1px solid #888;
animation: fadein 0.5s;
}
@keyframes fadein {
from { top: -5%; opacity: 0; }
to { top: 5%; opacity: 1; }
}
/* The Close Button */
.close {
color: black;
float: right;
font-size: 28px;
font-weight: bold;
cursor: pointer;
}
.close:hover,
.close:focus {
color: white;
}
</style>
<body>
<div class='portal'>
<table><tbody><tr><td style="text-align: right;width: 50%;">
<svg id="wi-fi-tm" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 960 960">
<defs>
<style>
.cls-1 { fill-rule: evenodd; }
.cls-1, .cls-2, .cls-3, .cls-4 { stroke-width: 0px; }
.cls-3 { fill: #fff; }
.cls-4 { fill: #231f20; }
</style>
</defs>
<g id="layer1">
<g id="g3250">
<path id="path112" class="cls-1" d="M441.51,202.59c-88.73,0-167.77,41.73-218.57,106.61h-47.57c-74.64,0-135.38,60.7-135.38,135.34v81.61c0,74.64,60.74,135.38,135.38,135.38h56.29c50.89,58.79,126.05,95.99,209.85,95.99s158.96-37.2,209.85-95.99h54.2c74.67,0,135.41-60.74,135.41-135.38v-81.61c0-74.64-60.75-135.34-135.41-135.34h-45.47c-50.8-64.88-129.84-106.61-218.57-106.61Z"/>
<path id="path118" class="cls-3" d="M458.96,526.13v-81.58c0-60.27,49.05-109.31,109.31-109.31h137.28c60.27,0,109.34,49.05,109.34,109.31v81.58c0,60.27-49.08,109.31-109.34,109.31h-302.26c33.72-24.64,55.67-64.46,55.67-109.31Z"/>
<path id="path120" class="cls-3" d="M280.53,568.47h-45.06l-8.07-38.26c-5.75-27.15-11.05-60.15-12.06-72.96-1.04,12.81-6.3,45.81-12.06,72.96l-8.1,38.26h-44.54l-42.02-176.2h50.32l4.77,29.47c4.05,24.93,8.85,55.64,10.58,76.52,2.02-20.65,7.55-51.13,13.1-76.32l6.02-29.67h44.82l6.04,29.67c5.52,25.19,11.05,55.67,13.1,76.32,1.74-20.88,6.54-51.59,10.56-76.52l4.77-29.47h49.86l-42.05,176.2Z"/>
<path id="path122" class="cls-3" d="M366.74,426.77c-14.86,0-25.94-8.59-25.94-22.38,0-12.87,11.08-21.92,25.94-21.92s26.4,9.05,26.4,21.92c0,13.79-10.82,22.38-26.4,22.38ZM344.07,568.47v-128h45.32v128h-45.32Z"/>
<path id="path124" class="cls-2" d="M569.06,433.79v39.39h93.76v41.33h-93.76v53.96h-48.58v-176.2h152.32v41.53h-103.73Z"/>
<path id="path126" class="cls-2" d="M723.66,426.77c-14.84,0-25.94-8.59-25.94-22.38,0-12.87,11.1-21.92,25.94-21.92,15.59,0,26.4,9.05,26.4,21.92,0,13.79-10.82,22.38-26.4,22.38ZM701.01,568.47v-128h45.29v128h-45.29Z"/>
<path id="path136" class="cls-4" d="M859.87,359.18v-31h-11.02v-6.33h29.56v6.33h-11.05v31h-7.49Z"/>
<path id="path138" class="cls-4" d="M883.17,359.18v-37.33h11.34l6.68,25.48,6.59-25.48h11.34v37.33h-6.94l-.06-29.38-7.32,29.38h-7.29l-7.35-29.38-.06,29.38h-6.94Z"/>
</g>
</g>
</svg>
</td><td>Provisioning</td></tr></tbody>
</table>
<h2>Select AP or enter <button onclick='javascript:openConnectModal("");'>manually</button></h2>
<table>
<tbody id='ssid-list'>
<tr><td class='ssid-block'>Loading...</td>
<td class='info-block'>
<span class='bi-lock'></span>
<span class='bi-wifi-3'></span>
</td>
</tr>
</tbody>
</table>
<button onclick='javascript:openErasenvsModal();'>Erase NVS</button>
<button onclick='javascript:openOtaUpdateModal();'>OTA Update</button>
<!-- Connect modal content -->
<div id='connect-modal' class='modal'>
<div class='modal-content'>
<div class='modal-header'>
<span class='close' onclick='javascript:closeConnectModal();'>×</span>
<h1>Wi-Fi Credentials</h1>
</div>
<div style='margin: 15px;'>
<h2>Please enter wireless network name (SSID) and Wi-Fi password:</h2>
<label for='wifi-ssid'>SSID</label>
<input type='text' id='wifi-ssid' placeholder='Enter Wi-Fi SSID'>
<label for='wifi-password'>SSID password</label>
<input type='text' id='wifi-password' placeholder='Enter Wi-Fi password'>
<hr>
<button onclick='javascript:SaveAndRestart();'>Save and restart</button>
<button style='background: #adb5bd;' onclick='javascript:closeConnectModal();'>Cancel</button>
</div>
</div>
</div>
<!-- Erase NVS modal content -->
<div id='erasenvs-modal' class='modal'>
<div class='modal-content'>
<div class='modal-header'>
<span class='close' onclick='javascript:closeErasenvsModal();'>×</span>
<h1>Erase NVS</h1>
</div>
<div style='margin: 15px;'>
<h2>You are about to erase ESP32 NVS partition!</h2>
<hr>
<button style='background: #df0c24;' onclick='javascript:erasenvs();'>Confirm</button>
<button style='background: #adb5bd;' onclick='javascript:closeErasenvsModal();'>Cancel</button>
</div>
</div>
</div>
<!-- OTA Update modal content -->
<div id='otaupdate-modal' class='modal'>
<div class='modal-content'>
<div class='modal-header'>
<span class='close' onclick='javascript:closeOtaUpdateModal();'>×</span>
<h1>OTA Update</h1>
</div>
<div style='margin: 15px;'>
<h2>Upload new firmware over the air.</h2>
<input id='firmware' type="file" style="width:90%;" />
<h2 id='ota-status'>Ready.</h2>
<hr>
<button onclick='javascript:otaUpdate();'>Upload</button>
<button style='background: #adb5bd;' onclick='javascript:closeOtaUpdateModal();'>Cancel</button>
</div>
</div>
</div>
</div> <!-- class portal -->
<script>
function openConnectModal(name) {
document.getElementById('wifi-ssid').value = name;
document.getElementById('wifi-password').value = '';
document.getElementById('connect-modal').style.display = 'block';
};
function closeConnectModal() {
document.getElementById('connect-modal').style.display = 'none';
};
function openErasenvsModal() {
document.getElementById('erasenvs-modal').style.display = 'block';
}
function closeErasenvsModal() {
document.getElementById('erasenvs-modal').style.display = 'none';
}
function openOtaUpdateModal() {
document.getElementById('otaupdate-modal').style.display = 'block';
}
function closeOtaUpdateModal() {
document.getElementById('otaupdate-modal').style.display = 'none';
}
document.onreadystatechange = function () {
if (document.readyState === 'interactive') updateSSIDList();
};
function updateSSIDList() {
fetch('/scanap')
.then(response => {
if (!response.ok) {
throw new Error('Network response.');
}
return response.json();
})
.then(data => {
if (!Array.isArray(data)) {
console.error('Error! Array expected.');
return;
}
let htmlaplist = '';
data.forEach((ssid, index) => {
htmlaplist += '<tr><td class=\'ssid-block\'><a href=\'javascript:openConnectModal(\"' + ssid.ssid + '\")\'>' + ssid.ssid + '</a></td>\n';
htmlaplist += '<td class=\'info-block\'>';
if ( ssid.auth > 0 ) { htmlaplist += '<span class=\'bi-lock\'></span>\n'; }
if ( ssid.rssi < -75 ) { htmlaplist += '<span class=\'bi-wifi-1\'></span>\n'; }
else if ( ssid.rssi < -60 ) { htmlaplist += '<span class=\'bi-wifi-2\'></span>\n'; }
else { htmlaplist += '<span class=\'bi-wifi-3\'></span>\n'; }
htmlaplist += '</td>\n</tr>\n';
});
document.getElementById("ssid-list").innerHTML = htmlaplist;
})
.catch(error => {
console.error('Fetch error:', error);
});
}
function SaveAndRestart() {
let params = new URLSearchParams();
params.append( 'ssid', document.getElementById('wifi-ssid').value );
params.append( 'password', document.getElementById('wifi-password').value );
fetch( '/savewifi?' + params.toString() )
.then(response => {
if (response.ok) {
location.reload();
} else {
console.error('Failed to reset Wi-Fi settings');
}
})
.catch(error => console.error('Fetch error:', error));
closeConnectModal();
}
function erasenvs() {
fetch( '/nvserase' );
closeErasenvsModal();
}
function otaUpdate() {
document.getElementById("firmware").disabled = true;
var fileInput = document.getElementById("firmware").files;
if (fileInput.length == 0) {
alert("No file selected!");
} else {
var fwfile = fileInput[0];
var xhttp = new XMLHttpRequest();
xhttp.onload = function () {
if (this.status == 200) {
document.getElementById("ota-status").textContent = this.responseText;
} else {
document.getElementById("ota-status").textContent = this.status + ' Error!\n' + this.responseText;
}
};
xhttp.upload.onprogress = function (event) {
var percent = event.loaded / event.total ;
document.getElementById("ota-status").textContent = 'Progress ' + Math.round( 100 * percent ) + '%';
};
xhttp.open('POST', '/updateota');
xhttp.send(fwfile);
}
}
</script>
</body>
</html>