2019-11-27 22:28:13 +01:00
|
|
|
<!DOCTYPE html>
|
2020-12-23 21:43:30 +01:00
|
|
|
<html lang="en">
|
2019-11-27 22:28:13 +01:00
|
|
|
<head>
|
2020-06-10 12:45:44 +02:00
|
|
|
<meta charset="utf-8">
|
2019-11-27 22:28:13 +01:00
|
|
|
<meta name="viewport" content="width=500">
|
2021-12-08 14:38:21 +01:00
|
|
|
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport"/>
|
2019-11-27 22:28:13 +01:00
|
|
|
<title>WiFi Settings</title>
|
|
|
|
<script>
|
2022-11-24 02:50:24 +01:00
|
|
|
var d = document;
|
2023-06-04 18:40:29 +02:00
|
|
|
var loc = false, locip, locproto = "http:";
|
2022-11-24 02:50:24 +01:00
|
|
|
var scanLoops = 0, preScanSSID = "";
|
|
|
|
|
|
|
|
function gId(e) { return d.getElementById(e); }
|
|
|
|
function cE(e) { return d.createElement(e); }
|
2021-12-08 22:05:51 +01:00
|
|
|
function H(){window.open("https://kno.wled.ge/features/settings/#wifi-settings");}
|
2023-06-04 18:40:29 +02:00
|
|
|
function B(){window.open(getURL("/settings"),"_self");}
|
2022-11-24 02:50:24 +01:00
|
|
|
function N() {
|
|
|
|
const button = gId("scan");
|
|
|
|
button.disabled = true;
|
2023-06-11 01:39:48 +02:00
|
|
|
button.textContent = "Scanning...";
|
2022-11-24 02:50:24 +01:00
|
|
|
|
2023-06-04 18:40:29 +02:00
|
|
|
fetch(getURL("/json/net")).then((response) => {
|
2022-11-24 02:50:24 +01:00
|
|
|
return response.json();
|
|
|
|
}).then((json) => {
|
|
|
|
// Get the list of networks only, defaulting to an empty array.
|
|
|
|
return Object.assign(
|
|
|
|
{},
|
|
|
|
{"networks": []},
|
|
|
|
json,
|
|
|
|
).networks.sort(
|
|
|
|
// Sort by signal strength, descending.
|
|
|
|
(a, b) => b.rssi - a.rssi
|
|
|
|
).reduce(
|
|
|
|
// Filter out duplicate SSIDs. Since it is sorted by signal
|
|
|
|
// strength, the strongest signal will be kept in the
|
|
|
|
// order it orginally appeared in the array.
|
|
|
|
(unique, other) => {
|
|
|
|
if(!unique.some(obj => obj.ssid === other.ssid)) {
|
|
|
|
unique.push(other);
|
|
|
|
}
|
|
|
|
return unique;
|
|
|
|
},
|
|
|
|
[],
|
|
|
|
);
|
|
|
|
}).then((networks) => {
|
|
|
|
// If there are no networks, fetch it again in a second.
|
|
|
|
// but only do this a few times.
|
|
|
|
if (networks.length === 0 && scanLoops < 10) {
|
|
|
|
scanLoops++;
|
|
|
|
setTimeout(N, 1000);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
scanLoops = 0;
|
|
|
|
|
|
|
|
let cs = gId("CS");
|
|
|
|
if (cs) {
|
|
|
|
let select = cE("select");
|
|
|
|
select.setAttribute("id", "CS");
|
|
|
|
select.setAttribute("name", "CS");
|
|
|
|
select.setAttribute("onchange", "T()");
|
|
|
|
preScanSSID = cs.value;
|
|
|
|
|
|
|
|
for (let i = 0; i < select.children.length; i++) {
|
|
|
|
select.removeChild(select.children[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let i = 0; i < networks.length; i++) {
|
|
|
|
const option = cE("option");
|
|
|
|
|
|
|
|
option.setAttribute("value", networks[i].ssid);
|
2023-06-11 01:39:48 +02:00
|
|
|
option.textContent = `${networks[i].ssid} (${networks[i].rssi} dBm)`;
|
2022-11-24 02:50:24 +01:00
|
|
|
|
|
|
|
if (networks[i].ssid === cs.value) {
|
|
|
|
option.setAttribute("selected", "selected");
|
|
|
|
}
|
|
|
|
|
|
|
|
select.appendChild(option);
|
|
|
|
}
|
|
|
|
const option = cE("option");
|
|
|
|
|
|
|
|
option.setAttribute("value", "!Cs");
|
2023-06-11 01:39:48 +02:00
|
|
|
option.textContent = `Other network...`;
|
2022-11-24 02:50:24 +01:00
|
|
|
select.appendChild(option);
|
|
|
|
|
|
|
|
cs.replaceWith(select);
|
|
|
|
}
|
|
|
|
|
|
|
|
button.disabled = false;
|
2023-06-11 01:39:48 +02:00
|
|
|
button.textContent = "Scan";
|
2022-11-24 02:50:24 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
// replace WiFi select with custom SSID input field again
|
|
|
|
function T() {
|
|
|
|
let cs = gId("CS");
|
|
|
|
if (!cs || cs.value != "!Cs") return;
|
|
|
|
let input = cE("input");
|
|
|
|
input.type = "text";
|
|
|
|
input.id = "CS";
|
|
|
|
input.name ="CS";
|
|
|
|
input.setAttribute("maxlength",32);
|
|
|
|
input.value = preScanSSID;
|
|
|
|
cs.replaceWith(input);
|
|
|
|
}
|
2022-07-17 15:58:41 +02:00
|
|
|
// https://www.educative.io/edpresso/how-to-dynamically-load-a-js-file-in-javascript
|
|
|
|
function loadJS(FILE_URL, async = true) {
|
2022-11-24 02:50:24 +01:00
|
|
|
let scE = cE("script");
|
2022-07-17 15:58:41 +02:00
|
|
|
scE.setAttribute("src", FILE_URL);
|
|
|
|
scE.setAttribute("type", "text/javascript");
|
|
|
|
scE.setAttribute("async", async);
|
|
|
|
d.body.appendChild(scE);
|
2022-11-24 02:50:24 +01:00
|
|
|
// success event
|
2022-07-17 15:58:41 +02:00
|
|
|
scE.addEventListener("load", () => {
|
|
|
|
//console.log("File loaded");
|
|
|
|
GetV();
|
|
|
|
});
|
|
|
|
// error event
|
|
|
|
scE.addEventListener("error", (ev) => {
|
|
|
|
console.log("Error on loading file", ev);
|
|
|
|
alert("Loading of configuration script failed.\nIncomplete page data!");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function S() {
|
2023-06-07 21:37:54 +02:00
|
|
|
let l = window.location;
|
|
|
|
if (l.protocol == "file:") {
|
2022-07-17 15:58:41 +02:00
|
|
|
loc = true;
|
2023-06-04 18:40:29 +02:00
|
|
|
locip = localStorage.getItem('locIp');
|
2022-07-17 15:58:41 +02:00
|
|
|
if (!locip) {
|
|
|
|
locip = prompt("File Mode. Please enter WLED IP!");
|
2023-06-04 18:40:29 +02:00
|
|
|
localStorage.setItem('locIp', locip);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// detect reverse proxy
|
2023-06-07 21:37:54 +02:00
|
|
|
let path = l.pathname;
|
2023-06-04 18:40:29 +02:00
|
|
|
let paths = path.slice(1,path.endsWith('/')?-1:undefined).split("/");
|
|
|
|
if (paths.length > 2) {
|
2023-06-07 21:37:54 +02:00
|
|
|
locproto = l.protocol;
|
2023-06-04 18:40:29 +02:00
|
|
|
loc = true;
|
2023-06-08 07:14:03 +02:00
|
|
|
locip = l.hostname + (l.port ? ":" + l.port : "") + "/" + paths[0];
|
2022-07-17 15:58:41 +02:00
|
|
|
}
|
|
|
|
}
|
2023-06-04 18:40:29 +02:00
|
|
|
loadJS(getURL('/settings/s.js?p=1'), false); // If we set async false, file is loaded and executed, then next statement is processed
|
|
|
|
if (loc) d.Sf.action = getURL('/settings/wifi');
|
|
|
|
}
|
|
|
|
function getURL(path) {
|
|
|
|
return (loc ? locproto + "//" + locip : "") + path;
|
2019-11-27 22:28:13 +01:00
|
|
|
}
|
|
|
|
</script>
|
2021-12-06 20:53:09 +01:00
|
|
|
<style>@import url("style.css");</style>
|
2019-11-27 22:28:13 +01:00
|
|
|
</head>
|
2022-07-17 15:58:41 +02:00
|
|
|
<body onload="S()">
|
2019-11-27 22:28:13 +01:00
|
|
|
<form id="form_s" name="Sf" method="post">
|
2021-03-05 09:50:59 +01:00
|
|
|
<div class="toprow">
|
2019-11-27 22:28:13 +01:00
|
|
|
<div class="helpB"><button type="button" onclick="H()">?</button></div>
|
2020-06-10 12:45:44 +02:00
|
|
|
<button type="button" onclick="B()">Back</button><button type="submit">Save & Connect</button><hr>
|
2021-03-05 09:50:59 +01:00
|
|
|
</div>
|
2019-11-27 22:28:13 +01:00
|
|
|
<h2>WiFi setup</h2>
|
|
|
|
<h3>Connect to existing network</h3>
|
2022-11-24 02:50:24 +01:00
|
|
|
<button type="button" id="scan" onclick="N()">Scan</button><br>
|
|
|
|
Network name (SSID, empty to not connect):<br>
|
|
|
|
<input type="text" id="CS" name="CS" maxlength="32"><br>
|
2019-11-27 22:28:13 +01:00
|
|
|
Network password: <br> <input type="password" name="CP" maxlength="63"><br>
|
|
|
|
Static IP (leave at 0.0.0.0 for DHCP):<br>
|
2021-07-01 00:01:27 +02:00
|
|
|
<input name="I0" type="number" class="s" min="0" max="255" required> .
|
|
|
|
<input name="I1" type="number" class="s" min="0" max="255" required> .
|
|
|
|
<input name="I2" type="number" class="s" min="0" max="255" required> .
|
|
|
|
<input name="I3" type="number" class="s" min="0" max="255" required><br>
|
2019-11-27 22:28:13 +01:00
|
|
|
Static gateway:<br>
|
2021-07-01 00:01:27 +02:00
|
|
|
<input name="G0" type="number" class="s" min="0" max="255" required> .
|
|
|
|
<input name="G1" type="number" class="s" min="0" max="255" required> .
|
|
|
|
<input name="G2" type="number" class="s" min="0" max="255" required> .
|
|
|
|
<input name="G3" type="number" class="s" min="0" max="255" required><br>
|
2019-11-27 22:28:13 +01:00
|
|
|
Static subnet mask:<br>
|
2021-07-01 00:01:27 +02:00
|
|
|
<input name="S0" type="number" class="s" min="0" max="255" required> .
|
|
|
|
<input name="S1" type="number" class="s" min="0" max="255" required> .
|
|
|
|
<input name="S2" type="number" class="s" min="0" max="255" required> .
|
|
|
|
<input name="S3" type="number" class="s" min="0" max="255" required><br>
|
2022-11-24 02:50:24 +01:00
|
|
|
mDNS address (leave empty for no mDNS):<br>
|
2021-12-08 22:05:51 +01:00
|
|
|
http:// <input type="text" name="CM" maxlength="32"> .local<br>
|
2019-11-27 22:28:13 +01:00
|
|
|
Client IP: <span class="sip"> Not connected </span> <br>
|
|
|
|
<h3>Configure Access Point</h3>
|
2021-12-08 22:05:51 +01:00
|
|
|
AP SSID (leave empty for no AP):<br> <input type="text" name="AS" maxlength="32"><br>
|
2019-11-27 22:28:13 +01:00
|
|
|
Hide AP name: <input type="checkbox" name="AH"><br>
|
2020-12-19 17:09:39 +01:00
|
|
|
AP password (leave empty for open):<br> <input type="password" name="AP" maxlength="63" pattern="(.{8,63})|()" title="Empty or min. 8 characters"><br>
|
2021-07-01 00:01:27 +02:00
|
|
|
Access Point WiFi channel: <input name="AC" type="number" class="xs" min="1" max="13" required><br>
|
2021-06-20 15:13:38 +02:00
|
|
|
AP opens:
|
|
|
|
<select name="AB">
|
|
|
|
<option value="0">No connection after boot</option>
|
|
|
|
<option value="1">Disconnected</option>
|
|
|
|
<option value="2">Always</option>
|
|
|
|
<option value="3">Never (not recommended)</option></select><br>
|
2020-06-10 12:45:44 +02:00
|
|
|
AP IP: <span class="sip"> Not active </span><br>
|
2020-05-17 21:39:57 +02:00
|
|
|
<h3>Experimental</h3>
|
|
|
|
Disable WiFi sleep: <input type="checkbox" name="WS"><br>
|
|
|
|
<i>Can help with connectivity issues.<br>
|
2021-06-20 15:13:38 +02:00
|
|
|
Do not enable if WiFi is working correctly, increases power consumption.</i>
|
|
|
|
<div id="ethd">
|
2022-04-04 20:52:42 +02:00
|
|
|
<h3>Ethernet Type</h3>
|
|
|
|
<select name="ETH">
|
|
|
|
<option value="0">None</option>
|
2023-06-02 10:51:37 +02:00
|
|
|
<option value="9">ABC! WLED V43 & compatible</option>
|
2022-04-04 20:52:42 +02:00
|
|
|
<option value="2">ESP32-POE</option>
|
|
|
|
<option value="6">ESP32Deux</option>
|
|
|
|
<option value="7">KIT-VE</option>
|
2023-06-02 10:51:37 +02:00
|
|
|
<option value="8">QuinLED-Dig-Octa & T-ETH-POE</option>
|
2022-04-04 20:52:42 +02:00
|
|
|
<option value="4">QuinLED-ESP32</option>
|
2023-05-08 08:48:52 +02:00
|
|
|
<option value="10">Serg74-ETH32</option>
|
2022-04-04 20:52:42 +02:00
|
|
|
<option value="5">TwilightLord-ESP32</option>
|
|
|
|
<option value="3">WESP32</option>
|
|
|
|
<option value="1">WT32-ETH01</option>
|
|
|
|
</select><br><br>
|
2021-06-20 15:13:38 +02:00
|
|
|
</div>
|
2020-05-17 21:39:57 +02:00
|
|
|
<hr>
|
2020-06-10 12:45:44 +02:00
|
|
|
<button type="button" onclick="B()">Back</button><button type="submit">Save & Connect</button>
|
2019-11-27 22:28:13 +01:00
|
|
|
</form>
|
|
|
|
</body>
|
2022-11-24 02:50:24 +01:00
|
|
|
</html>
|