Reorder SoftAP setup

This commit is contained in:
fvanroie 2020-02-21 23:49:03 +01:00
parent 220b0f39a0
commit bde590394d

View File

@ -195,7 +195,7 @@ void httpHandleReboot()
////////////////////////////////////////////////////////////////////////////////////////////////////
void webHandleScreenshot()
{ // http://plate01/about
{ // http://plate01/screenshot
if(!httpIsAuthenticated(F("/screenshot"))) return;
if(webServer.hasArg(F("q"))) {
@ -222,6 +222,7 @@ void webHandleScreenshot()
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void webHandleAbout()
{ // http://plate01/about
if(!httpIsAuthenticated(F("/about"))) return;
@ -261,6 +262,7 @@ void webHandleAbout()
webServer.sendContent(httpMessage); // len
webServer.sendContent_P(HTTP_END); // 20
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void webHandleInfo()
{ // http://plate01/
@ -336,8 +338,8 @@ void webHandleInfo()
httpMessage += FPSTR(MAIN_MENU_BUTTON);
webSendPage(nodename, httpMessage.length(), false);
webServer.sendContent(httpMessage); // len
webServer.sendContent_P(HTTP_END); // 20
webServer.sendContent(httpMessage);
webServer.sendContent_P(HTTP_END);
}
String getContentType(String filename)
@ -370,7 +372,7 @@ String getContentType(String filename)
return F("text/plain");
}
String urldecode(String str)
/* String urldecode(String str)
{
String encodedString = "";
char c;
@ -394,13 +396,14 @@ String urldecode(String str)
yield();
}
return encodedString;
}
} */
bool handleFileRead(String path)
{
if(!httpIsAuthenticated(F("fileread"))) return false;
path = urldecode(path).substring(0, 31);
// path = urldecode(path).substring(0, 31);
path = webServer.urlDecode(path);
if(!httpIsAuthenticated(path)) return false;
if(path.endsWith("/")) {
@ -988,6 +991,13 @@ void httpHandleResetConfig()
////////////////////////////////////////////////////////////////////////////////////////////////////
void httpSetup(const JsonObject & settings)
{
if(WiFi.getMode() == WIFI_AP) {
debugPrintln(F("HTTP: Wifi access point"));
webServer.on(F("/"), webHandleWifiConfig);
webServer.on(F("/config"), webHandleConfig);
webServer.onNotFound(httpHandleNotFound);
} else {
webServer.on(F("/page/"), []() {
String pageid = webServer.arg(F("page"));
webServer.send(200, PSTR("text/plain"), "Page: '" + pageid + "'");
@ -1036,6 +1046,7 @@ void httpSetup(const JsonObject & settings)
webServer.on(F("/espfirmware"), httpHandleEspFirmware);
webServer.on(F("/reboot"), httpHandleReboot);
webServer.onNotFound(httpHandleNotFound);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
@ -1043,16 +1054,16 @@ void httpReconnect()
{
if(!httpEnable) return;
if(WiFi.getMode() == WIFI_AP) {
webServer.on(F("/"), webHandleWifiConfig);
webServer.on(F("/config"), webHandleConfig);
webServer.onNotFound(webHandleWifiConfig);
}
webServer.stop();
webServerStarted = false;
if(WiFi.getMode() == WIFI_AP) {
webServer.on(F("/"), webHandleWifiConfig);
webServer.on(F("/config"), webHandleConfig);
webServer.onNotFound(httpHandleNotFound);
} else {
if(WiFi.status() != WL_CONNECTED) return;
}
webServer.begin();
webServerStarted = true;