Added autoRise with AutoConnectConfig

pull/8/head
Hieromon Ikasamo 6 years ago
parent 9d39ad18e8
commit 5400779bd5
  1. 25
      docs/api/index.html
  2. 6
      docs/css/paragraph.css
  3. 30
      docs/search/search_index.json
  4. 74
      docs/usage/index.html
  5. 13
      mkdocs/api.md
  6. 6
      mkdocs/css/paragraph.css
  7. 53
      mkdocs/usage.md
  8. 75
      src/AutoConnect.cpp
  9. 12
      src/AutoConnect.h

@ -545,6 +545,13 @@
autoReset
</a>
</li>
<li class="md-nav__item">
<a href="#autorise" title="autoRise" class="md-nav__link">
autoRise
</a>
</li>
<li class="md-nav__item">
@ -882,6 +889,13 @@
autoReset
</a>
</li>
<li class="md-nav__item">
<a href="#autorise" title="autoRise" class="md-nav__link">
autoRise
</a>
</li>
<li class="md-nav__item">
@ -989,7 +1003,9 @@
<span class="cp">#define AUTOCONNECT_AP_NM 0x00FFFFFF </span><span class="c1">// Default subnet mask</span>
<span class="cp">#define AUTOCONNECT_DNSPORT 53 </span><span class="c1">// Default DNS port at captive portal</span>
<span class="cp">#define AUTOCONNECT_MENU_TITLE &quot;AutoConnect&quot; </span><span class="c1">// Default AutoConnect menu title</span>
<span class="cp">#define AUTOCONNECT_STARTUPTIME 10 </span><span class="c1">// Default waiting time[s] for after reset</span>
<span class="cp">#define AUTOCONNECT_URI &quot;/_ac&quot; </span><span class="c1">// Default AutoConnect root path</span>
<span class="cp">#define AUTOCONNECT_TIMEOUT 30000 </span><span class="c1">// Default connection timeout[ms]</span>
</pre></div>
<h2 id="autoconnect-api">AutoConnect API<a class="headerlink" href="#autoconnect-api" title="Permanent link">&para;</a></h2>
@ -1151,6 +1167,15 @@ Register the handler function for undefined URL request detected.
<dd><span class="apidef" style="width:230px;">true</span>Reset after WiFi disconnected automatically.</dd>
<dd><span class="apidef" style="width:230px;">false</span>No reset.</dd>
</dl></p>
<h4 id="autorise">autoRise<a class="headerlink" href="#autorise" title="Permanent link">&para;</a></h4>
<p>Captive portal activation switch. False for disabling the captive portal. It prevents starting the captive portal even if the connection at the first <em>WiFi.begin</em> fails.
<dl class="apidl">
<dt><strong>Type</strong></dt>
<dd>bool</dd>
<dt><strong>Value</strong></dt>
<dd><span class="apidef" style="width:230px;">true</span>Enable the captive portal. This is a default.</dd>
<dd><span class="apidef" style="width:230px;">false</span>Disable the captive portal.</dd>
</dl></p>
<h4 id="autosave">autoSave<a class="headerlink" href="#autosave" title="Permanent link">&para;</a></h4>
<p>The credential saved automatically at the connection establishment.
<dl class="apidl">

@ -35,4 +35,10 @@
.apidl {
margin-left: 20px;
}
.ulsty-edit > li:before {
font-family: 'FontAwesome';
content: '\f044';
margin:0 0.8em 0 -1.8em;
}

File diff suppressed because one or more lines are too long

