webui: add AP reset recovery action
This commit is contained in:
@@ -250,6 +250,7 @@ input{width:100%;border:1px solid var(--line);border-radius:12px;padding:12px;ba
|
||||
<button onclick="toggleApPassword()">Show / Hide Password</button>
|
||||
<button class="on" onclick="saveApConfig()">Save AP Settings</button>
|
||||
</div>
|
||||
<button class="off" onclick="resetApConfig()">Reset AP to Default</button>
|
||||
<div class="configWarning">Saving AP settings restarts the access point. Your phone may disconnect and need to reconnect to the new SSID/password. Dashboard auto-migration is planned but not implemented yet.</div>
|
||||
</div>
|
||||
</section>
|
||||
@@ -447,6 +448,28 @@ function renderApConfig(data){
|
||||
setConfigValue("apSsidInput",n.ap_ssid||"");
|
||||
}
|
||||
|
||||
|
||||
async function resetApConfig(){
|
||||
if(!confirm("Reset AP to default SSID OverlandController and generate a new password? Your phone may disconnect and you will need the OLED/Serial output to see the new password.")){
|
||||
return;
|
||||
}
|
||||
|
||||
const r=await fetch(api("/config/ap/reset"),{method:"POST"});
|
||||
const text=await r.text();
|
||||
let body=null;
|
||||
try{ body=JSON.parse(text); }catch(e){}
|
||||
|
||||
if(!r.ok || body?.ok===false){
|
||||
alert("Failed to reset AP settings: "+(body?.error||text||r.status));
|
||||
return;
|
||||
}
|
||||
|
||||
clearConfigTouched(["apSsidInput","apPasswordInput"]);
|
||||
if($("apSsidInput")) $("apSsidInput").value=body?.ssid||"OverlandController";
|
||||
if($("apPasswordInput")) $("apPasswordInput").value="";
|
||||
alert("AP reset. Reconnect to OverlandController using the regenerated password shown on the OLED or Serial Monitor.");
|
||||
}
|
||||
|
||||
async function saveApConfig(){
|
||||
const ssid=$("apSsidInput")?.value.trim()||"";
|
||||
const password=$("apPasswordInput")?.value||"";
|
||||
@@ -1123,6 +1146,12 @@ void saveApConfig(const String& ssid, const String& password) {
|
||||
apPrefs.end();
|
||||
}
|
||||
|
||||
void resetApConfigToDefaults() {
|
||||
String newPassword = generateDefaultApPassword();
|
||||
saveApConfig("OverlandController", newPassword);
|
||||
}
|
||||
|
||||
|
||||
bool startAccessPoint() {
|
||||
bool ok = WiFi.softAP(apSsid.c_str(), apPassword.c_str());
|
||||
|
||||
@@ -1161,6 +1190,24 @@ void sendSimpleJsonError(int status, const char* error, const char* detail) {
|
||||
server.send(status, "application/json", output);
|
||||
}
|
||||
|
||||
|
||||
void handleResetApConfig() {
|
||||
resetApConfigToDefaults();
|
||||
restartAccessPoint();
|
||||
|
||||
DynamicJsonDocument response(512);
|
||||
response["ok"] = true;
|
||||
response["ssid"] = apSsid;
|
||||
response["password_set"] = true;
|
||||
response["auth"] = "wpa2";
|
||||
response["ap_ip"] = WiFi.softAPIP().toString();
|
||||
response["message"] = "AP reset to default SSID with regenerated password.";
|
||||
|
||||
String output;
|
||||
serializeJson(response, output);
|
||||
server.send(200, "application/json", output);
|
||||
}
|
||||
|
||||
void handleGetApConfig() {
|
||||
DynamicJsonDocument response(512);
|
||||
|
||||
@@ -3448,6 +3495,7 @@ void setup() {
|
||||
server.on(API_V1("/config/wifi"), HTTP_GET, handleGetWifiConfig);
|
||||
server.on(API_V1("/config/ap"), HTTP_GET, handleGetApConfig);
|
||||
server.on(API_V1("/config/ap"), HTTP_POST, handleUpdateApConfig);
|
||||
server.on(API_V1("/config/ap/reset"), HTTP_POST, handleResetApConfig);
|
||||
server.on(API_V1("/config/wifi"), HTTP_POST, handleUpdateWifiConfig);
|
||||
server.on(API_V1("/wifi/connect"), HTTP_POST, handleWifiConnect);
|
||||
server.on(API_V1("/wifi/clear"), HTTP_POST, handleWifiClear);
|
||||
|
||||
Reference in New Issue
Block a user