Moznost pouzit predminulou konfiguraci

This commit is contained in:
Pavel Brychta 2021-08-26 07:03:29 +02:00
parent 610229d21d
commit 9797117ab9
3 changed files with 31 additions and 2 deletions

View File

@ -303,6 +303,7 @@ String WiFiConfig::rootProcessor(const String &var)
{ {
String content; String content;
if (var == "STATUS") {
switch (_status) { switch (_status) {
#if defined(ESP8266) #if defined(ESP8266)
case STATION_IDLE: case STATION_IDLE:
@ -366,9 +367,26 @@ String WiFiConfig::rootProcessor(const String &var)
break; break;
#endif #endif
} }
} else if (var == F("RESTORE")) {
if (USEDFS.exists(F(WIFICFG_OLD_FILE))) {
content = FPSTR(PAGE_RESTORE);
}
}
return content; 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) 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("/s"), std::bind(&WiFiConfig::_handleSetAP, this, std::placeholders::_1));
server->on(PSTR("/r"), std::bind(&WiFiConfig::_handleReset, 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("/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)); server->on(PSTR("/index.htm"), std::bind(&WiFiConfig::_handleRoot, this, std::placeholders::_1));
#ifdef USE_WIFICONFIG_OTAUPDATE #ifdef USE_WIFICONFIG_OTAUPDATE
server->on(PSTR("/u"), []() { server->on(PSTR("/u"), []() {

View File

@ -160,6 +160,7 @@ private:
void _handleNotFound(AsyncWebServerRequest *request); // CaptivePortal redirector void _handleNotFound(AsyncWebServerRequest *request); // CaptivePortal redirector
void _handleRoot(AsyncWebServerRequest *request); // jen jednoducha stranka kvuli CaptivePortalu umoznuje prejit na spravnou stranku (ale nedela to...) void _handleRoot(AsyncWebServerRequest *request); // jen jednoducha stranka kvuli CaptivePortalu umoznuje prejit na spravnou stranku (ale nedela to...)
void _handleScan(AsyncWebServerRequest *request); void _handleScan(AsyncWebServerRequest *request);
void _handleRestore(AsyncWebServerRequest *request);
bool _testWifi(wificonfig_cb cb); bool _testWifi(wificonfig_cb cb);
WiFiConfigUsrParameter *_searchUsrParameter(const char *name); WiFiConfigUsrParameter *_searchUsrParameter(const char *name);
IPAddress _getIP(const String &from); IPAddress _getIP(const String &from);

View File

@ -127,7 +127,7 @@ static const char PAGE_SAVED[] PROGMEM = R"=====(
<title>xPablo Setup - Konfigurace uložena</title> <title>xPablo Setup - Konfigurace uložena</title>
<style>div,input {margin-bottom: 5px;}body{width:200px;display:block;margin-left:auto;margin-right:auto;}</style> <style>div,input {margin-bottom: 5px;}body{width:200px;display:block;margin-left:auto;margin-right:auto;}</style>
</head><body> </head><body>
Uloženo do EEPROM...<br/> Uloženo do Flash...<br/>
Restart za několik sekund. Restart za několik sekund.
</body></html> </body></html>
)====="; )=====";
@ -138,6 +138,7 @@ static const char PAGE_CAPTIVEPORTALCATCH[] PROGMEM = R"=====(<!DOCTYPE html>
.vl-info {border-left: thick solid #1fa3ec;background: #cee6ff; text-align:left; display:inline-block; min-width:260px; margin-top:15px} .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;} .red { background-color: #ff0000;}
.magenta { background-color: #ff00ff;} .magenta { background-color: #ff00ff;}
.yellow { background-color: #FFD700;}
</style> </style>
</head><body><div style='text-align:left;display:inline-block;min-width:260px;'> </head><body><div style='text-align:left;display:inline-block;min-width:260px;'>
<form action="/config" method="get"> <form action="/config" method="get">
@ -145,7 +146,9 @@ static const char PAGE_CAPTIVEPORTALCATCH[] PROGMEM = R"=====(<!DOCTYPE html>
</form><br/> </form><br/>
<form action="/i" method="get"> <form action="/i" method="get">
<button>Informace o modulu</button> <button>Informace o modulu</button>
</form><br/><form action="/r" method="post"> </form><br/>
$RESTORE$
<form action="/r" method="post">
<button class="red">Reset</button></form><br>)=====" <button class="red">Reset</button></form><br>)====="
#if defined USE_WIFICONFIG_OTAUPDATE #if defined USE_WIFICONFIG_OTAUPDATE
R"=====( R"=====(
@ -255,3 +258,9 @@ button{border:0;border-radius:0.3rem;background-color:#1fa3ec;color:#fff;line-he
<tr><td>Flash Chip ID:<td>$FID$ <tr><td>Flash Chip ID:<td>$FID$
</table></form> </table></form>
)====="; )=====";
static const char PAGE_RESTORE[] PROGMEM = R"=====(
<form action="/o" method="post">
<button class="yellow">Předminulá konfigurace</button>
</form><br/>
)=====";