Skip to content

Commit

Permalink
0.8.107
Browse files Browse the repository at this point in the history
* improved `Wizard`
  • Loading branch information
lumapu committed Apr 8, 2024
1 parent 36b17b1 commit a677079
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 29 deletions.
1 change: 1 addition & 0 deletions src/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions src/network/AhoyNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/network/AhoyWifiAp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/web/RestApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) */

Expand Down
57 changes: 32 additions & 25 deletions src/web/html/wizard.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title>{#NAV_WIZARD}</title>
{#HTML_HEADER}
</head>
<body>
<body onload="init()">
<div id="wrapper">
<div class="container d-flex aic jc">
<div id="con"></div>
Expand All @@ -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 = [
Expand Down Expand Up @@ -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*/
Expand All @@ -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*/
Expand All @@ -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) {
Expand Down Expand Up @@ -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*/
}

</script>
</body>
Expand Down
1 change: 1 addition & 0 deletions src/web/web.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit a677079

Please sign in to comment.