@ -451,6 +451,13 @@
404 handler
</a>
</li>
<li class="md-nav__item">
<a href="#auto-save-credential" title=" Auto save Credential" class="md-nav__link">
Auto save Credential
</a>
</li>
<li class="md-nav__item">
@ -468,15 +475,15 @@
</li>
<li class="md-nav__item">
<a href="#credential-data" title=" Credential data" class="md-nav__link">
Credential data
<a href="#debug-print" title=" Debug print" class="md-nav__link">
Debug print
</a>
</li>
<li class="md-nav__item">
<a href="#debug-print" title=" Debug print" class="md-nav__link">
Debug print
<a href="#disable-the-captive-portal" title=" Disable the captive portal" class="md-nav__link">
Disable the captive portal
</a>
</li>
@ -733,6 +740,13 @@
404 handler
</a>
</li>
<li class="md-nav__item">
<a href="#auto-save-credential" title=" Auto save Credential" class="md-nav__link">
Auto save Credential
</a>
</li>
<li class="md-nav__item">
@ -750,15 +764,15 @@
</li>
<li class="md-nav__item">
<a href="#credential-data" title=" Credential data" class="md-nav__link">
Credential data
<a href="#debug-print" title=" Debug print" class="md-nav__link">
Debug print
</a>
</li>
<li class="md-nav__item">
<a href="#debug-print" title=" Debug print" class="md-nav__link">
Debug print
<a href="#disable-the-captive-portal" title=" Disable the captive portal" class="md-nav__link">
Disable the captive portal
</a>
</li>
@ -846,12 +860,15 @@
<h3 id="embed-to-the-sketches"><i class="fa fa-edit"></i> Embed to the sketches<a class="headerlink" href="#embed-to-the-sketches" title="Permanent link">&para;</a></h3>
<p>How embed the AutoConnect to the sketches you have. Most simple approach to applying AutoConnect for the existing sketches, follow the below steps.</p>
<p><img src="../images/BeforeAfter.svg" /></p>
<p><i class="fa fa-edit"></i> Insert <code class="codehilite"><span class="cp">#include</span> <span class="cpf">&lt;AutoConnect.h&gt;</span><span class="cp"></span></code> to behind of <code class="codehilite"><span class="cp">#include</span> <span class="cpf">&lt;ESP8266WebServer.h&gt;</span><span class="cp"></span></code>.<br />
<i class="fa fa-edit"></i> Insert <code class="codehilite">AutoConnect</code><em><code class="codehilite">PORTAL(WEBSERVER);</code></em> to behind of <code class="codehilite">ESP8266WebServer</code><em><code class="codehilite">WEBSERVER;</code></em> declaration.<sup id="fnref:1"><a class="footnote-ref" href="#fn:1" rel="footnote">1</a></sup><br />
<i class="fa fa-edit"></i> Remove <code class="codehilite">WiFi.begin(</code><em><code class="codehilite">SSID</code></em><code class="codehilite">,</code><em><code class="codehilite">PSK</code></em><code class="codehilite">)</code> and the subsequent logic for the connection status check.<br />
<i class="fa fa-edit"></i> Replace <em><code class="codehilite">WEBSERVER</code></em><code class="codehilite"><span class="na">.begin</span><span class="p">()</span></code> to <em><code class="codehilite">PORTAL</code></em><code class="codehilite"><span class="na">.begin</span><span class="p">()</span></code>.<sup id="fnref:2"><a class="footnote-ref" href="#fn:2" rel="footnote">2</a></sup><br />
<i class="fa fa-edit"></i> Replace <em><code class="codehilite">WEBSERVER</code></em><code class="codehilite"><span class="na">.handleClient</span><span class="p">()</span></code> to <em><code class="codehilite">PORTAL</code></em><code class="codehilite"><span class="na">.handleClient</span><span class="p">()</span></code>.<sup id="fnref:3"><a class="footnote-ref" href="#fn:3" rel="footnote">3</a></sup><br />
<i class="fa fa-edit"></i> If the connection successful logic is needed, you can check the return value as <code class="codehilite">true</code> or <code class="codehilite">false</code> of <em><code class="codehilite">PORTAL</code></em><code class="codehilite"><span class="na">.begin</span><span class="p">()</span></code>.</p>
<ul class="ulsty-edit" style="list-style:none;">
<li>Insert <code class="codehilite"><span class="cp">#include</span> <span class="cpf">&lt;AutoConnect.h&gt;</span></code> to behind of <code class="codehilite"><span class="cp">#include</span> <span class="cpf">&lt;ESP8266WebServer.h&gt;</span></code>.</li>
<li>Insert <code class="codehilite"><span class="na">AutoConnect</span> <em>PORTAL(WEBSERVER);</em></code> to behind of <code class="codehilite"><span class="na">ESP8266WebServer</span> <em>WEBSERVER;</em></code> declaration.<sup id="fnref:1"><a class="footnote-ref" href="#fn:1" rel="footnote">1</a></sup></li>
<li>Remove <code class="codehilite">WiFi.<span class="na">begin</span>(<em>SSID</em>,<em>PSK</em>)</code> and the subsequent logic for the connection status check.</li>
<li>Replace <code class="codehilite"><em>WEBSERVER</em>.<span class="na">begin</span><span class="p">()</span></code> to <code class="codehilite"><em>PORTAL</em>.<span class="na">begin</span><span class="p">()</span></code>.<sup id="fnref:2"><a class="footnote-ref" href="#fn:2" rel="footnote">2</a></sup></li>
<li>Replace <code class="codehilite"><em>WEBSERVER</em>.<span class="na">handleClient</span><span class="p">()</span></code> to <code class="codehilite"><em>PORTAL</em>.<span class="na">handleClient</span><span class="p">()</span></code>.<sup id="fnref:3"><a class="footnote-ref" href="#fn:3" rel="footnote">3</a></sup></li>
<li>If the connection checks logic is needed, you can check the return value according to <code class="codehilite"><em>PORTAL</em>.<span class="na">begin</span><span class="p">()</span></code> with <code class="codehilite">true</code> or <code class="codehilite">false</code>.</li>
</ul>
<h2 id="basic-usage">Basic usage<a class="headerlink" href="#basic-usage" title="Permanent link">&para;</a></h2>
<h3 id="basic-logic-sequence-for-the-user-sketches"><i class="fa fa-caret-right"></i> Basic logic sequence for the user sketches<a class="headerlink" href="#basic-logic-sequence-for-the-user-sketches" title="Permanent link">&para;</a></h3>
<h4 id="1-a-typical-logic-sequence">1. A typical logic sequence<a class="headerlink" href="#1-a-typical-logic-sequence" title="Permanent link">&para;</a></h4>
@ -945,6 +962,15 @@ or</p>
<h2 id="advanced-usage">Advanced usage<a class="headerlink" href="#advanced-usage" title="Permanent link">&para;</a></h2>
<h3 id="404-handler"><i class="fa fa-caret-right"></i> 404 handler<a class="headerlink" href="#404-handler" title="Permanent link">&para;</a></h3>
<p>Registering the "not found" handler is a different way than ESP8266. The <em>onNotFound</em> of ESP8266WebServer does not work with AutoConnect. AutoConnect overrides <em>ESP8266WebServer::onNotFound</em> to handle a captive portal. To register "not found" handler, use <a href="../api/index.html#onnotfound"><em>AutoConnect::onNotFound</em></a>.</p>
<h3 id="auto-save-credential"><i class="fa fa-caret-right"></i> Auto save Credential<a class="headerlink" href="#auto-save-credential" title="Permanent link">&para;</a></h3>
<p>By default, AutoConnect saves the credentials of the established connection in EEPROM. You can disable it with the <strong>autoSave</strong> parameter specified by <a href="../api/index.html#config"><em>AutoConnect::config</em></a>.</p>
<div class="codehilite"><pre><span></span><span class="n">AutoConnect</span> <span class="n">Portal</span><span class="p">;</span>
<span class="n">AutoConnectConfig</span> <span class="n">Config</span><span class="p">;</span>
<span class="hll"><span class="n">Config</span><span class="p">.</span><span class="n">autoSave</span> <span class="o">=</span> <span class="n">AC_SAVECREDENTIAL_NEVER</span><span class="p">;</span>
</span><span class="n">Portal</span><span class="p">.</span><span class="nf">config</span><span class="p">(</span><span class="n">Config</span><span class="p">);</span>
<span class="n">Portal</span><span class="p">.</span><span class="nf">begin</span><span class="p">();</span>
</pre></div>
<h3 id="captive-portal-start-detection"><i class="fa fa-caret-right"></i> Captive portal start detection<a class="headerlink" href="#captive-portal-start-detection" title="Permanent link">&para;</a></h3>
<p>The captive portal will only be activated if the first <em>WiFi::begin</em> fails. Sketch can detect with the <a href="../api/index.html#ondetect"><em>onDetect</em></a> 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.</p>
<div class="codehilite"><pre><span></span><span class="n">AutoConnect</span> <span class="n">Portal</span><span class="p">;</span>
@ -990,15 +1016,6 @@ or</p>
<span class="p">}</span>
</pre></div>
<h3 id="credential-data"><i class="fa fa-caret-right"></i> Credential data<a class="headerlink" href="#credential-data" title="Permanent link">&para;</a></h3>
<p>By default, AutoConnect saves the credentials of the established connection in EEPROM. You can disable it with the <strong>autoSave</strong> parameter specified by <a href="../api/index.html#config"><em>AutoConnect::config</em></a>.</p>
<div class="codehilite"><pre><span></span><span class="n">AutoConnect</span> <span class="n">Portal</span><span class="p">;</span>
<span class="n">AutoConnectConfig</span> <span class="n">Config</span><span class="p">;</span>
<span class="hll"><span class="n">Config</span><span class="p">.</span><span class="n">autoSave</span> <span class="o">=</span> <span class="n">AC_SAVECREDENTIAL_NEVER</span><span class="p">;</span>
</span><span class="n">Portal</span><span class="p">.</span><span class="nf">config</span><span class="p">(</span><span class="n">Config</span><span class="p">);</span>
<span class="n">Portal</span><span class="p">.</span><span class="nf">begin</span><span class="p">();</span>
</pre></div>
<div class="admonition note">
<p class="admonition-title">AutoConnect::config before AutoConnect::begin</p>
<p><em>AutoConnect::config</em> must be executed before <em>AutoConnect::begin</em>.</p>
@ -1008,6 +1025,17 @@ or</p>
<div class="codehilite"><pre><span></span><span class="cp">#define AC_DEBUG</span>
</pre></div>
<h3 id="disable-the-captive-portal"><i class="fa fa-caret-right"></i> Disable the captive portal<a class="headerlink" href="#disable-the-captive-portal" title="Permanent link">&para;</a></h3>
<p>It can also prevent the captive portal from starting even if the connection at the first <em>WiFi.begin</em> fails. In this case, the behavior of <em>AutoConnect::begin</em> is the same as <em>WiFi.begin</em>.</p>
<p>For disabling the captive portal, <strong>autoRise</strong> sets to false with AutoConnectConfig.</p>
<div class="codehilite"><pre><span></span><span class="n">AutoConnect</span> <span class="n">portal</span><span class="p">;</span>
<span class="n">AutoConnectConfig</span> <span class="n">acConfig</span><span class="p">;</span>
<span class="hll"><span class="n">acConfig</span><span class="p">.</span><span class="n">autoRaise</span> <span class="o">=</span> <span class="kr">false</span><span class="p">;</span>
</span><span class="n">portal</span><span class="p">.</span><span class="nf">config</span><span class="p">(</span><span class="n">acConfig</span><span class="p">);</span>
<span class="n">portal</span><span class="p">.</span><span class="nf">begin</span><span class="p">();</span>
</pre></div>
<h3 id="refers-the-hosted-esp8266webserver"><i class="fa fa-caret-right"></i> Refers the hosted ESP8266WebServer<a class="headerlink" href="#refers-the-hosted-esp8266webserver" title="Permanent link">&para;</a></h3>
<p>Constructing an AutoConnect object variable without parameters then creates and starts an ESP8266WebServer inside the AutoConnect. This object variable could be referred by <a href="../api/index.html#host"><em>AutoConnect::host()</em></a> function to access ESP8266WebServer instance as like below.</p>
<div class="codehilite"><pre><span></span><span class="n">AutoConnect</span> <span class="n">Portal</span><span class="p">;</span>

