Added autoRise with AutoConnectConfig

pull/8/head
Hieromon Ikasamo 7 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. 9
      src/AutoConnect.cpp
  9. 12
      src/AutoConnect.h

@ -545,6 +545,13 @@
autoReset autoReset
</a> </a>
</li>
<li class="md-nav__item">
<a href="#autorise" title="autoRise" class="md-nav__link">
autoRise
</a>
</li> </li>
<li class="md-nav__item"> <li class="md-nav__item">
@ -882,6 +889,13 @@
autoReset autoReset
</a> </a>
</li>
<li class="md-nav__item">
<a href="#autorise" title="autoRise" class="md-nav__link">
autoRise
</a>
</li> </li>
<li class="md-nav__item"> <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_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_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_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_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> </pre></div>
<h2 id="autoconnect-api">AutoConnect API<a class="headerlink" href="#autoconnect-api" title="Permanent link">&para;</a></h2> <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;">true</span>Reset after WiFi disconnected automatically.</dd>
<dd><span class="apidef" style="width:230px;">false</span>No reset.</dd> <dd><span class="apidef" style="width:230px;">false</span>No reset.</dd>
</dl></p> </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> <h4 id="autosave">autoSave<a class="headerlink" href="#autosave" title="Permanent link">&para;</a></h4>
<p>The credential saved automatically at the connection establishment. <p>The credential saved automatically at the connection establishment.
<dl class="apidl"> <dl class="apidl">

