diff --git a/src/WiFiConfig.cpp b/src/WiFiConfig.cpp index f3c8342..5df71bc 100644 --- a/src/WiFiConfig.cpp +++ b/src/WiFiConfig.cpp @@ -303,6 +303,7 @@ String WiFiConfig::rootProcessor(const String &var) { String content; + if (var == "STATUS") { switch (_status) { #if defined(ESP8266) case STATION_IDLE: @@ -366,9 +367,26 @@ String WiFiConfig::rootProcessor(const String &var) break; #endif } + } else if (var == F("RESTORE")) { + if (USEDFS.exists(F(WIFICFG_OLD_FILE))) { + content = FPSTR(PAGE_RESTORE); + } + } return content; } +void WiFiConfig::_handleRestore(AsyncWebServerRequest *request) +{ + + USEDFS.remove(F(WIFICFG_FILE)); + USEDFS.rename(F(WIFICFG_OLD_FILE), F(WIFICFG_FILE)); + + request->onDisconnect([]() { + _doReconfig = true; // aktivujeme novou konfiguraci a restartujeme ESP + }); + request->send_P(200, TEXTHTML, PAGE_SAVED); +} + void WiFiConfig::_handleNotFound(AsyncWebServerRequest *request) { @@ -582,6 +600,7 @@ wificonfigresult_t WiFiConfig::_setupAP(wificonfig_cb cb) server->on(PSTR("/s"), std::bind(&WiFiConfig::_handleSetAP, this, std::placeholders::_1)); server->on(PSTR("/r"), std::bind(&WiFiConfig::_handleReset, this, std::placeholders::_1)); server->on(PSTR("/i"), std::bind(&WiFiConfig::_handleInfo, this, std::placeholders::_1)); + server->on(PSTR("/o"), std::bind(&WiFiConfig::_handleRestore, this, std::placeholders::_1)); server->on(PSTR("/index.htm"), std::bind(&WiFiConfig::_handleRoot, this, std::placeholders::_1)); #ifdef USE_WIFICONFIG_OTAUPDATE server->on(PSTR("/u"), []() { diff --git a/src/WiFiConfig.h b/src/WiFiConfig.h index 17869c3..f8802ab 100644 --- a/src/WiFiConfig.h +++ b/src/WiFiConfig.h @@ -160,6 +160,7 @@ private: void _handleNotFound(AsyncWebServerRequest *request); // CaptivePortal redirector void _handleRoot(AsyncWebServerRequest *request); // jen jednoducha stranka kvuli CaptivePortalu umoznuje prejit na spravnou stranku (ale nedela to...) void _handleScan(AsyncWebServerRequest *request); + void _handleRestore(AsyncWebServerRequest *request); bool _testWifi(wificonfig_cb cb); WiFiConfigUsrParameter *_searchUsrParameter(const char *name); IPAddress _getIP(const String &from); diff --git a/src/embHTML.h b/src/embHTML.h index d99a122..66d7fe0 100644 --- a/src/embHTML.h +++ b/src/embHTML.h @@ -127,7 +127,7 @@ static const char PAGE_SAVED[] PROGMEM = R"=====( xPablo Setup - Konfigurace uložena -Uloženo do EEPROM...
+Uloženo do Flash...
Restart za několik sekund. )====="; @@ -138,6 +138,7 @@ static const char PAGE_CAPTIVEPORTALCATCH[] PROGMEM = R"=====( .vl-info {border-left: thick solid #1fa3ec;background: #cee6ff; text-align:left; display:inline-block; min-width:260px; margin-top:15px} .red { background-color: #ff0000;} .magenta { background-color: #ff00ff;} +.yellow { background-color: #FFD700;}
@@ -145,7 +146,9 @@ static const char PAGE_CAPTIVEPORTALCATCH[] PROGMEM = R"=====(

-

+

+$RESTORE$ +

)=====" #if defined USE_WIFICONFIG_OTAUPDATE R"=====( @@ -255,3 +258,9 @@ button{border:0;border-radius:0.3rem;background-color:#1fa3ec;color:#fff;line-he Flash Chip ID:$FID$ )====="; + +static const char PAGE_RESTORE[] PROGMEM = R"=====( +
+ +

+)=====";