|
|
@ -393,6 +393,7 @@ void AutoConnect::_startWebServer() { |
|
|
|
if (!_responsePage) { |
|
|
|
if (!_responsePage) { |
|
|
|
_responsePage = new PageBuilder(); |
|
|
|
_responsePage = new PageBuilder(); |
|
|
|
_responsePage->chunked(AUTOCONNECT_HTTP_TRANSFER); |
|
|
|
_responsePage->chunked(AUTOCONNECT_HTTP_TRANSFER); |
|
|
|
|
|
|
|
_responsePage->reserve(AUTOCONNECT_CONTENTBUFFER_SIZE); |
|
|
|
_responsePage->exitCanHandle(std::bind(&AutoConnect::_classifyHandle, this, std::placeholders::_1, std::placeholders::_2)); |
|
|
|
_responsePage->exitCanHandle(std::bind(&AutoConnect::_classifyHandle, this, std::placeholders::_1, std::placeholders::_2)); |
|
|
|
_responsePage->insert(*_webServer); |
|
|
|
_responsePage->insert(*_webServer); |
|
|
|
|
|
|
|
|
|
|
@ -600,8 +601,8 @@ bool AutoConnect::_captivePortal() { |
|
|
|
String hostHeader = _webServer->hostHeader(); |
|
|
|
String hostHeader = _webServer->hostHeader(); |
|
|
|
if (!_isIP(hostHeader) && (hostHeader != WiFi.localIP().toString())) { |
|
|
|
if (!_isIP(hostHeader) && (hostHeader != WiFi.localIP().toString())) { |
|
|
|
String location = String(F("http://")) + _webServer->client().localIP().toString() + String(AUTOCONNECT_URI); |
|
|
|
String location = String(F("http://")) + _webServer->client().localIP().toString() + String(AUTOCONNECT_URI); |
|
|
|
_webServer->sendHeader(F("Location"), location, true); |
|
|
|
_webServer->sendHeader(String(F("Location")), location, true); |
|
|
|
_webServer->send(302, F("text/plain"), ""); |
|
|
|
_webServer->send(302, String(F("text/plain")), ""); |
|
|
|
_webServer->client().flush(); |
|
|
|
_webServer->client().flush(); |
|
|
|
_webServer->client().stop(); |
|
|
|
_webServer->client().stop(); |
|
|
|
return true; |
|
|
|
return true; |
|
|
@ -649,13 +650,13 @@ void AutoConnect::_handleNotFound() { |
|
|
|
_notFoundHandler(); |
|
|
|
_notFoundHandler(); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
PageElement page404(_PAGE_404, { { "HEAD", std::bind(&AutoConnect::_token_HEAD, this, std::placeholders::_1) } }); |
|
|
|
PageElement page404(_PAGE_404, { { String(F("HEAD")), std::bind(&AutoConnect::_token_HEAD, this, std::placeholders::_1) } }); |
|
|
|
String html = page404.build(); |
|
|
|
String html = page404.build(); |
|
|
|
_webServer->sendHeader(F("Cache-Control"), F("no-cache, no-store, must-revalidate"), true); |
|
|
|
_webServer->sendHeader(String(F("Cache-Control")), String(F("no-cache, no-store, must-revalidate")), true); |
|
|
|
_webServer->sendHeader(F("Pragma"), F("no-cache")); |
|
|
|
_webServer->sendHeader(String(F("Pragma")), String(F("no-cache"))); |
|
|
|
_webServer->sendHeader(F("Expires"), F("-1")); |
|
|
|
_webServer->sendHeader(String(F("Expires")), String("-1")); |
|
|
|
_webServer->sendHeader(F("Content-Length"), String(html.length())); |
|
|
|
_webServer->sendHeader(String(F("Content-Length")), String(html.length())); |
|
|
|
_webServer->send(404, F("text/html"), html); |
|
|
|
_webServer->send(404, String(F("text/html")), html); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -730,9 +731,8 @@ String AutoConnect::_induceConnect(PageArgument& args) { |
|
|
|
// String url = String(F("http://")) + _webServer->client().localIP().toString() + String(AUTOCONNECT_URI_RESULT);
|
|
|
|
// String url = String(F("http://")) + _webServer->client().localIP().toString() + String(AUTOCONNECT_URI_RESULT);
|
|
|
|
// _webServer->sendHeader(F("Location"), url, true);
|
|
|
|
// _webServer->sendHeader(F("Location"), url, true);
|
|
|
|
// _webServer->send(302, F("text/plain"), "");
|
|
|
|
// _webServer->send(302, F("text/plain"), "");
|
|
|
|
// _webServer->client().stop();
|
|
|
|
|
|
|
|
// _webServer->client().flush();
|
|
|
|
// _webServer->client().flush();
|
|
|
|
// _waitForEndTransmission(); // Wait for response transmission complete
|
|
|
|
// _webServer->client().stop();
|
|
|
|
// _responsePage->cancel();
|
|
|
|
// _responsePage->cancel();
|
|
|
|
return String(""); |
|
|
|
return String(""); |
|
|
|
} |
|
|
|
} |
|
|
@ -742,10 +742,11 @@ String AutoConnect::_induceConnect(PageArgument& args) { |
|
|
|
* A destination as _redirectURI is indicated by loop to establish connection. |
|
|
|
* A destination as _redirectURI is indicated by loop to establish connection. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
String AutoConnect::_invokeResult(PageArgument& args) { |
|
|
|
String AutoConnect::_invokeResult(PageArgument& args) { |
|
|
|
|
|
|
|
AC_DBG("_invokeResult entered\n"); |
|
|
|
String redirect = String(F("http://")); |
|
|
|
String redirect = String(F("http://")); |
|
|
|
// The host address to which the connection result for ESP32 responds
|
|
|
|
// The host address to which the connection result for ESP32 responds
|
|
|
|
// changed from v0.9.7. This change is a measure according to the
|
|
|
|
// changed from v0.9.7. This change is a measure according to the
|
|
|
|
// implementation of the arduino-esp32 1.0.1 core.
|
|
|
|
// implementation of the arduino-esp32 1.0.1.
|
|
|
|
#if defined(ARDUINO_ARCH_ESP32) |
|
|
|
#if defined(ARDUINO_ARCH_ESP32) |
|
|
|
// In ESP32, the station IP address just established could not be reached.
|
|
|
|
// In ESP32, the station IP address just established could not be reached.
|
|
|
|
redirect += _webServer->client().localIP().toString(); |
|
|
|
redirect += _webServer->client().localIP().toString(); |
|
|
@ -756,10 +757,10 @@ String AutoConnect::_invokeResult(PageArgument& args) { |
|
|
|
redirect += _currentHostIP.toString(); |
|
|
|
redirect += _currentHostIP.toString(); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
redirect += _redirectURI; |
|
|
|
redirect += _redirectURI; |
|
|
|
_webServer->sendHeader(F("Location"), redirect, true); |
|
|
|
_webServer->sendHeader(String(F("Location")), redirect, true); |
|
|
|
_webServer->send(302, F("text/plain"), ""); |
|
|
|
_webServer->send(302, String(F("text/plain")), ""); |
|
|
|
_webServer->client().stop(); |
|
|
|
|
|
|
|
_webServer->client().flush(); |
|
|
|
_webServer->client().flush(); |
|
|
|
|
|
|
|
_webServer->client().stop(); |
|
|
|
_waitForEndTransmission(); // Wait for response transmission complete
|
|
|
|
_waitForEndTransmission(); // Wait for response transmission complete
|
|
|
|
_responsePage->cancel(); |
|
|
|
_responsePage->cancel(); |
|
|
|
return String(""); |
|
|
|
return String(""); |
|
|
|