@ -36,3 +36,9 @@
.apidl { .apidl {
margin-left: 20px; 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 404 handler
</a> </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>
<li class="md-nav__item"> <li class="md-nav__item">
@ -468,15 +475,15 @@
</li> </li>
<li class="md-nav__item"> <li class="md-nav__item">
<a href="#credential-data" title=" Credential data" class="md-nav__link"> <a href="#debug-print" title=" Debug print" class="md-nav__link">
Credential data Debug print
</a> </a>
</li> </li>
<li class="md-nav__item"> <li class="md-nav__item">
<a href="#debug-print" title=" Debug print" class="md-nav__link"> <a href="#disable-the-captive-portal" title=" Disable the captive portal" class="md-nav__link">
Debug print Disable the captive portal
</a> </a>
</li> </li>
@ -733,6 +740,13 @@
404 handler 404 handler
</a> </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>
<li class="md-nav__item"> <li class="md-nav__item">
@ -750,15 +764,15 @@
</li> </li>
<li class="md-nav__item"> <li class="md-nav__item">
<a href="#credential-data" title=" Credential data" class="md-nav__link"> <a href="#debug-print" title=" Debug print" class="md-nav__link">
Credential data Debug print
</a> </a>
</li> </li>
<li class="md-nav__item"> <li class="md-nav__item">
<a href="#debug-print" title=" Debug print" class="md-nav__link"> <a href="#disable-the-captive-portal" title=" Disable the captive portal" class="md-nav__link">
Debug print Disable the captive portal
</a> </a>
</li> </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> <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>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><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 /> <ul class="ulsty-edit" style="list-style:none;">
<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 /> <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>
<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 /> <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>
<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 /> <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>
<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 /> <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>
<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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <span class="p">}</span>
</pre></div> </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"> <div class="admonition note">
<p class="admonition-title">AutoConnect::config before AutoConnect::begin</p> <p class="admonition-title">AutoConnect::config before AutoConnect::begin</p>
<p><em>AutoConnect::config</em> must be executed before <em>AutoConnect::begin</em>.</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> <div class="codehilite"><pre><span></span><span class="cp">#define AC_DEBUG</span>
</pre></div> </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> <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> <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> <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_AP_NM 0x00FFFFFF // Default subnet mask
#define AUTOCONNECT_DNSPORT 53 // Default DNS port at captive portal #define AUTOCONNECT_DNSPORT 53 // Default DNS port at captive portal
#define AUTOCONNECT_MENU_TITLE "AutoConnect" // Default AutoConnect menu title #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_URI "/_ac" // Default AutoConnect root path
#define AUTOCONNECT_TIMEOUT 30000 // Default connection timeout[ms]
``` ```
## AutoConnect API ## 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> <dd><span class="apidef" style="width:230px;">false</span>No reset.</dd>
</dl> </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 #### autoSave
The credential saved automatically at the connection establishment. The credential saved automatically at the connection establishment.

@ -36,3 +36,9 @@
.apidl { .apidl {
margin-left: 20px; 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" /> <img src="../images/BeforeAfter.svg" />
<i class="fa fa-edit"></i> Insert `#include <AutoConnect.h>` to behind of `#include <ESP8266WebServer.h>`. <ul class="ulsty-edit" style="list-style:none;">
<i class="fa fa-edit"></i> Insert `AutoConnect`*`PORTAL(WEBSERVER);`* to behind of `ESP8266WebServer`*`WEBSERVER;`* declaration.[^1] <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>
<i class="fa fa-edit"></i> Remove `WiFi.begin(`*`SSID`*`,`*`PSK`*`)` and the subsequent logic for the connection status check. <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>
<i class="fa fa-edit"></i> Replace *`WEBSERVER`*`.begin()` to *`PORTAL`*`.begin()`.[^2] <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>
<i class="fa fa-edit"></i> Replace *`WEBSERVER`*`.handleClient()` to *`PORTAL`*`.handleClient()`.[^3] <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>
<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()`. <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]: [^1]:
Each *VARIABLE* conforms to the actual declaration in the sketches. 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). 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 ### <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. 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" !!! note "AutoConnect::config before AutoConnect::begin"
*AutoConnect::config* must be executed 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 #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 ### <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. 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,9 +99,15 @@ bool AutoConnect::begin(const char* ssid, const char* passphrase) {
cs = _waitForConnect(_portalTimeout) == WL_CONNECTED; cs = _waitForConnect(_portalTimeout) == WL_CONNECTED;
_currentHostIP = WiFi.localIP(); _currentHostIP = WiFi.localIP();
// Rushing into the portal. // It doesn't matter the connection status for launching the Web server.
_startWebServer(); _startWebServer();
// Rushing into the portal.
if (!cs) { if (!cs) {
// The captive portal is effective at the autoRise is valid only.
if (_apConfig.autoRise) {
// Change WiFi working mode, Enable AP with STA // Change WiFi working mode, Enable AP with STA
WiFi.setAutoConnect(false); WiFi.setAutoConnect(false);
WiFi.disconnect(); WiFi.disconnect();
@ -142,6 +148,7 @@ bool AutoConnect::begin(const char* ssid, const char* passphrase) {
} }
} }
} }
}
return cs; return cs;
} }

@ -110,8 +110,9 @@ class AutoConnectConfig {
channel(1), channel(1),
hidden(0), hidden(0),
autoSave(AC_SAVECREDENTIAL_AUTO), autoSave(AC_SAVECREDENTIAL_AUTO),
autoReset(true),
uptime(AUTOCONNECT_STARTUPTIME), uptime(AUTOCONNECT_STARTUPTIME),
autoRise(true),
autoReset(true),
homeUri(AUTOCONNECT_HOMEURI) {} homeUri(AUTOCONNECT_HOMEURI) {}
/** /**
* Configure by SSID for the captive portal access point and password. * Configure by SSID for the captive portal access point and password.
@ -125,8 +126,9 @@ class AutoConnectConfig {
channel(1), channel(1),
hidden(0), hidden(0),
autoSave(AC_SAVECREDENTIAL_AUTO), autoSave(AC_SAVECREDENTIAL_AUTO),
autoReset(true),
uptime(AUTOCONNECT_STARTUPTIME), uptime(AUTOCONNECT_STARTUPTIME),
autoRise(true),
autoReset(true),
homeUri(AUTOCONNECT_HOMEURI) {} homeUri(AUTOCONNECT_HOMEURI) {}
~AutoConnectConfig() {} ~AutoConnectConfig() {}
@ -140,8 +142,9 @@ class AutoConnectConfig {
channel = o.channel; channel = o.channel;
hidden = o.hidden; hidden = o.hidden;
autoSave = o.autoSave; autoSave = o.autoSave;
autoReset = o.autoReset;
uptime = o.uptime; uptime = o.uptime;
autoRise = o.autoRise;
autoReset = o.autoReset;
homeUri = o.homeUri; homeUri = o.homeUri;
return *this; return *this;
} }
@ -154,8 +157,9 @@ class AutoConnectConfig {
uint8_t channel; /**< SoftAP used wifi channel */ uint8_t channel; /**< SoftAP used wifi channel */
uint8_t hidden; /**< SoftAP SSID hidden */ uint8_t hidden; /**< SoftAP SSID hidden */
AC_SAVECREDENTIAL_t autoSave; /**< Auto save credential */ AC_SAVECREDENTIAL_t autoSave; /**< Auto save credential */
bool autoReset; /**< Reset ESP8266 module automatically when WLAN disconnected. */
int uptime; /**< Length of start up time */ 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 */ String homeUri; /**< A URI of user site */
}; };

Loading…
Cancel
Save