-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.html
More file actions
109 lines (92 loc) · 4.67 KB
/
setup.html
File metadata and controls
109 lines (92 loc) · 4.67 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ESP8266 Setup</title>
<style>
body { font-family: -apple-system, sans-serif; text-align: center; padding: 20px; background: #f0f2f5; }
.card { background: white; max-width: 350px; margin: 20px auto; padding: 2rem; border-radius: 12px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); }
h1 { color: #333; margin-top: 0; }
input { width: 100%; padding: 12px; margin-bottom: 15px; border: 1px solid #ddd; border-radius: 8px; box-sizing: border-box; }
button { width: 100%; padding: 12px; background: #28a745; color: white; border: none; border-radius: 8px; font-size: 16px; font-weight: bold; cursor: pointer; }
button:hover { background: #218838; }
.note { margin-top: 15px; font-size: 0.9rem; color: #666; }
.wifi-list { list-style: none; padding: 0; margin: 20px 0; max-height: 200px; overflow-y: auto; text-align: left; border: 1px solid #eee; border-radius: 8px; }
.wifi-item { padding: 10px; border-bottom: 1px solid #eee; cursor: pointer; display: flex; justify-content: space-between; }
.wifi-item:last-child { border-bottom: none; }
.wifi-item:hover { background: #f8f9fa; }
.wifi-rssi { color: #888; font-size: 0.8rem; }
.refresh-btn { background: #007bff; margin-bottom: 15px; font-size: 14px; padding: 8px; }
.refresh-btn:hover { background: #0056b3; }
</style>
</head>
<body>
<div class="card">
<h1>📶 WiFi Setup</h1>
<button class="refresh-btn" id="scanBtn" onclick="scanWifi()">🔄 Scan Networks</button>
<div id="loading" style="display:none; color: #666; margin: 10px;">Scanning...</div>
<ul id="wifiList" class="wifi-list" style="display:none;"></ul>
<form id="wifiForm">
<input type="text" id="ssid" placeholder="WiFi Name (SSID)" required>
<input type="password" id="password" placeholder="WiFi Password" required>
<button type="submit">Save & Connect</button>
</form>
<p class="note" id="status"></p>
</div>
<script>
async function scanWifi() {
const listEl = document.getElementById('wifiList');
const loadEl = document.getElementById('loading');
listEl.style.display = 'none';
loadEl.style.display = 'block';
try {
const res = await fetch('/api/scan');
const networks = await res.json();
listEl.innerHTML = '';
networks.forEach(n => {
const li = document.createElement('li');
li.className = 'wifi-item';
// Add lock icon if secure
const lock = n.auth > 0 ? '🔒' : '';
li.innerHTML = `<span>${n.ssid} ${lock}</span> <span class="wifi-rssi">${n.rssi}dBm</span>`;
li.onclick = () => {
document.getElementById('ssid').value = n.ssid;
document.getElementById('password').focus();
};
listEl.appendChild(li);
});
listEl.style.display = 'block';
} catch (e) {
alert("Scan failed");
} finally {
loadEl.style.display = 'none';
}
}
document.getElementById('wifiForm').addEventListener('submit', async (e) => {
e.preventDefault();
const ssid = document.getElementById('ssid').value;
const password = document.getElementById('password').value;
const statusEl = document.getElementById('status');
statusEl.textContent = "Saving...";
try {
const res = await fetch('/api/wifi', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ ssid, password })
});
if (res.ok) {
statusEl.textContent = "Saved! Device is rebooting...";
alert("WiFi Saved! Device will reboot and try to connect.");
} else {
statusEl.textContent = "Error saving config.";
}
} catch (err) {
statusEl.textContent = "Connection error.";
}
});
// Auto scan on load
scanWifi();
</script>
</body>
</html>