<h2id="write-the-custom-web-page-with-json">Write the custom Web page with JSON<aclass="headerlink"href="#write-the-custom-web-page-with-json"title="Permanent link">¶</a></h2>
<h2id="write-the-custom-web-page-with-json">Write the custom Web page with JSON<aclass="headerlink"href="#write-the-custom-web-page-with-json"title="Permanent link">¶</a></h2>
@ -982,18 +988,12 @@ The following JSON code and sketch will execute the custom Web page as the examp
<ahref="#cast-items-of-your-sketch-own-into-the-autoccnnect-menu"title=" Cast items of your sketch own into the AutocCnnect menu"class="md-nav__link">
Cast items of your sketch own into the AutocCnnect menu
</a>
</li>
<liclass="md-nav__item">
<ahref="#change-menu-title"title=" Change menu title"class="md-nav__link">
Change menu title
</a>
</li>
</li>
<liclass="md-nav__item">
<liclass="md-nav__item">
@ -817,6 +837,20 @@
Captive portal timeout control
Captive portal timeout control
</a>
</a>
</li>
<liclass="md-nav__item">
<ahref="#cast-items-of-your-sketch-own-into-the-autoccnnect-menu"title=" Cast items of your sketch own into the AutocCnnect menu"class="md-nav__link">
Cast items of your sketch own into the AutocCnnect menu
</a>
</li>
<liclass="md-nav__item">
<ahref="#change-menu-title"title=" Change menu title"class="md-nav__link">
Change menu title
</a>
</li>
</li>
<liclass="md-nav__item">
<liclass="md-nav__item">
@ -984,7 +1018,7 @@
<divclass="admonition note">
<divclass="admonition note">
<pclass="admonition-title">In ESP32, the credentials for AutoConnect are not in NVS</p>
<pclass="admonition-title">In ESP32, the credentials for AutoConnect are not in NVS</p>
<p>The credentials used by AutoConnect are not saved in NVS on ESP32 module. ESP-IDF saves the WiFi connection configuration to NVS, but AutoConnect stores it on the eeprom partition. You can find the partition table for default as <ahref="https://github.com/espressif/arduino-esp32/blob/master/tools/partitions/default.csv">default.csv</a></p>
<p>The credentials used by AutoConnect are not saved in NVS on ESP32 module. ESP-IDF saves the WiFi connection configuration to NVS, but AutoConnect stores it on the EEPROM partition. You can find the partition table for default as <ahref="https://github.com/espressif/arduino-esp32/blob/master/tools/partitions/default.csv">default.csv</a></p>
<p>The captive portal will only be activated if the first <em>WiFi::begin</em> fails. Sketch can detect with the <ahref="api.html#ondetect"><em>AutoConnect::onDetect</em></a> function 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 <ahref="api.html#ondetect"><em>AutoConnect::onDetect</em></a> function 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>
<spanstyle="color: #75715e">// Some sketch code for not connected scene is here.</span>
<spanstyle="color: #75715e">// Some sketch code for not connected scene is here.</span>
@ -1089,6 +1123,65 @@ Also, if you want to stop AutoConnect completely when the captive portal is time
<spanstyle="color: #f8f8f2">}</span>
<spanstyle="color: #f8f8f2">}</span>
</pre></div>
</pre></div>
<h3id="cast-items-of-your-sketch-own-into-the-autoccnnect-menu"><iclass="fa fa-caret-right"></i> Cast items of your sketch own into the AutocCnnect menu<aclass="headerlink"href="#cast-items-of-your-sketch-own-into-the-autoccnnect-menu"title="Permanent link">¶</a></h3>
<p>If your sketch is handling your own web page, you can call that page from the <ahref="menu.html">AutoConnect menu</a>. Unlike the custom Web pages by <ahref="apiaux.html#autoconnectaux">AutoConnectAux</a>, this allows AutoConnect menu to legacy web pages registered by <em>ESP8266WebServer::on</em>/<em>WebServer::on</em> function.</p>
<p>To implement this with your sketch, use only the <ahref="apiaux.html#autoconnectaux">AutoConnectAux</a> constructed with the URI of that page. <ahref="acelements.html">AutoConnectElements</a> is not required. The basic procedure for this as follows. The FSBrowser menu as the below has <strong>Edit</strong> and <strong>List</strong> item, which are implemented according to this basic procedure.</p>
<ol>
<li>Declare AutoConnectAux for each legacy page. It includes the URI of the page and item string which will display in the AutoConnect menu.</li>
<li>Sketch legacy page handlers.</li>
<li>Register those handler functions to ESP8266WebServer/WebServer with the <strong>on</strong> function.</li>
<li>Register AutoConnectAux declared with #1 to AutoConnect using <ahref="api.html#join">AutoConnect::join</a> function. It serves as a menu item.</li>
<li><ahref="api.html#begin">Begin</a> the portal.</li>
<li>Performs <ahref="api.html#handleClient">AutoConnect::handleClient</a> in the <strong>loop</strong> function.</li>
<h3id="change-menu-title"><iclass="fa fa-caret-right"></i> Change menu title<aclass="headerlink"href="#change-menu-title"title="Permanent link">¶</a></h3>
<p>Although the default menu title is <strong>AutoConnect</strong>, you can change the title by setting <ahref="apiconfig.html#title">AutoConnectConfig::title</a>. To set the menu title properly, you must set before calling <ahref="api.html#begin">AutoConnect::begin</a>.</p>
<h3id="combination-with-mdns"><iclass="fa fa-caret-right"></i> Combination with mDNS<aclass="headerlink"href="#combination-with-mdns"title="Permanent link">¶</a></h3>
<h3id="combination-with-mdns"><iclass="fa fa-caret-right"></i> Combination with mDNS<aclass="headerlink"href="#combination-with-mdns"title="Permanent link">¶</a></h3>
<p>With <ahref="https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266mDNS">mDNS library</a>, you can access to ESP8266 by name instead of IP address after connection. The sketch can start the MDNS responder after <ahref="api.html#begin"><em>AutoConnect::begin</em></a>.</p>
<p>With <ahref="https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266mDNS">mDNS library</a>, you can access to ESP8266 by name instead of IP address after connection. The sketch can start the MDNS responder after <ahref="api.html#begin"><em>AutoConnect::begin</em></a>.</p>
<spanstyle="color: #f8f8f2">AutoConenctConfig</span><spanstyle="color: #a6e22e">Config</span><spanstyle="color: #f8f8f2">(</span><spanstyle="color: #e6db74">""</span><spanstyle="color: #f8f8f2">,</span><spanstyle="color: #e6db74">"passpass"</span><spanstyle="color: #f8f8f2">);</span><spanstyle="color: #75715e">// SoftAp name is determined at runtime</span>
<spanstyle="color: #f8f8f2">AutoConenctConfig</span><spanstyle="color: #a6e22e">Config</span><spanstyle="color: #f8f8f2">(</span><spanstyle="color: #e6db74">""</span><spanstyle="color: #f8f8f2">,</span><spanstyle="color: #e6db74">"passpass"</span><spanstyle="color: #f8f8f2">);</span><spanstyle="color: #75715e">// SoftAp name is determined at runtime</span>
@ -1255,7 +1281,8 @@ The default value is 0.
<spanstyle="color: #f8f8f2">Config.boundaryOffet</span><spanstyle="color: #f92672">=</span><spanstyle="color: #ae81ff">64</span><spanstyle="color: #f8f8f2">;</span><spanstyle="color: #75715e">// Reserve 64 bytes for the user data in EEPROM.</span>
<spanstyle="color: #f8f8f2">Config.boundaryOffet</span><spanstyle="color: #f92672">=</span><spanstyle="color: #ae81ff">64</span><spanstyle="color: #f8f8f2">;</span><spanstyle="color: #75715e">// Reserve 64 bytes for the user data in EEPROM.</span>
<spanstyle="color: #f8f8f2">Config.portalTimeout</span><spanstyle="color: #f92672">=</span><spanstyle="color: #ae81ff">60000</span><spanstyle="color: #f8f8f2">;</span><spanstyle="color: #75715e">// Sets timeout value for the captive portal</span>
<spanstyle="color: #f8f8f2">Config.portalTimeout</span><spanstyle="color: #f92672">=</span><spanstyle="color: #ae81ff">60000</span><spanstyle="color: #f8f8f2">;</span><spanstyle="color: #75715e">// Sets timeout value for the captive portal</span>
<spanstyle="color: #f8f8f2">Config.retainPortal</span><spanstyle="color: #f92672">=</span><spanstyle="color: #f8f8f2">true;</span><spanstyle="color: #75715e">// Retains the portal function after timed-out</span>
<spanstyle="color: #f8f8f2">Config.retainPortal</span><spanstyle="color: #f92672">=</span><spanstyle="color: #f8f8f2">true;</span><spanstyle="color: #75715e">// Retains the portal function after timed-out</span>
<spanstyle="color: #f8f8f2">Config.homeUri</span><spanstyle="color: #f92672">=</span><spanstyle="color: #e6db74">"/index.html"</span><spanstyle="color: #75715e">// Sets home path of the sketch application</span>
<spanstyle="color: #f8f8f2">Config.homeUri</span><spanstyle="color: #f92672">=</span><spanstyle="color: #e6db74">"/index.html"</span><spanstyle="color: #f8f8f2">;</span><spanstyle="color: #75715e">// Sets home path of the sketch application</span>
<spanstyle="color: #f8f8f2">Config.title</span><spanstyle="color: #f92672">=</span><spanstyle="color: #e6db74">"My menu"</span><spanstyle="color: #f8f8f2">;</span><spanstyle="color: #75715e">// Customize the menu title</span>
!!! note "In ESP32, the credentials for AutoConnect are not in NVS"
!!! note "In ESP32, the credentials for AutoConnect are not in NVS"
The credentials used by AutoConnect are not saved in NVS on ESP32 module. ESP-IDF saves the WiFi connection configuration to NVS, but AutoConnect stores it on the eeprom partition. You can find the partition table for default as [default.csv](https://github.com/espressif/arduino-esp32/blob/master/tools/partitions/default.csv)
The credentials used by AutoConnect are not saved in NVS on ESP32 module. ESP-IDF saves the WiFi connection configuration to NVS, but AutoConnect stores it on the EEPROM partition. You can find the partition table for default as [default.csv](https://github.com/espressif/arduino-esp32/blob/master/tools/partitions/default.csv)
### <iclass="fa fa-caret-right"></i> Captive portal timeout control
### <iclass="fa fa-caret-right"></i> Captive portal timeout control
AutoConnect has two parameters for timeout control. One is a timeout value used when trying to connect to the specified AP. It behaves the same as general timeout control in connection attempt by WiFi.begin. This control is specified by the third parameter of [*AutoConnect::begin*](api.md#begin). Default value is macro defined by [**AUTOCONNECT_TIMEOUT**](api.md#defined-macros) in the `AutoConnectDef.h` file.
AutoConnect has two parameters for timeout control. One is a timeout value used when trying to connect to the specified AP. It behaves the same as general timeout control in connection attempt by WiFi.begin. This control is specified by the third parameter of [*AutoConnect::begin*](api.md#begin). Default value is macro defined by [**AUTOCONNECT_TIMEOUT**](api.md#defined-macros) in the `AutoConnectDef.h` file.
@ -91,7 +92,7 @@ void setup() {
void loop() {
void loop() {
if (WiFi.status() == WL_CONNECTED) {
if (WiFi.status() == WL_CONNECTED) {
// Some sketck code for the connected scene is here.
// Some sketch code for the connected scene is here.
}
}
else {
else {
// Some sketch code for not connected scene is here.
// Some sketch code for not connected scene is here.
@ -115,7 +116,7 @@ void setup() {
void loop() {
void loop() {
if (WiFi.status() == WL_CONNECTED) {
if (WiFi.status() == WL_CONNECTED) {
// Some sketck code for the connected scene is here.
// Some sketch code for the connected scene is here.
}
}
else {
else {
// Some sketch code for not connected scene is here.
// Some sketch code for not connected scene is here.
@ -145,7 +146,7 @@ void setup() {
void loop() {
void loop() {
if (WiFi.status() == WL_CONNECTED) {
if (WiFi.status() == WL_CONNECTED) {
// Some sketck code for the connected scene is here.
// Some sketch code for the connected scene is here.
}
}
else {
else {
// Some sketch code for not connected scene is here.
// Some sketch code for not connected scene is here.
@ -154,6 +155,72 @@ void loop() {
}
}
```
```
### <iclass="fa fa-caret-right"></i> Cast items of your sketch own into the AutocCnnect menu
If your sketch is handling your own web page, you can call that page from the [AutoConnect menu](menu.md). Unlike the custom Web pages by [AutoConnectAux](apiaux.md#autoconnectaux), this allows AutoConnect menu to legacy web pages registered by *ESP8266WebServer::on*/*WebServer::on* function.
To implement this with your sketch, use only the [AutoConnectAux](apiaux.md#autoconnectaux) constructed with the URI of that page. [AutoConnectElements](acelements.md) is not required. The basic procedure for this as follows. The FSBrowser menu as the below has **Edit** and **List** item, which are implemented according to this basic procedure.
1. Declare AutoConnectAux for each legacy page. It includes the URI of the page and item string which will display in the AutoConnect menu.
2. Sketch legacy page handlers.
3. Register those handler functions to ESP8266WebServer/WebServer with the **on** function.
4. Register AutoConnectAux declared with #1 to AutoConnect using [AutoConnect::join](api.md#join) function. It serves as a menu item.
5. [Begin](api.md#begin) the portal.
6. Performs [AutoConnect::handleClient](api.md#handleClient) in the **loop** function.
### <iclass="fa fa-caret-right"></i> Change menu title
Although the default menu title is **AutoConnect**, you can change the title by setting [AutoConnectConfig::title](apiconfig.md#title). To set the menu title properly, you must set before calling [AutoConnect::begin](api.md#begin).
```cpp hl_lines="6 7"
AutoConnect Portal;
AutoConnectConfig Config;
void setup() {
// Set menu title
Config.title = "FSBrowser";
Portal.config(Config);
Portal.begin();
}
```
Executing the above sketch will rewrite the menu title to *FSBrowser* as the below.
### <iclass="fa fa-caret-right"></i> Combination with mDNS
### <iclass="fa fa-caret-right"></i> Combination with mDNS
With [mDNS library](https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266mDNS), you can access to ESP8266 by name instead of IP address after connection. The sketch can start the MDNS responder after [*AutoConnect::begin*](api.md#begin).
With [mDNS library](https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266mDNS), you can access to ESP8266 by name instead of IP address after connection. The sketch can start the MDNS responder after [*AutoConnect::begin*](api.md#begin).
@ -355,7 +422,7 @@ AutoConnect will activate SoftAP at failed the first *WiFi.begin*. It SoftAP set