\n\n\n\n\n\nDefine macros\n\u00b6\n\n\n#define AC_DEBUG \n// Monitor message output activation\n\n\n#define AC_DEBUG_PORT Serial \n// Default message output device\n\n\n#define AUTOCONNECT_AP_IP 0x01F4A8C0 \n// Default SoftAP IP\n\n\n#define AUTOCONNECT_AP_GW 0x01F4A8C0 \n// Default SoftAP Gateway IP\n\n\n#define AUTOCONNECT_AP_NM 0x00FFFFFF \n// Default subnet mask\n\n\n#define AUTOCONNECT_DNSPORT 53 \n// Default DNS port at captive portal\n\n\n#define AUTOCONNECT_MENU_TITLE \"AutoConnect\" \n// Default AutoConnect menu title\n\n\n#define AUTOCONNECT_STARTUPTIME 10 \n// Default waiting time[s] for after reset\n\n\n#define AUTOCONNECT_URI \"/_ac\" \n// Default AutoConnect root path\n\n\n#define AUTOCONNECT_TIMEOUT 30000 \n// Default connection timeout[ms]\n\n\n\n\n\nAutoConnect API\n\u00b6\n\n\n Constructors\n\u00b6\n\n\nAutoConnect\n\u00b6\n\n\nAutoConnect\n()\n\n\n\n\n\nAutoConnect default constructor. This entry activates WebServer internally and the web server is allocated internal.\n\n\nAutoConnect\n(\nESP8266WebServer\n&\n \nwebServer\n)\n\n\n\n\n\nRun the AutoConnect site using the externally ensured ESP 8266 WebServer. User's added URI handler response can be included in handleClient method.\n\n\n \nParameters\n\n \nwebServer\nA reference of ESP8266WebServer instance.\n\n\n\n\n Public member functions\n\u00b6\n\n\nbegin\n\u00b6\n\n\nbool\n \nbegin\n()\n\n\n\n\nbool\n \nbegin\n(\nconst\n \nchar\n*\n \nssid\n,\n \nconst\n \nchar\n*\n \npassphraase\n)\n\n\n\n\nbool\n \nbegin\n(\nconst\n \nchar\n*\n \nssid\n,\n \nconst\n \nchar\n*\n \npassphraase\n,\n \nunsinged\n \nlong\n \ntimeout\n)\n\n\n\n\nStarts establishing WiFi connection. Before establishing, start the Web server and DNS server for the captive portal. Then begins connection establishment in WIFI_STA mode. If connection can not established with the specified SSID and password, switch to WIFI_AP_STA mode and activate SoftAP.\n\n\n \nParameters\n\n \nssid\nSSID to be connected.\n\n \npassphrase\nPassword for connection.\n\n \ntimeout\nA time out value in milliseconds for waiting connection.\n\n \nReturn value\n\n \ntrue\nConnection established, AutoConnect service started with WIFI_STA mode.\n\n \nfalse\nCould not connected, Captive portal started with WIFI_AP_STA mode.\n\n\n\n\nconfig\n\u00b6\n\n\nbool\n \nconfig\n(\nAutoConnectConfig\n&\n \nconfig\n)\n\n\n\n\nbool\n \nconfig\n(\nconst\n \nchar\n*\n \nap\n,\n \nconst\n \nchar\n*\n \npassword\n \n=\n \nnullptr\n)\n\n\n\n\nSets SoftAP's WiFi configuration. \n\n\n \nParameters\n\n \nconfig\nReference to AutoConnectConfig containing SoftAP's parameters.\n\n \nap\nSSID for SoftAP. The default value is \nesp8266ap\n.\n\n \npassword\nPassword for SodtAP. The default value is \n12345678\n.\n\n \nReturn value\n\n \ntrue\nSuccessfully configured.\n\n \nfalse\nConfiguration parameter is invalid, some values out of range.\n\n\n\n\nend\n\u00b6\n\n\nvoid\n \nend\n()\n\n\n\n\n\nStops AutoConnect captive portal service. Release ESP8266WebServer and DNSServer. \n\n\n\n\nAttention to end\n\n\nThe end function releases the instance of ESP8266WebServer and DNSServer. It can not process them after the end function.\n\n\n\n\nhandleClient\n\u00b6\n\n\nvoid\n \nhandleClient\n()\n\n\n\n\n\nHandling for the AutoConnect web interface. Invoke the handleClient of the parent web server to process client request of the AutoConnect WEB interface. No effects when the web server is not available.\n\n\nhandleRequest\n\u00b6\n\n\nvoid\n \nhandleRequest\n()\n\n\n\n\n\nHandling for the AutoConnect menu request.\n\n\n\n\nAbout used in combination with handleClient\n\n\nThe handleRequest function is not supposed to use with AutoConnect::handleClient. It should be used with ESP8266::handleClient.\n\n\n\n\nhome\n\u00b6\n\n\nvoid\n \nhome\n(\nString\n \nuri\n)\n\n\n\n\n\nPut a user site's home URI. The URI specified by home is linked from \"HOME\" in the AutoConnect portal menu.\n\n\n \nParameters\n\n \nuri\n A URI string of user site's home path.\n\n\n\n\nhost\n\u00b6\n\n\nReturns the reference of the ESP8266WebServer which is allocated in AutoConnect automatically.\n\n\nESP8266WebServer\n&\n \nhost\n()\n\n\n\n\n\n \nReturn value\n\n \nA reference of the ESP8266WebServer.\n\n\n\n\n\n\n&reference is not a pointer\n\n\nA reference cannot be re-assigned, and must be assigned at initialization. It's like as bind as alias. \n\n\nESP8266WebServer\n&\n \nserver\n \n=\n \nportal\n.\nhost\n();\n\n\nserver\n.\nhandleClient\n();\n\n\n\nor\n\n\nportal\n.\nhost\n().\nhandleClient\n();\n\n\n\n\n\n\nonDetect\n\u00b6\n\n\nvoid\n \nonDetect\n(\nDetectExit_ft\n \nfn\n)\n\n\n\nRegister the function which will call from AutoConnect at the start of the captive portal.\n\n\n \nParameters\n\n \nfn\nFunction called at the captive portal start.\n\n\n\n\n\nAn \nfn\n specifies the function called when the captive portal starts. Its prototype declaration is defined as \"\nDetectFunc_ft\n\".\n\n\ntypedef\n \nstd\n::\nfunction\n<\nbool\n(\nIPAddress\n \nsoftapIP\n)\n>\n \nDetectExit_ft\n\n\n\n\n\n \nParameters\n\n \nsoftapIP\nAn IP address of SoftAP for the captive portal.\n\n \nRetuen value\n\n \ntrue\nContinues captive portal handling.\n\n \nfalse\nCancel the captive portal. AutoConnect::begin function will return with a false.\n\n\n\n\nonNotFound\n\u00b6\n\n\nvoid\n \nonNotFound\n(\nESP8266WebServer\n::\nTHandlerFunction\n \nfn\n)\n\n\n\nRegister the handler function for undefined URL request detected.\n\n\n \nParameters\n\n \nfn\nA function of the \"not found\" handler.\n\n\n\n\nAutoConnectConfig API\n\u00b6\n\n\n Constructor\n\u00b6\n\n\nAutoConnectConfig\n\u00b6\n\n\nAutoConnectConfig\n();\n\n\n\n\nAutoConnectConfig\n(\nconst\n \nchar\n*\n \nap\n,\n \nconst\n \nchar\n*\n \npassword\n);\n\n\n\n\n\n \nParameters\n\n \nap\nSSID for SoftAP. The length should be up to 31. The default value is \nesp8266ap\n.\n\n \npassword\nPassword for SodtAP. The length should be from 8 to up to 63. The default value is \n12345678\n.\n\n\n\n\n Public member variables\n\u00b6\n\n\napid\n\u00b6\n\n\nSoftAP's SSID.\n\n\n \nType\n\n \nString\n\n\n\n\napip\n\u00b6\n\n\nSets IP address for Soft AP in captive portal. When AutoConnect fails the initial WiFi.begin, it starts the captive portal with the IP address specified this.\n\n\n \nType\n\n \nIPAddress\n\n\n\n\nautoReset\n\u00b6\n\n\nReset ESP8266 module automatically when WLAN disconnected.\n\n\n \nType\n\n \nbool\n\n \nValue\n\n \ntrue\nReset after WiFi disconnected automatically.\n\n \nfalse\nNo reset.\n\n\n\n\nautoRise\n\u00b6\n\n\nCaptive portal activation switch. False for disabling the captive portal. It prevents starting the captive portal even if the connection at the first \nWiFi.begin\n fails.\n\n\n \nType\n\n \nbool\n\n \nValue\n\n \ntrue\nEnable the captive portal. This is a default.\n\n \nfalse\nDisable the captive portal.\n\n\n\n\nautoSave\n\u00b6\n\n\nThe credential saved automatically at the connection establishment.\n\n\n \nType\n\n \nAC_SAVECREDENTIAL_t\n\n \nValue\n\n \nAC_SAVECREDENTIAL_AUTO\nThe credential saved automatically.\n\n \nAC_SAVECREDENTIAL_NEVER\nThe credential no saved.\n\n\n\n\nchannel\n\u00b6\n\n\nThe channel number of WIFi when SoftAP starts.\n\n\n \nType\n\n \nuint8_t\n\n \nValue\n\n \n1 ~ 14. The default value is 1.\n\n\n\n\n\n\nSee Application note\n\n\nEspressif Systems had announced the \napplication note\n about Wi-Fi channel selection.\n\n\n\n\ngateway\n\u00b6\n\n\nSets gateway address for Soft AP in captive portal. When AutoConnect fails the initial WiFi.begin, it starts the captive portal with the IP address specified this.\n\n\n \nType\n\n \nIPAddress\n\n\n\n\nhidden\n\u00b6\n\n\nSets SoftAP to hidden SSID.\n\n\n \nType\n\n \nuint8_t\n\n \nValue\n\n \n0\nSSID will be appeared. This is the default.\n\n \n1\nSSID will be hidden.\n\n\n\n\nhomeUri\n\u00b6\n\n\nSets the home path of user sketch. This path would be linked from 'HOME' in the AutoConnect menu.\n\n\n \nType\n\n \nString\n\n\n\n\nnetmask\n\u00b6\n\n\nSets subnet mask for Soft AP in captive portal. When AutoConnect fails the initial WiFi.begin, it starts the captive portal with the IP address specified this.\n\n\n \nType\n\n \nIPAddress\n\n\n\n\npsk\n\u00b6\n\n\nSets password for SoftAP. The length should be from 8 to up to 63. The default value is \n12345678\n.\n\n\n \nType\n\n \nString\n\n\n\n\n AutoConnectConfig example\n\u00b6\n\n\nAutoConenct\n \nPortal\n;\n\n\nAutoConenctConfig\n \nConfig\n(\n\"\"\n,\n \n\"passpass\"\n);\n \n// SoftAp name is determined at runtime\n\n\nConfig\n.\napid\n \n=\n \nESP\n.\nhostname\n();\n \n// Retrieve host name to SotAp identification\n\n\nConfig\n.\napip\n \n=\n \nIPAddress\n(\n192\n,\n168\n,\n10\n,\n101\n);\n \n// Sets SoftAP IP address\n\n\nConfig\n.\ngateway\n \n=\n \nIPAddress\n(\n192\n,\n168\n,\n10\n,\n1\n);\n \n// Sets WLAN router IP address\n\n\nConfig\n.\nnetmask\n \n=\n \nIPAddress\n(\n255\n,\n255\n,\n255\n,\n0\n);\n \n// Sets WLAN scope\n\n\nConfig\n.\nautoSave\n \n=\n \nAC_SAVECREDENTIAL_NEVER\n;\n \n// No save credential\n\n\nConfig\n.\nhomeUri\n \n=\n \n\"/index.html\"\n \n// Sets home path of the sketch application\n\n\nPortal\n.\nconfig\n(\nConfig\n);\n \n// Configure AutoConnect\n\n\nPortal\n.\nbegin\n();\n \n// Starts and behaves captive portal\n\n\n\n\n\n Something extra\n\u00b6\n\n\nThe library presents two PNG icons which can be used to embed a hyperlink to the AutoConnect menu.\n\n\n\n\nBar type \n\n\nCog type \n\n\n\n\nTo reference the icon, use the \nAUTOCONNECT_LINK\n macro in the sketch. It expands into the string literal as an HTML \n\n tag with PNG embedded of the AutoConnect menu hyperlinks. Icon type is specified by the parameter of the macro.\n\n\n\n \nBAR_32\nBars icon, 32x32.\n\n \nBAR_48\nBars icon, 48x48.\n\n \nCOG_24\nCog icon, 24x24.\n\n \nCOG_32\nCog icon, 32x32.\n\n\n\n\n\n\n\nUsage\n\n\nString\n \nhtml\n \n=\n \n\"\"\n;\n\n\nhtml\n \n+=\n \nAUTOCONNECT_LINK\n(\nBAR_32\n);\n\n\nhtml\n \n+=\n \n\"\"\n;\n\n\nserver\n.\nsend\n(\n200\n,\n \n\"text/html\"\n,\n \nhtml\n);",
"title": "Library APIs"
},
{
@@ -277,7 +282,7 @@
},
{
"location": "/api/index.html#define-macros",
- "text": "#define AC_DEBUG // Monitor message output activation #define AC_DEBUG_PORT Serial // Default message output device #define AUTOCONNECT_AP_IP 0x01F4A8C0 // Default SoftAP IP #define AUTOCONNECT_AP_GW 0x01F4A8C0 // Default SoftAP Gateway IP #define AUTOCONNECT_AP_NM 0x00FFFFFF // Default subnet mask #define AUTOCONNECT_DNSPORT 53 // Default DNS port at captive portal #define AUTOCONNECT_MENU_TITLE \"AutoConnect\" // Default AutoConnect menu title #define AUTOCONNECT_URI \"/_ac\" // Default AutoConnect root path",
+ "text": "#define AC_DEBUG // Monitor message output activation #define AC_DEBUG_PORT Serial // Default message output device #define AUTOCONNECT_AP_IP 0x01F4A8C0 // Default SoftAP IP #define AUTOCONNECT_AP_GW 0x01F4A8C0 // Default SoftAP Gateway IP #define AUTOCONNECT_AP_NM 0x00FFFFFF // Default subnet mask #define AUTOCONNECT_DNSPORT 53 // Default DNS port at captive portal #define AUTOCONNECT_MENU_TITLE \"AutoConnect\" // Default AutoConnect menu title #define AUTOCONNECT_STARTUPTIME 10 // Default waiting time[s] for after reset #define AUTOCONNECT_URI \"/_ac\" // Default AutoConnect root path #define AUTOCONNECT_TIMEOUT 30000 // Default connection timeout[ms]",
"title": "Define macros"
},
{
@@ -380,6 +385,11 @@
"text": "Reset ESP8266 module automatically when WLAN disconnected. \n Type \n bool \n Value \n true Reset after WiFi disconnected automatically. \n false No reset.",
"title": "autoReset"
},
+ {
+ "location": "/api/index.html#autorise",
+ "text": "Captive portal activation switch. False for disabling the captive portal. It prevents starting the captive portal even if the connection at the first WiFi.begin fails. \n Type \n bool \n Value \n true Enable the captive portal. This is a default. \n false Disable the captive portal.",
+ "title": "autoRise"
+ },
{
"location": "/api/index.html#autosave",
"text": "The credential saved automatically at the connection establishment. \n Type \n AC_SAVECREDENTIAL_t \n Value \n AC_SAVECREDENTIAL_AUTO The credential saved automatically. \n AC_SAVECREDENTIAL_NEVER The credential no saved.",
diff --git a/docs/usage/index.html b/docs/usage/index.html
index 765fd8f..79edd72 100644
--- a/docs/usage/index.html
+++ b/docs/usage/index.html
@@ -451,6 +451,13 @@
404 handler
+
+
+
+
+ Auto save Credential
+
+
@@ -468,15 +475,15 @@
-
- Credential data
+
+ Debug print
-
- Debug print
+
+ Disable the captive portal
@@ -733,6 +740,13 @@
404 handler
+
+
+
+
+ Auto save Credential
+
+
@@ -750,15 +764,15 @@
-
- Credential data
+
+ Debug print
-
- Debug print
+
+ Disable the captive portal
@@ -846,12 +860,15 @@
Embed to the sketches
How embed the AutoConnect to the sketches you have. Most simple approach to applying AutoConnect for the existing sketches, follow the below steps.
- Insert #include <AutoConnect.h>
to behind of #include <ESP8266WebServer.h>
.
- Insert AutoConnect
PORTAL(WEBSERVER);
to behind of ESP8266WebServer
WEBSERVER;
declaration.
- Remove WiFi.begin(
SSID
,
PSK
)
and the subsequent logic for the connection status check.
- Replace WEBSERVER
.begin()
to PORTAL
.begin()
.
- Replace WEBSERVER
.handleClient()
to PORTAL
.handleClient()
.
- If the connection successful logic is needed, you can check the return value as true
or false
of PORTAL
.begin()
.
+
+ - Insert
#include <AutoConnect.h>
to behind of #include <ESP8266WebServer.h>
.
+ - Insert
AutoConnect PORTAL(WEBSERVER);
to behind of ESP8266WebServer WEBSERVER;
declaration.
+ - Remove
WiFi.begin(SSID,PSK)
and the subsequent logic for the connection status check.
+ - Replace
WEBSERVER.begin()
to PORTAL.begin()
.
+ - Replace
WEBSERVER.handleClient()
to PORTAL.handleClient()
.
+ - If the connection checks logic is needed, you can check the return value according to
PORTAL.begin()
with true
or false
.
+
+
Basic usage
Basic logic sequence for the user sketches
1. A typical logic sequence
@@ -945,6 +962,15 @@ or
Advanced usage
404 handler
Registering the "not found" handler is a different way than ESP8266. The onNotFound of ESP8266WebServer does not work with AutoConnect. AutoConnect overrides ESP8266WebServer::onNotFound to handle a captive portal. To register "not found" handler, use AutoConnect::onNotFound.
+ Auto save Credential
+By default, AutoConnect saves the credentials of the established connection in EEPROM. You can disable it with the autoSave parameter specified by AutoConnect::config.
+AutoConnect Portal;
+AutoConnectConfig Config;
+Config.autoSave = AC_SAVECREDENTIAL_NEVER;
+Portal.config(Config);
+Portal.begin();
+
+
Captive portal start detection
The captive portal will only be activated if the first WiFi::begin fails. Sketch can detect with the onDetect funciton that the captive portal has started. For example, the sketch can be written like as follows that turns on the LED at the start captive portal.
AutoConnect Portal;
@@ -990,15 +1016,6 @@ or
}
- Credential data
-By default, AutoConnect saves the credentials of the established connection in EEPROM. You can disable it with the autoSave parameter specified by AutoConnect::config.
-AutoConnect Portal;
-AutoConnectConfig Config;
-Config.autoSave = AC_SAVECREDENTIAL_NEVER;
-Portal.config(Config);
-Portal.begin();
-
-
AutoConnect::config before AutoConnect::begin
AutoConnect::config must be executed before AutoConnect::begin.
@@ -1008,6 +1025,17 @@ or
+
Disable the captive portal
+
It can also prevent the captive portal from starting even if the connection at the first WiFi.begin fails. In this case, the behavior of AutoConnect::begin is the same as WiFi.begin.
+
For disabling the captive portal, autoRise sets to false with AutoConnectConfig.
+
AutoConnect portal;
+AutoConnectConfig acConfig;
+
+acConfig.autoRaise = false;
+portal.config(acConfig);
+portal.begin();
+
+
Refers the hosted ESP8266WebServer
Constructing an AutoConnect object variable without parameters then creates and starts an ESP8266WebServer inside the AutoConnect. This object variable could be referred by AutoConnect::host() function to access ESP8266WebServer instance as like below.
AutoConnect Portal;
diff --git a/mkdocs/api.md b/mkdocs/api.md
index 28873b9..6155fba 100644
--- a/mkdocs/api.md
+++ b/mkdocs/api.md
@@ -16,7 +16,9 @@
#define AUTOCONNECT_AP_NM 0x00FFFFFF // Default subnet mask
#define AUTOCONNECT_DNSPORT 53 // Default DNS port at captive portal
#define AUTOCONNECT_MENU_TITLE "AutoConnect" // Default AutoConnect menu title
+#define AUTOCONNECT_STARTUPTIME 10 // Default waiting time[s] for after reset
#define AUTOCONNECT_URI "/_ac" // Default AutoConnect root path
+#define AUTOCONNECT_TIMEOUT 30000 // Default connection timeout[ms]
```
## AutoConnect API
@@ -233,6 +235,17 @@ Reset ESP8266 module automatically when WLAN disconnected.
falseNo reset.
+#### autoRise
+
+Captive portal activation switch. False for disabling the captive portal. It prevents starting the captive portal even if the connection at the first *WiFi.begin* fails.
+
+ - **Type**
+ - bool
+ - **Value**
+ - trueEnable the captive portal. This is a default.
+ - falseDisable the captive portal.
+
+
#### autoSave
The credential saved automatically at the connection establishment.
diff --git a/mkdocs/css/paragraph.css b/mkdocs/css/paragraph.css
index 130e8df..0f8f66a 100644
--- a/mkdocs/css/paragraph.css
+++ b/mkdocs/css/paragraph.css
@@ -35,4 +35,10 @@
.apidl {
margin-left: 20px;
+}
+
+.ulsty-edit > li:before {
+ font-family: 'FontAwesome';
+ content: '\f044';
+ margin:0 0.8em 0 -1.8em;
}
\ No newline at end of file
diff --git a/mkdocs/usage.md b/mkdocs/usage.md
index 1c2bdd6..3fd694e 100644
--- a/mkdocs/usage.md
+++ b/mkdocs/usage.md
@@ -6,12 +6,14 @@ How embed the AutoConnect to the sketches you have. Most simple approach to appl
-
Insert `#include
` to behind of `#include `.
- Insert `AutoConnect`*`PORTAL(WEBSERVER);`* to behind of `ESP8266WebServer`*`WEBSERVER;`* declaration.[^1]
- Remove `WiFi.begin(`*`SSID`*`,`*`PSK`*`)` and the subsequent logic for the connection status check.
- Replace *`WEBSERVER`*`.begin()` to *`PORTAL`*`.begin()`.[^2]
- Replace *`WEBSERVER`*`.handleClient()` to *`PORTAL`*`.handleClient()`.[^3]
- If the connection successful logic is needed, you can check the return value as `true` or `false` of *`PORTAL`*`.begin()`.
+
+ - Insert
#include <AutoConnect.h>
to behind of #include <ESP8266WebServer.h>
.
+ - Insert
AutoConnect PORTAL(WEBSERVER);
to behind of ESP8266WebServer WEBSERVER;
declaration.
+ - Remove
WiFi.begin(SSID,PSK)
and the subsequent logic for the connection status check.
+ - Replace
WEBSERVER.begin()
to PORTAL.begin()
.
+ - Replace
WEBSERVER.handleClient()
to PORTAL.handleClient()
.
+ - If the connection checks logic is needed, you can check the return value according to
PORTAL.begin()
with true
or false
.
+
[^1]:
Each *VARIABLE* conforms to the actual declaration in the sketches.
@@ -108,6 +110,18 @@ Reference to ESP8266WebServer | AutoConnect menu not available.
host() not ne
Registering the "not found" handler is a different way than ESP8266. The *onNotFound* of ESP8266WebServer does not work with AutoConnect. AutoConnect overrides *ESP8266WebServer::onNotFound* to handle a captive portal. To register "not found" handler, use [*AutoConnect::onNotFound*](api.md#onnotfound).
+### Auto save Credential
+
+By default, AutoConnect saves the credentials of the established connection in EEPROM. You can disable it with the **autoSave** parameter specified by [*AutoConnect::config*](api.md#config).
+
+```arduino hl_lines="3"
+AutoConnect Portal;
+AutoConnectConfig Config;
+Config.autoSave = AC_SAVECREDENTIAL_NEVER;
+Portal.config(Config);
+Portal.begin();
+```
+
### Captive portal start detection
The captive portal will only be activated if the first *WiFi::begin* fails. Sketch can detect with the [*onDetect*](api.md#ondetect) funciton that the captive portal has started. For example, the sketch can be written like as follows that turns on the LED at the start captive portal.
@@ -159,18 +173,6 @@ void loop() {
}
```
-### Credential data
-
-By default, AutoConnect saves the credentials of the established connection in EEPROM. You can disable it with the **autoSave** parameter specified by [*AutoConnect::config*](api.md#config).
-
-```arduino hl_lines="3"
-AutoConnect Portal;
-AutoConnectConfig Config;
-Config.autoSave = AC_SAVECREDENTIAL_NEVER;
-Portal.config(Config);
-Portal.begin();
-```
-
!!! note "AutoConnect::config before AutoConnect::begin"
*AutoConnect::config* must be executed before *AutoConnect::begin*.
@@ -182,6 +184,21 @@ You can output AutoConnect monitor messages to the **Serial**. A monitor message
#define AC_DEBUG
```
+### Disable the captive portal
+
+It can also prevent the captive portal from starting even if the connection at the first *WiFi.begin* fails. In this case, the behavior of *AutoConnect::begin* is the same as *WiFi.begin*.
+
+For disabling the captive portal, **autoRise** sets to false with AutoConnectConfig.
+
+```arduino hl_lines="4"
+AutoConnect portal;
+AutoConnectConfig acConfig;
+
+acConfig.autoRaise = false;
+portal.config(acConfig);
+portal.begin();
+```
+
### Refers the hosted ESP8266WebServer
Constructing an AutoConnect object variable without parameters then creates and starts an ESP8266WebServer inside the AutoConnect. This object variable could be referred by [*AutoConnect::host()*](api.md#host) function to access ESP8266WebServer instance as like below.
diff --git a/src/AutoConnect.cpp b/src/AutoConnect.cpp
index 827b953..77aa666 100644
--- a/src/AutoConnect.cpp
+++ b/src/AutoConnect.cpp
@@ -99,46 +99,53 @@ bool AutoConnect::begin(const char* ssid, const char* passphrase) {
cs = _waitForConnect(_portalTimeout) == WL_CONNECTED;
_currentHostIP = WiFi.localIP();
- // Rushing into the portal.
+ // It doesn't matter the connection status for launching the Web server.
_startWebServer();
+
+ // Rushing into the portal.
if (!cs) {
- // Change WiFi working mode, Enable AP with STA
- WiFi.setAutoConnect(false);
- WiFi.disconnect();
- WiFi.mode(WIFI_AP_STA);
- delay(100);
- // Connection unsuccessful, launch the captive portal.
- if (!(_apConfig.apip == IPAddress(0, 0, 0, 0) || _apConfig.gateway == IPAddress(0, 0, 0, 0) || _apConfig.netmask == IPAddress(0, 0, 0, 0))) {
- _config();
- }
- WiFi.softAP(_apConfig.apid.c_str(), _apConfig.psk.c_str(), _apConfig.channel, _apConfig.hidden);
- while (WiFi.softAPIP() == IPAddress(0, 0, 0, 0))
- yield();
- _currentHostIP = WiFi.softAPIP();
- AC_DBG("SoftAP %s/%s CH(%d) H(%d) IP:%s\n", _apConfig.apid.c_str(), _apConfig.psk.c_str(), _apConfig.channel, _apConfig.hidden, WiFi.softAPIP().toString().c_str());
-
- // Fork to the exit routine that starts captive portal.
- cs = _onDetectExit ? _onDetectExit(_currentHostIP) : true;
-
- // Start captive portal without cancellation by DetectExit.
- if (cs) {
- // Prepare for redirecting captive portal detection.
- // Pass all URL requests to _captivePortal to disguise the captive portal.
- _startDNSServer();
-
- // Start the captive portal to make a new connection
- while (WiFi.status() != WL_CONNECTED && !_rfReset) {
- handleClient();
- // Force execution of queued processes.
- yield();
+ // The captive portal is effective at the autoRise is valid only.
+ if (_apConfig.autoRise) {
+
+ // Change WiFi working mode, Enable AP with STA
+ WiFi.setAutoConnect(false);
+ WiFi.disconnect();
+ WiFi.mode(WIFI_AP_STA);
+ delay(100);
+
+ // Connection unsuccessful, launch the captive portal.
+ if (!(_apConfig.apip == IPAddress(0, 0, 0, 0) || _apConfig.gateway == IPAddress(0, 0, 0, 0) || _apConfig.netmask == IPAddress(0, 0, 0, 0))) {
+ _config();
}
- cs = WiFi.status() == WL_CONNECTED;
+ WiFi.softAP(_apConfig.apid.c_str(), _apConfig.psk.c_str(), _apConfig.channel, _apConfig.hidden);
+ while (WiFi.softAPIP() == IPAddress(0, 0, 0, 0))
+ yield();
+ _currentHostIP = WiFi.softAPIP();
+ AC_DBG("SoftAP %s/%s CH(%d) H(%d) IP:%s\n", _apConfig.apid.c_str(), _apConfig.psk.c_str(), _apConfig.channel, _apConfig.hidden, WiFi.softAPIP().toString().c_str());
- // If WLAN successfully connected, release DNS server.
+ // Fork to the exit routine that starts captive portal.
+ cs = _onDetectExit ? _onDetectExit(_currentHostIP) : true;
+
+ // Start captive portal without cancellation by DetectExit.
if (cs) {
- _dnsServer->stop();
- _dnsServer.reset();
+ // Prepare for redirecting captive portal detection.
+ // Pass all URL requests to _captivePortal to disguise the captive portal.
+ _startDNSServer();
+
+ // Start the captive portal to make a new connection
+ while (WiFi.status() != WL_CONNECTED && !_rfReset) {
+ handleClient();
+ // Force execution of queued processes.
+ yield();
+ }
+ cs = WiFi.status() == WL_CONNECTED;
+
+ // If WLAN successfully connected, release DNS server.
+ if (cs) {
+ _dnsServer->stop();
+ _dnsServer.reset();
+ }
}
}
}
diff --git a/src/AutoConnect.h b/src/AutoConnect.h
index 5f700e4..6d05b5a 100644
--- a/src/AutoConnect.h
+++ b/src/AutoConnect.h
@@ -110,8 +110,9 @@ class AutoConnectConfig {
channel(1),
hidden(0),
autoSave(AC_SAVECREDENTIAL_AUTO),
- autoReset(true),
uptime(AUTOCONNECT_STARTUPTIME),
+ autoRise(true),
+ autoReset(true),
homeUri(AUTOCONNECT_HOMEURI) {}
/**
* Configure by SSID for the captive portal access point and password.
@@ -125,8 +126,9 @@ class AutoConnectConfig {
channel(1),
hidden(0),
autoSave(AC_SAVECREDENTIAL_AUTO),
- autoReset(true),
uptime(AUTOCONNECT_STARTUPTIME),
+ autoRise(true),
+ autoReset(true),
homeUri(AUTOCONNECT_HOMEURI) {}
~AutoConnectConfig() {}
@@ -140,8 +142,9 @@ class AutoConnectConfig {
channel = o.channel;
hidden = o.hidden;
autoSave = o.autoSave;
- autoReset = o.autoReset;
uptime = o.uptime;
+ autoRise = o.autoRise;
+ autoReset = o.autoReset;
homeUri = o.homeUri;
return *this;
}
@@ -154,8 +157,9 @@ class AutoConnectConfig {
uint8_t channel; /**< SoftAP used wifi channel */
uint8_t hidden; /**< SoftAP SSID hidden */
AC_SAVECREDENTIAL_t autoSave; /**< Auto save credential */
- bool autoReset; /**< Reset ESP8266 module automatically when WLAN disconnected. */
int uptime; /**< Length of start up time */
+ bool autoRise; /**< automatic starting the captive portal */
+ bool autoReset; /**< Reset ESP8266 module automatically when WLAN disconnected. */
String homeUri; /**< A URI of user site */
};