Supports AutoConnectAux

pull/41/head
Hieromon Ikasamo 6 years ago
parent a7402ea391
commit a18d543665
  1. 39
      src/AutoConnect.cpp
  2. 1
      src/AutoConnectDefs.h
  3. 2
      src/AutoConnectPage.cpp

@ -388,8 +388,8 @@ void AutoConnect::handleRequest() {
_disconnectWiFi(true); _disconnectWiFi(true);
// An attempt to establish a new AP. // An attempt to establish a new AP.
AC_DBG("Request for %s\n", (const char*)_credential.ssid); AC_DBG("Request for %s\n", reinterpret_cast<const char*>(_credential.ssid));
WiFi.begin((const char*)_credential.ssid, (const char*)_credential.password, _apConfig.channel); WiFi.begin(reinterpret_cast<const char*>(_credential.ssid), reinterpret_cast<const char*>(_credential.password), _apConfig.channel);
if (_waitForConnect(_portalTimeout) == WL_CONNECTED) { if (_waitForConnect(_portalTimeout) == WL_CONNECTED) {
if (WiFi.BSSID() != NULL) { if (WiFi.BSSID() != NULL) {
memcpy(_credential.bssid, WiFi.BSSID(), sizeof(station_config::bssid)); memcpy(_credential.bssid, WiFi.BSSID(), sizeof(station_config::bssid));
@ -400,19 +400,19 @@ void AutoConnect::handleRequest() {
if (_apConfig.autoSave == AC_SAVECREDENTIAL_AUTO) { if (_apConfig.autoSave == AC_SAVECREDENTIAL_AUTO) {
AutoConnectCredential credit(_apConfig.boundaryOffset); AutoConnectCredential credit(_apConfig.boundaryOffset);
credit.save(&_credential); credit.save(&_credential);
AC_DBG("%s credential saved\n", _credential.ssid); AC_DBG("%s credential saved\n", reinterpret_cast<const char*>(_credential.ssid));
} }
} }
else else
AC_DBG("%s has no BSSID, saving is unavailable\n", _credential.ssid); AC_DBG("%s has no BSSID, saving is unavailable\n", reinterpret_cast<const char*>(_credential.ssid));
} }
else { else {
_currentHostIP = WiFi.softAPIP(); _currentHostIP = WiFi.softAPIP();
_redirectURI = String(AUTOCONNECT_URI_FAIL); _redirectURI = String(AUTOCONNECT_URI_FAIL);
_rsConnect = WiFi.status(); _rsConnect = WiFi.status();
WiFi.disconnect(); _disconnectWiFi(false);
while (WiFi.status() != WL_IDLE_STATUS) { while (WiFi.status() != WL_IDLE_STATUS) {
delay(100); delay(10);
yield(); yield();
} }
} }
@ -433,7 +433,7 @@ void AutoConnect::handleRequest() {
_stopPortal(); _stopPortal();
_disconnectWiFi(false); _disconnectWiFi(false);
while (WiFi.status() == WL_CONNECTED) { while (WiFi.status() == WL_CONNECTED) {
delay(100); delay(10);
yield(); yield();
} }
AC_DBG("Disconnected\n"); AC_DBG("Disconnected\n");
@ -651,9 +651,9 @@ String AutoConnect::_invokeResult(PageArgument& args) {
* a part of the handling of http request originated from handleClient. * a part of the handling of http request originated from handleClient.
*/ */
bool AutoConnect::_classifyHandle(HTTPMethod method, String uri) { bool AutoConnect::_classifyHandle(HTTPMethod method, String uri) {
AC_DBG("Host:%s, URI:%s\n", _webServer->hostHeader().c_str(), uri.c_str()); AC_DBG("Host:%s, URI:%s", _webServer->hostHeader().c_str(), uri.c_str());
if (uri == _uri) { if (uri == _uri) {
AC_DBG("%s already allocated\n", _uri.c_str()); AC_DBG_DUMB(", already allocated\n", _uri.c_str());
return true; // The response page already exists. return true; // The response page already exists.
} }
@ -661,22 +661,21 @@ bool AutoConnect::_classifyHandle(HTTPMethod method, String uri) {
_responsePage->clearElement(); _responsePage->clearElement();
if (_currentPageElement != nullptr) if (_currentPageElement != nullptr)
delete _currentPageElement; delete _currentPageElement;
_uri = String(); _uri = String("");
// Create the page dynamically // Create the page dynamically
if ((_currentPageElement = _setupPage(uri)) != nullptr) { if ((_currentPageElement = _setupPage(uri)) == nullptr)
_uri = String(uri); if (_aux) {
_responsePage->addElement(*_currentPageElement);
} else if (_aux) {
// Requested URL is not a normal page, exploring AUX pages // Requested URL is not a normal page, exploring AUX pages
if ((_currentPageElement = _aux->_setupPage(uri)) != nullptr) { _currentPageElement = _aux->_setupPage(uri);
_uri = String(uri);
_responsePage->addElement(*_currentPageElement);
}
} }
if (_currentPageElement != nullptr) {
AC_DBG_DUMB(", generated:%s", uri.c_str());
_uri = uri;
_responsePage->addElement(*_currentPageElement);
_responsePage->setUri(_uri.c_str()); _responsePage->setUri(_uri.c_str());
AC_DBG("Page[%s] allocated\n", _responsePage->uri()); }
AC_DBG_DUMB(", %s\n", _currentPageElement != nullptr ? "allocated" : "ignored");
return _currentPageElement != nullptr ? true : false; return _currentPageElement != nullptr ? true : false;
} }

@ -18,6 +18,7 @@
#define AC_DEBUG_PORT Serial #define AC_DEBUG_PORT Serial
#endif // !AC_DEBUG_PORT #endif // !AC_DEBUG_PORT
#ifdef AC_DEBUG #ifdef AC_DEBUG
#define AC_DBG_DUMB(...) do {AC_DEBUG_PORT.printf( __VA_ARGS__ );} while (0)
#define AC_DBG(...) do {AC_DEBUG_PORT.print("[AC] "); AC_DEBUG_PORT.printf( __VA_ARGS__ );} while (0) #define AC_DBG(...) do {AC_DEBUG_PORT.print("[AC] "); AC_DEBUG_PORT.printf( __VA_ARGS__ );} while (0)
#else #else
#define AC_DBG(...) #define AC_DBG(...)

@ -831,7 +831,7 @@ String AutoConnect::_token_MENU_PRE(PageArgument& args) {
} }
String AutoConnect::_token_MENU_AUX(PageArgument& args) { String AutoConnect::_token_MENU_AUX(PageArgument& args) {
String menuItem; String menuItem = "";
if (_aux) if (_aux)
menuItem = _aux->_injectMenu(args); menuItem = _aux->_injectMenu(args);
return menuItem; return menuItem;

Loading…
Cancel
Save