feat: Wi-Fi access point with a setting, password and boot button
The controller runs an AP (SSID = hostname, 192.168.5.1) next to ESP-NOW, on by default. Network settings gain an on/off switch (ap_enabled) and an optional WPA2 password (ap_password, 8-63 chars; empty is open). A button on D7 (GPIO44) held at boot forces the AP on. Wi-Fi now starts before Ethernet, and a missing W5500 no longer aborts the boot: the web server and mDNS start anyway so the AP stays usable. Network tuning found while testing over the AP: HTTP backlog 10 and 12 open sockets (the default 5 dropped the 6th SYN, a 1 s stall on every page load), larger TCP and Wi-Fi buffers, and IPv6 link-local addresses so mDNS answers AAAA queries (browsers waited about a second for them). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9989dd3062
commit
f85021d40d
11 files changed
+197
-22
No files matched your search
+27
-1
@@ -98,6 +98,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const hostInput = document.getElementById('hostname-input');
|
||||
if (hostInput && staticIpsList && data && typeof data === 'object') {
|
||||
hostInput.value = data.hostname || '';
|
||||
setApToggle(data.ap_enabled !== false);
|
||||
const apPw = document.getElementById('ap-password-input');
|
||||
if (apPw) apPw.value = data.ap_password || '';
|
||||
staticIpsList.innerHTML = '';
|
||||
(Array.isArray(data.static_ips) ? data.static_ips : []).forEach(addStaticIpRow);
|
||||
}
|
||||
@@ -106,6 +109,19 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
}
|
||||
}
|
||||
|
||||
const apToggle = document.getElementById('ap-enabled-toggle');
|
||||
function setApToggle(on) {
|
||||
if (apToggle) {
|
||||
apToggle.setAttribute('aria-pressed', on ? 'true' : 'false');
|
||||
apToggle.classList.toggle('is-on', on);
|
||||
}
|
||||
}
|
||||
if (apToggle) {
|
||||
apToggle.addEventListener('click', () => {
|
||||
setApToggle(apToggle.getAttribute('aria-pressed') !== 'true');
|
||||
});
|
||||
}
|
||||
|
||||
const staticIpsList = document.getElementById('static-ips-list');
|
||||
const STATIC_IP_FIELDS = [
|
||||
['ip', 'IP address', '192.168.1.50'],
|
||||
@@ -256,6 +272,11 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
showSettingsMessage('Hostname may only contain letters, digits and hyphens', 'error');
|
||||
return;
|
||||
}
|
||||
const apPassword = (document.getElementById('ap-password-input') || { value: '' }).value;
|
||||
if (apPassword && (apPassword.length < 8 || apPassword.length > 63)) {
|
||||
showSettingsMessage('Access point password must be 8 to 63 characters, or empty for open', 'error');
|
||||
return;
|
||||
}
|
||||
let staticIps;
|
||||
try {
|
||||
staticIps = readStaticIps();
|
||||
@@ -267,7 +288,12 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const response = await fetch('/settings/settings', {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ hostname, static_ips: staticIps }),
|
||||
body: JSON.stringify({
|
||||
hostname,
|
||||
static_ips: staticIps,
|
||||
ap_password: apPassword,
|
||||
ap_enabled: !apToggle || apToggle.getAttribute('aria-pressed') === 'true',
|
||||
}),
|
||||
});
|
||||
const result = await response.json();
|
||||
if (response.ok) {
|
||||
|
||||
@@ -1282,6 +1282,16 @@ html.simulated-bpm-mode .seq-switch-toggle-wrap {
|
||||
background-color: #e8e4ff;
|
||||
}
|
||||
|
||||
.nav-slide-toggle-switch.is-on {
|
||||
background-color: #1b5e20;
|
||||
border-color: #4caf50;
|
||||
}
|
||||
|
||||
.nav-slide-toggle-switch.is-on .nav-slide-toggle-thumb {
|
||||
left: calc(100% - 1rem - 2px);
|
||||
background-color: #e8f5e9;
|
||||
}
|
||||
|
||||
.main-menu-dropdown .nav-slide-toggle-wrap--mobile {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
|
||||
@@ -1182,6 +1182,20 @@
|
||||
<input type="text" id="hostname-input" placeholder="led-controller" pattern="[A-Za-z0-9\-]+" maxlength="63">
|
||||
<small>The controller answers at <code>hostname.local</code>.</small>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="ap-enabled-toggle">Wi-Fi access point</label>
|
||||
<div class="nav-slide-toggle-wrap">
|
||||
<button type="button" role="switch" class="nav-slide-toggle-switch" id="ap-enabled-toggle" aria-pressed="true" aria-label="Wi-Fi access point enabled">
|
||||
<span class="nav-slide-toggle-track" aria-hidden="true"><span class="nav-slide-toggle-thumb"></span></span>
|
||||
</button>
|
||||
</div>
|
||||
<small>Named after the hostname; the controller is at <code>192.168.5.1</code> on it. Holding the button on D7 while the controller boots turns it on even when this is off.</small>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="ap-password-input">Access point password</label>
|
||||
<input type="text" id="ap-password-input" placeholder="open (no password)" minlength="8" maxlength="63" autocomplete="off">
|
||||
<small>8 to 63 characters (WPA2). Leave empty for an open network.</small>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Static IPs</label>
|
||||
<small>Tried in order each time the Ethernet link comes up; the first whose gateway answers is used. If none does, or the list is empty, DHCP is used. With no DHCP server, as on a cable straight to a PC, the controller is at <code>192.168.4.1</code>; give the PC a static IP such as <code>192.168.4.2</code>.</small>
|
||||
|
||||
Reference in new issue
Block a user