@ -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.
<dd><span class="apidef" style="width:230px;">false</span>No reset.</dd>
</dl>
#### 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.
<dl class="apidl">
<dt>**Type**</dt>
<dd>bool</dd>
<dt>**Value**</dt>
<dd><span class="apidef" style="width:230px;">true</span>Enable the captive portal. This is a default.</dd>
<dd><span class="apidef" style="width:230px;">false</span>Disable the captive portal.</dd>
</dl>
#### autoSave
The credential saved automatically at the connection establishment.

@ -35,4 +35,10 @@
.apidl {
margin-left: 20px;
}
.ulsty-edit > li:before {
font-family: 'FontAwesome';
content: '\f044';
margin:0 0.8em 0 -1.8em;
}

@ -6,12 +6,14 @@ How embed the AutoConnect to the sketches you have. Most simple approach to appl
<img src="../images/BeforeAfter.svg" />
<i class="fa fa-edit"></i> Insert `#include <AutoConnect.h>` to behind of `#include <ESP8266WebServer.h>`.
<i class="fa fa-edit"></i> Insert `AutoConnect`*`PORTAL(WEBSERVER);`* to behind of `ESP8266WebServer`*`WEBSERVER;`* declaration.[^1]
<i class="fa fa-edit"></i> Remove `WiFi.begin(`*`SSID`*`,`*`PSK`*`)` and the subsequent logic for the connection status check.
<i class="fa fa-edit"></i> Replace *`WEBSERVER`*`.begin()` to *`PORTAL`*`.begin()`.[^2]
<i class="fa fa-edit"></i> Replace *`WEBSERVER`*`.handleClient()` to *`PORTAL`*`.handleClient()`.[^3]
<i class="fa fa-edit"></i> If the connection successful logic is needed, you can check the return value as `true` or `false` of *`PORTAL`*`.begin()`.
<ul class="ulsty-edit" style="list-style:none;">
<li>Insert <code class="codehilite"><span class="cp">#include</span> <span class="cpf">&lt;AutoConnect.h&gt;</span></code> to behind of <code class="codehilite"><span class="cp">#include</span> <span class="cpf">&lt;ESP8266WebServer.h&gt;</span></code>.</li>
<li>Insert <code class="codehilite"><span class="na">AutoConnect</span> <em>PORTAL(WEBSERVER);</em></code> to behind of <code class="codehilite"><span class="na">ESP8266WebServer</span> <em>WEBSERVER;</em></code> declaration.<sup id="fnref:1"><a class="footnote-ref" href="#fn:1" rel="footnote">1</a></sup></li>
<li>Remove <code class="codehilite">WiFi.<span class="na">begin</span>(<em>SSID</em>,<em>PSK</em>)</code> and the subsequent logic for the connection status check.</li>
<li>Replace <code class="codehilite"><em>WEBSERVER</em>.<span class="na">begin</span><span class="p">()</span></code> to <code class="codehilite"><em>PORTAL</em>.<span class="na">begin</span><span class="p">()</span></code>.<sup id="fnref:2"><a class="footnote-ref" href="#fn:2" rel="footnote">2</a></sup></li>
<li>Replace <code class="codehilite"><em>WEBSERVER</em>.<span class="na">handleClient</span><span class="p">()</span></code> to <code class="codehilite"><em>PORTAL</em>.<span class="na">handleClient</span><span class="p">()</span></code>.<sup id="fnref:3"><a class="footnote-ref" href="#fn:3" rel="footnote">3</a></sup></li>
<li>If the connection checks logic is needed, you can check the return value according to <code class="codehilite"><em>PORTAL</em>.<span class="na">begin</span><span class="p">()</span></code> with <code class="codehilite">true</code> or <code class="codehilite">false</code>.</li>
</ul>
[^1]:
Each *VARIABLE* conforms to the actual declaration in the sketches.
@ -108,6 +110,18 @@ Reference to ESP8266WebServer | AutoConnect menu not available.<br>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).
### <i class="fa fa-caret-right"></i> 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();
```
### <i class="fa fa-caret-right"></i> 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() {
}
```
### <i class="fa fa-caret-right"></i> 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
```
### <i class="fa fa-caret-right"></i> 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();
```
### <i class="fa fa-caret-right"></i> 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.

@ -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();
}
}
}
}

@ -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 */
};

Loading…
Cancel
Save