Skip to content

Commit c95892d

Browse files
authored
Merge pull request #21 from yellowcooln/feat/webui-wifi-setup-reset
feat: add generic Wi-Fi setup reset controls
2 parents 01c4d01 + de57e19 commit c95892d

3 files changed

Lines changed: 24 additions & 4 deletions

File tree

firmware/src/main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ void noteTransportFrameError(uint8_t err_code) {
12861286

12871287
// ─── Setup ───────────────────────────────────────────────────
12881288
void setup() {
1289-
// PRG held ≥3s at boot → wipe Wi-Fi NVS and reboot. Must come before
1289+
// PRG held ≥5s at boot → wipe Wi-Fi NVS and reboot. Must come before
12901290
// other init so button sampling is clean.
12911291
WifiManager::checkResetButton();
12921292

@@ -1646,13 +1646,14 @@ void loop() {
16461646
}
16471647

16481648
// PRG short-tap: cycle SLEEP → STATUS → RADIO → DIAGNOSTICS → STATUS → …
1649-
// (Factory reset on 3 s hold-at-boot is handled in setup()/checkResetButton.)
1649+
// (Wi-Fi setup reset on 5 s hold-at-boot is handled in setup()/checkResetButton.)
16501650
// Boards with pin_user_button < 0 (e.g. ESP32-P4-Nano where the BOOT
16511651
// button shares a pin with RMII Ethernet TXD1) skip polling entirely.
16521652
bool btn = false;
16531653
if (BOARD.pin_user_button >= 0) {
16541654
btn = (digitalRead(BOARD.pin_user_button) == (BOARD.user_button_active_low ? LOW : HIGH));
16551655
}
1656+
16561657
if (btn && millis() > prgIgnoreUntil) {
16571658
prgIgnoreUntil = millis() + PRG_DEBOUNCE_MS;
16581659
oledWakeUntil = millis() + OLED_WAKE_DURATION_MS;

firmware/src/ota_manager.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ static void handleRoot() {
664664
"label{display:block;margin-top:.8em;font-weight:600}input{width:100%;padding:.55em;box-sizing:border-box;font-size:1em;border:1px solid #ccc;border-radius:6px}"
665665
"input[type=file]{padding:.3em 0;border:0}input[type=checkbox]{width:auto;margin-right:.45em}"
666666
".checkline{display:flex;align-items:center;gap:.35em;margin-top:.8em}button{margin-top:.9em;padding:.6em 1em;background:#2f6f5e;color:#fff;border:0;border-radius:6px;cursor:pointer}"
667-
"code{font-family:ui-monospace,SFMono-Regular,monospace;background:#f3f3f3;padding:.1em .35em;border-radius:4px}"
667+
"button.danger{background:#b3261e}code{font-family:ui-monospace,SFMono-Regular,monospace;background:#f3f3f3;padding:.1em .35em;border-radius:4px}"
668668
"@media (max-width:640px){body{padding:0 .75em}}</style></head><body>");
669669
body += "<h2>" + title + "</h2>";
670670
body += "<div class='summary'><p><strong>mDNS</strong> " + hostname + ".local</p>";
@@ -749,6 +749,12 @@ static void handleRoot() {
749749
"<button type='submit'>Save password</button>"
750750
"</form><p class='m'>Password changes take effect on the next request.</p></div></details>");
751751

752+
body += F("<details><summary>Wi-Fi Setup Mode</summary><div class='inside'>"
753+
"<p>Clear the saved modem configuration and reboot into the open <code>LoRa-Modem-XXXX</code> setup AP.</p>"
754+
"<form method='POST' action='/wifi-reset' onsubmit=\"return confirm('Clear saved modem configuration and reboot into Wi-Fi setup AP?');\">"
755+
"<button class='danger' type='submit'>Enter Wi-Fi Setup Mode</button>"
756+
"</form><p class='m'>Use this before moving the modem to a different Wi-Fi network.</p></div></details>");
757+
752758
body += F("<details><summary>Reboot</summary><div class='inside'>"
753759
"<p>Restart the modem without changing any settings.</p>"
754760
"<form method='POST' action='/reboot'>"
@@ -969,6 +975,18 @@ static void handleApiReboot() {
969975
ESP.restart();
970976
}
971977

978+
static void handleWifiReset() {
979+
if (!checkAuth()) return;
980+
981+
Serial.printf("[OTA] Wi-Fi setup reset requested by %s\n",
982+
httpServer->client().remoteIP().toString().c_str());
983+
sendSimplePage(F("Entering Wi-Fi setup mode"),
984+
F("Entering Wi-Fi setup mode"),
985+
F("Saved modem configuration is being cleared. The modem will reboot into the open LoRa-Modem setup AP."));
986+
delay(500);
987+
WifiManager::factoryReset(); // does not return
988+
}
989+
972990
static void handleHostnameSave() {
973991
if (!checkAuth()) return;
974992

@@ -1230,6 +1248,7 @@ void begin(const String& hn, const String& tk) {
12301248
httpServer->on("/gps", HTTP_POST, handleGpsSave);
12311249
httpServer->on("/token", HTTP_POST, handleTokenSave);
12321250
httpServer->on("/auth", HTTP_POST, handleAuthSave);
1251+
httpServer->on("/wifi-reset", HTTP_POST, handleWifiReset);
12331252
httpServer->on("/reboot", HTTP_POST, handleReboot);
12341253
httpServer->on("/update", HTTP_POST, handleUpdateResult, handleUpdateUpload);
12351254
httpServer->onNotFound([]() { httpServer->send(404, "text/plain", "Not found"); });

firmware/src/wifi_manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace WifiManager {
1414
static constexpr const char* NVS_NAMESPACE = "lora_modem";
1515
static constexpr uint16_t DEFAULT_TCP_PORT = 5055;
1616
static constexpr uint32_t STA_CONNECT_TIMEOUT_MS = 30000;
17-
static constexpr uint32_t PRG_RESET_HOLD_MS = 3000;
17+
static constexpr uint32_t PRG_RESET_HOLD_MS = 5000;
1818
static constexpr uint8_t MAX_HOSTNAME_LEN = 32;
1919

2020
static Config cfg;

0 commit comments

Comments
 (0)