From a677079681d3a899c668a8289cb668d81bddb508 Mon Sep 17 00:00:00 2001 From: lumapu Date: Tue, 9 Apr 2024 00:13:34 +0200 Subject: [PATCH] 0.8.107 * improved `Wizard` --- src/CHANGES.md | 1 + src/network/AhoyNetwork.h | 7 +++-- src/network/AhoyWifiAp.h | 1 + src/web/RestApi.h | 1 + src/web/html/wizard.html | 57 ++++++++++++++++++++++----------------- src/web/web.h | 1 + 6 files changed, 39 insertions(+), 29 deletions(-) diff --git a/src/CHANGES.md b/src/CHANGES.md index d1069c8c..61b6cc12 100644 --- a/src/CHANGES.md +++ b/src/CHANGES.md @@ -3,6 +3,7 @@ ## 0.8.107 - 2024-04-08 * fix boot loop on `reboot on midnight` feature #1542, #1599, #1566, #1571 * fix German translation #1569 +* improved `Wizard` ## 0.8.106 - 2024-04-05 * fix bootloop with CMT and NRF on ESP32 #1566 #1562 diff --git a/src/network/AhoyNetwork.h b/src/network/AhoyNetwork.h index 55c5d193..c0ea55c2 100644 --- a/src/network/AhoyNetwork.h +++ b/src/network/AhoyNetwork.h @@ -91,12 +91,10 @@ class AhoyNetwork { #if !defined(ETHERNET) bool getAvailNetworks(JsonObject obj) { - JsonArray nets = obj.createNestedArray(F("networks")); - if(!mScanActive) { mScanActive = true; - if(NetworkState::GOT_IP != mStatus) - WiFi.disconnect(); + //if(NetworkState::GOT_IP != mStatus) + // WiFi.disconnect(); WiFi.scanNetworks(true, true); return false; } @@ -106,6 +104,7 @@ class AhoyNetwork { return false; if(n > 0) { + JsonArray nets = obj.createNestedArray(F("networks")); int sort[n]; sortRSSI(&sort[0], n); for (int i = 0; i < n; ++i) { diff --git a/src/network/AhoyWifiAp.h b/src/network/AhoyWifiAp.h index ce2bbd1b..994af3de 100644 --- a/src/network/AhoyWifiAp.h +++ b/src/network/AhoyWifiAp.h @@ -44,6 +44,7 @@ class AhoyWifiAp { WiFi.softAPConfig(mIp, mIp, IPAddress(255, 255, 255, 0)); WiFi.softAP(WIFI_AP_SSID, mCfg->apPwd); + mDns.setErrorReplyCode(DNSReplyCode::NoError); mDns.start(53, "*", mIp); mEnabled = true; diff --git a/src/web/RestApi.h b/src/web/RestApi.h index fdc54fa4..1ed5d204 100644 --- a/src/web/RestApi.h +++ b/src/web/RestApi.h @@ -892,6 +892,7 @@ class RestApi { #if !defined(ETHERNET) void getNetworks(JsonObject obj) { obj[F("success")] = mApp->getAvailNetworks(obj); + obj[F("ip")] = mApp->getIp(); } #endif /* !defined(ETHERNET) */ diff --git a/src/web/html/wizard.html b/src/web/html/wizard.html index 1fc8503c..a6a29bbb 100644 --- a/src/web/html/wizard.html +++ b/src/web/html/wizard.html @@ -4,7 +4,7 @@ {#NAV_WIZARD} {#HTML_HEADER} - +
@@ -14,6 +14,7 @@ var v; var found = false; var c = document.getElementById("con"); + var redirIp = "http://192.168.4.1/index" /*IF_ESP32*/ var pinList = [ @@ -206,7 +207,7 @@ ]), ...lst, ml("div", {class: "row my-4"}, ml("div", {class: "col a-r"}, ml("input", {type: "button", class:"btn", value: "{#BTN_REBOOT}", onclick: () => {saveEth()}}, null))), - ml("div", {class: "row mt-5"}, ml("div", {class: "col a-c"}, ml("a", {href: "http://192.168.4.1/"}, "{#STOP_WIZARD}"))) + ml("div", {class: "row mt-5"}, ml("div", {class: "col a-c"}, ml("a", {onclick: () => {redirect()}}, "{#STOP_WIZARD}"))) ]) } /*ELSE*/ @@ -218,7 +219,7 @@ sect("{#WIFI_MANUAL}", ml("input", {id: "man", type: "text"})), sect("{#WIFI_PASSWORD}", ml("input", {id: "pwd", type: "password"})), ml("div", {class: "row my-4"}, ml("div", {class: "col a-r"}, ml("input", {type: "button", class:"btn", value: "{#BTN_NEXT}", onclick: () => {saveWifi()}}, null))), - ml("div", {class: "row mt-5"}, ml("div", {class: "col a-c"}, ml("a", {href: "http://192.168.4.1/index"}, "{#STOP_WIZARD}"))) + ml("div", {class: "row mt-5"}, ml("div", {class: "col a-c"}, ml("a", {onclick: () => {redirect()}}, "{#STOP_WIZARD}"))) ]) } /*ENDIF_ETHERNET*/ @@ -229,13 +230,13 @@ ml("div", {class: "row"}, ml("div", {class: "col"}, ml("span", {class: "fs-5"}, "{#TEST_CONNECTION}"))), sect("{#TRY_TO_CONNECT}", ml("span", {id: "state"}, "{#CONNECTING}")), ml("div", {class: "row my-4"}, ml("div", {class: "col a-r"}, ml("input", {type: "button", class:"btn hide", id: "btn", value: "{#BTN_FINISH}", onclick: () => {redirect()}}, null))), - ml("div", {class: "row mt-5"}, ml("div", {class: "col a-c"}, ml("a", {href: "http://192.168.4.1/index"}, "{#STOP_WIZARD}"))) + ml("div", {class: "row mt-5"}, ml("div", {class: "col a-c"}, ml("a", {onclick: () => {redirect()}}, "{#STOP_WIZARD}"))) ) - v = setInterval(() => {getAjax('/api/setup/getip', printIp)}, 300); + v = setInterval(() => {getAjax('/api/setup/getip', printIp)}, 500); } function redirect() { - window.location.replace("http://192.168.4.1/") + window.location.replace(redirIp) } function printIp(obj) { @@ -266,29 +267,35 @@ } /*ENDIF_ETHERNET*/ - /*IF_ETHERNET*/ - getAjax("/api/setup", ((o) => c.append(step1(o.eth)))); - /*ELSE*/ - function nets(obj) { - if(!obj.success) - return; + function init() { + /*IF_ETHERNET*/ + getAjax("/api/setup", ((o) => c.append(step1(o.eth)))); + /*ELSE*/ + function nets(obj) { + if(!obj.success) + return; + + clearInterval(v) + v = setInterval(() => {getAjax('/api/setup/networks', nets)}, 5000) - var e = document.getElementById("net"); - if(obj.networks.length > 0) { - var a = [] - a.push(ml("option", {value: -1}, obj.networks.length + " {#NUM_NETWORKS_FOUND}")) - for(n of obj.networks) { - a.push(ml("option", {value: n.ssid}, n.ssid + " (" + n.rssi + "dBm)")) - found = true; + var e = document.getElementById("net"); + if(obj.networks.length > 0) { + var a = [] + a.push(ml("option", {value: -1}, obj.networks.length + " {#NUM_NETWORKS_FOUND}")) + for(n of obj.networks) { + a.push(ml("option", {value: n.ssid}, n.ssid + " (" + n.rssi + "dBm)")) + found = true; + } + e.replaceChildren(...a) } - e.replaceChildren(...a) + + redirIp = obj.ip + "/index" } - } - c.append(step1()) - getAjax('/api/setup/networks', nets) - v = setInterval(() => {getAjax('/api/setup/networks', nets)}, 1000) - /*ENDIF_ETHERNET*/ + c.append(step1()) + getAjax('/api/setup/networks', nets) + /*ENDIF_ETHERNET*/ + } diff --git a/src/web/web.h b/src/web/web.h index 4f93b905..e88aa813 100644 --- a/src/web/web.h +++ b/src/web/web.h @@ -76,6 +76,7 @@ class Web { mWeb.on("/setup", HTTP_GET, std::bind(&Web::onSetup, this, std::placeholders::_1)); mWeb.on("/wizard", HTTP_GET, std::bind(&Web::onWizard, this, std::placeholders::_1)); + mWeb.on("/generate_204", HTTP_GET, std::bind(&Web::onWizard, this, std::placeholders::_1)); //Android captive portal mWeb.on("/save", HTTP_POST, std::bind(&Web::showSave, this, std::placeholders::_1)); mWeb.on("/live", HTTP_ANY, std::bind(&Web::onLive, this, std::placeholders::_1));