diff --git a/README.md b/README.md index 8a40a1b..1487d20 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,10 @@ AutoConnect can be embedded easily into your sketch, just "**begin**" and "**han The sketches which provide the web page using ESP8266WebServer/WebServer there is, AutoConnect will not disturb it. AutoConnect can use an already instantiated ESP8266WebServer object(ESP8266) or WebServer object(ESP32), or itself can assign it. +### Adding the user-owned web screen can easily + +You can easily add your own web screen with sketch. It can be called from the AutoConnect menu and parameters can be passed. + ## Supported hardware Apply the [Arduino core](https://github.com/esp8266/Arduino) of the ESP8266 Community. @@ -81,7 +85,11 @@ Full documentation is available on https://Hieromon.github.io/AutoConnect, some ## Change log -### [0.9.6] Sep. 27, 2018 +### [0.9.7] Nov. 11, 2018 +- Supports addition of AutoConnect menu with user sketch by AutoConnectAux implementation. +- Supports AutoConnectConfig::immediateStart option, to start the portal immediately without first trying WiFi.begin. + +### [0.9.6] Sept. 27, 2018 - Improvement of RSSI detection for saved SSIDs. - Fixed disconnection SoftAP completely at the first connection phase of the AutoConnect::begin. diff --git a/keywords.txt b/keywords.txt index 541bddb..3f12cc4 100644 --- a/keywords.txt +++ b/keywords.txt @@ -9,10 +9,15 @@ AutoConnectText KEYWORD1 AutoConnectInput KEYWORD1 AutoConnectButon KEYWORD1 AutoConnectSubmit KEYWORD1 +ACText KEYWORD1 +ACInput KEYWORD1 +ACButton KEYWORD1 +ACSubmit KEYWORD1 ####################################### # Methods and Functions (KEYWORD2) ####################################### +add KEYWORD2 config KEYWORD2 begin KEYWORD2 del KEYWORD2 @@ -24,9 +29,12 @@ home KEYWORD2 host KEYWORD2 join KEYWORD2 load KEYWORD2 +name KEYWORD2 +on KEYWORD2 onDetect KEYWORD2 onNotFound KEYWORD2 save KEYWORD2 +value KEYWORD2 ####################################### # Literals (KEYWORD3) diff --git a/src/AutoConnect.cpp b/src/AutoConnect.cpp index 5c46d14..3c90d48 100644 --- a/src/AutoConnect.cpp +++ b/src/AutoConnect.cpp @@ -111,13 +111,23 @@ bool AutoConnect::begin(const char* ssid, const char* passphrase, unsigned long AC_DBG("DHCP client(%s)\n", wifi_station_dhcpc_status() == DHCP_STOPPED ? "STOPPED" : "STARTED"); #endif - // Try to connect by STA immediately. - if (ssid == nullptr && passphrase == nullptr) - WiFi.begin(); - else - WiFi.begin(ssid, passphrase); - AC_DBG("WiFi.begin(%s%s%s)\n", ssid == nullptr ? "" : ssid, passphrase == nullptr ? "" : ",", passphrase == nullptr ? "" : passphrase); - cs = _waitForConnect(_portalTimeout) == WL_CONNECTED; + // If the portal is requested promptly skip the first WiFi.begin and + // immediately start the portal. + if (_apConfig.immediateStart) { + cs = false; + _apConfig.autoReconnect = false; + _apConfig.autoRise = true; + AC_DBG("Start the portal immediately\n"); + } + else { + // Try to connect by STA immediately. + if (ssid == nullptr && passphrase == nullptr) + WiFi.begin(); + else + WiFi.begin(ssid, passphrase); + AC_DBG("WiFi.begin(%s%s%s)\n", ssid == nullptr ? "" : ssid, passphrase == nullptr ? "" : ",", passphrase == nullptr ? "" : passphrase); + cs = _waitForConnect(_portalTimeout) == WL_CONNECTED; + } // Reconnect with a valid credential as the autoReconnect option is enabled. if (!cs && _apConfig.autoReconnect && (ssid == nullptr && passphrase == nullptr)) { @@ -264,14 +274,12 @@ WebServerClass& AutoConnect::host() { * the auxiliary page to be added. */ void AutoConnect::join(AutoConnectAux& aux) { - if (_aux) { - AutoConnectAux* addon = _aux.get(); - addon->_append(aux); - } + aux._join(*this); + AC_DBG("%s on hands\n", aux.uri()); + if (_aux) + _aux->_concat(aux); else _aux.reset(&aux); - aux._join(*this); - AC_DBG("%s contained\n", aux._uri); } /** diff --git a/src/AutoConnect.h b/src/AutoConnect.h index 1ba4b9f..05030ec 100644 --- a/src/AutoConnect.h +++ b/src/AutoConnect.h @@ -132,6 +132,7 @@ class AutoConnectConfig { autoRise(true), autoReset(true), autoReconnect(false), + immediateStart(false), homeUri(AUTOCONNECT_HOMEURI), staip(0U), staGateway(0U), @@ -155,6 +156,7 @@ class AutoConnectConfig { autoRise(true), autoReset(true), autoReconnect(false), + immediateStart(false), homeUri(AUTOCONNECT_HOMEURI), staip(0U), staGateway(0U), @@ -178,6 +180,7 @@ class AutoConnectConfig { autoRise = o.autoRise; autoReset = o.autoReset; autoReconnect = o.autoReconnect; + immediateStart = o.immediateStart; homeUri = o.homeUri; staip = o.staip; staGateway = o.staGateway; @@ -200,6 +203,7 @@ class AutoConnectConfig { bool autoRise; /**< Automatic starting the captive portal */ bool autoReset; /**< Reset ESP8266 module automatically when WLAN disconnected. */ bool autoReconnect; /**< Automatic reconnect with past SSID */ + bool immediateStart; /**< Skips WiFi.begin(), start portal immediately */ String homeUri; /**< A URI of user site */ IPAddress staip; /**< Station static IP address */ IPAddress staGateway; /**< Station gateway address */ @@ -208,8 +212,6 @@ class AutoConnectConfig { IPAddress dns2; /**< Secondary DNS server */ }; -class AutoConnectAux; - class AutoConnect { public: AutoConnect(); diff --git a/src/AutoConnectAux.cpp b/src/AutoConnectAux.cpp index 857a35a..4288a2a 100644 --- a/src/AutoConnectAux.cpp +++ b/src/AutoConnectAux.cpp @@ -10,7 +10,20 @@ #include "AutoConnect.h" #include "AutoConnectAux.h" +/** + * Template for auxiliary page composed with AutoConnectAux of user sketch. + * + * The structure of the auxiliary page depends on this template for + * the purpose to be incorporated into the AutoConnect Menu. + * The page element implemented by AutoConnectElement is placed at the + * position of {{AUX_ELEMENT}} token. This token is contained in a + *
block with a class defined in 'base-panel' and is held by a + *
element with an ID '_aux'. + * The JavaScript that named 'sa' at the end of the template determines + * the behavior of AutoConnectSubmit. + */ const char AutoConnectAux::_PAGE_AUX[] PROGMEM = { + "{{EXIT_HANDLE}}" "{{HEAD}}" "{{AUX_TITLE}}" "