Better reconnect check

This commit is contained in:
fvanroie 2020-03-10 21:59:59 +01:00
parent 1312f34ae3
commit b72c5fbbca
2 changed files with 33 additions and 24 deletions

View File

@ -1209,8 +1209,6 @@ void httpSetup(const JsonObject & settings)
if(WiFi.getMode() == WIFI_AP) { if(WiFi.getMode() == WIFI_AP) {
debugPrintln(F("HTTP: Wifi access point")); debugPrintln(F("HTTP: Wifi access point"));
webServer.on(F("/"), webHandleWifiConfig); webServer.on(F("/"), webHandleWifiConfig);
webServer.on(F("/config"), webHandleConfig);
webServer.onNotFound(httpHandleNotFound);
} else { } else {
webServer.on(F("/page/"), []() { webServer.on(F("/page/"), []() {
@ -1250,9 +1248,8 @@ void httpSetup(const JsonObject & settings)
});*/ });*/
webServer.on(F("/"), webHandleRoot); webServer.on(F("/"), webHandleRoot);
webServer.on(F("/about"), webHandleAbout);
webServer.on(F("/info"), webHandleInfo); webServer.on(F("/info"), webHandleInfo);
webServer.on(F("/config"), webHandleConfig);
webServer.on(F("/config/hasp"), webHandleHaspConfig); webServer.on(F("/config/hasp"), webHandleHaspConfig);
webServer.on(F("/config/http"), webHandleHttpConfig); webServer.on(F("/config/http"), webHandleHttpConfig);
webServer.on(F("/config/gui"), webHandleGuiConfig); webServer.on(F("/config/gui"), webHandleGuiConfig);
@ -1272,6 +1269,12 @@ void httpSetup(const JsonObject & settings)
webServer.onNotFound(httpHandleNotFound); webServer.onNotFound(httpHandleNotFound);
} }
// Shared pages
webServer.on(F("/about"), webHandleAbout);
webServer.on(F("/config"), webHandleConfig);
webServer.onNotFound(httpHandleNotFound);
httpReconnect();
debugPrintln(F("HTTP: Setup Complete")); debugPrintln(F("HTTP: Setup Complete"));
} }
@ -1280,33 +1283,38 @@ void httpReconnect()
{ {
if(!httpEnable) return; if(!httpEnable) return;
if(webServerStarted) {
webServer.stop(); webServer.stop();
webServerStarted = false; webServerStarted = false;
debugPrintln(F("HTTP: Server stoped"));
} else if(WiFi.status() == WL_CONNECTED || WiFi.getMode() == WIFI_AP) {
/*
if(WiFi.getMode() == WIFI_AP) { if(WiFi.getMode() == WIFI_AP) {
webServer.on(F("/"), webHandleWifiConfig); webServer.on(F("/"), webHandleWifiConfig);
webServer.on(F("/config"), webHandleConfig); webServer.on(F("/config"), webHandleConfig);
webServer.onNotFound(httpHandleNotFound); webServer.onNotFound(httpHandleNotFound);
} else { } else {
if(WiFi.status() != WL_CONNECTED) return;
} }
*/
webServer.begin(); webServer.begin();
webServerStarted = true; webServerStarted = true;
debugPrintln(String(F("HTTP: Server started @ http://")) + debugPrintln(String(F("HTTP: Server started @ http://")) +
(WiFi.getMode() == WIFI_AP ? WiFi.softAPIP().toString() : WiFi.localIP().toString())); (WiFi.getMode() == WIFI_AP ? WiFi.softAPIP().toString() : WiFi.localIP().toString()));
}
} }
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
void httpLoop() void httpLoop()
{ {
if(httpEnable) { if(httpEnable) webServer.handleClient();
if(webServerStarted) }
webServer.handleClient();
else ////////////////////////////////////////////////////////////////////////////////////////////////////
httpReconnect(); void httpEverySecond()
} {
if(httpEnable && !webServerStarted) httpReconnect();
} }
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -6,6 +6,7 @@
void httpSetup(const JsonObject & settings); void httpSetup(const JsonObject & settings);
void httpLoop(void); void httpLoop(void);
void httpEverySecond(void);
void httpReconnect(void); void httpReconnect(void);
bool httpGetConfig(const JsonObject & settings); bool httpGetConfig(const JsonObject & settings);