### <iclass="fa fa-caret-right"></i> Casts the HTML pages to be add-on into the menu
### <iclass="fa fa-caret-right"></i> Capture the legacy web pages as items into the menu
If your sketch handles web pages, you can embed the pages into the AutoConnect menu in continuance enjoying the utility of the WiFi connection feature. Unlike the custom Web pages by [AutoConnectElements](acelements.md), this allows to legacy web pages registered by *ESP8266WebServer::on* or *WebServer::on* function.
You can embed the ordinary page processed by the ESP8266WebServer request handler as an item into the AutoConnect menu. AutoConnect allows capturing the legacy web pages for ESP8266WebServer or WebServer of ESP32 and extends the menu containing these items, also Sketch can embed the legacy pages using the [*AutoConnect::append*](api.md#append) function.
To implement embedding your legacy web pages to the AutoConnect menu, you can use AutoConnectAux only constructed with the URI of the page to be embedding. AutoConnectElements is not required. The basic procedure for this as follows:
To process a web page using the ESP8266WebServer class (The WebServer class for ESP32), you usually register a handler with URI by the `on` function. The [*AutoConnect::append*](api.md#append) function creates internally an [**AutoConnectAux**](acintro.md) depended on its URI and integrates into the menu.
1. Declare AutoConnectAux for each legacy page. It includes the URI of the page and item string which will display in the AutoConnect menu.
The following code has a mixture of both AutoConnectAux and the legacy web page. An AutoConnectAux page is menued automatically with the [*AutoConnect::join*](api.md#join) or [*AutoConnect::load*](api.md#load) function, and a legacy page is integrated by the [*AutoConnect::append*](api.md#append) function.
2. Sketch the 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.
```cpp hl_lines="10 28 32"
```cpp hl_lines="26 35"
#include<ESP8266WiFi.h>
#include<ESP8266WiFi.h>
#include<ESP8266WebServer.h>
#include<ESP8266WebServer.h>
#include<AutoConnect.h>
#include<AutoConnect.h>
ESP8266WebServer server;
ESP8266WebServer server;
// Declaration for casting legacy page to AutoConnect menu.
// Specifies an uri and the menu label.
AutoConnect portal(server);
AutoConnect portal(server);
AutoConnectAux hello("/hello", "Hello"); // Step #1 as the above procedure
// Step #2 as the above procedure
// Definitions of AutoConnectAux page
// A conventional web page driven by the ESP8266WebServer::on handler.
For more details, see section [Constructing the menu](menuize.md) of Examples page.
The [*AutoConnect::append*](api.md#append) function also has the third parameter that directly specifies the request handler. It has similar efficacy to calling the append and `ESP8266WebSever::on` at once.
For more details, see section [Attach the menu](menuize.md) of Examples page.
!!! note "Necessary ESP8266WebServer/WebServer has materialized"
The WebServer must have instantiated for calling with a request handler parameter. AutoConnect can instantiate and host a WebServer internally, but in that case, the point in time to call the [AutoConnct::append](api.md#append) function with a request handler parameter must be after [AutoConnect::begin](api.md#begin).
### <iclass="fa fa-caret-right"></i> Change the menu labels
### <iclass="fa fa-caret-right"></i> Change the menu labels
@ -357,7 +373,7 @@ Combining these two parameters allows you to filter the destination AP when mult
</tr>
</tr>
<tr>
<tr>
<td>Specified with the Sketch</td>
<td>Specified with the Sketch</td>
<td>Not efective</td>
<td>Not effective</td>
<td>By AutoConnect::begin parameters</td>
<td>By AutoConnect::begin parameters</td>
<td>Use the specified value of AutoConnectConfig</td>
<td>Use the specified value of AutoConnectConfig</td>
</tr>
</tr>
@ -384,6 +400,44 @@ You can output AutoConnect monitor messages to the **Serial**. A monitor message
#define AC_DEBUG
#define AC_DEBUG
```
```
### <iclass="fa fa-caret-right"></i> Detect WiFi connection establishment with a router
[*AutoConnect::onConnect*](api.md#onconnect) allows the Sketch to detect a WiFi connection to a router. The Sketch uses [*AutoConnect::onConnect*] to register a function to call when WiFi connected.
For example, as the following Sketch, this can be combined with [*AutoConnectConfig::retainPortal*](apiconfig.md#retainportal) to stop **SoftAP** in a **loop()**. It avoids blocking in the captive portal state by AutoConnect and allows the loop to run even without a WiFi connection.
// Here, the Sketch can execute without WiFi connection.
// It avoids blocking the state by the captive portal even if the captive portal is available.
portal.handleClient();
}
```
!!! note "It is not an event"
AutoConnect::onConnect has the same effect on the Sketch as the [WiFi.onStationModeConnected](https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/generic-class.html#onevent), but AutoConnect does not use the event. Sketch can use `WiFi.onEvent` independently of AutoConnect.
### <iclass="fa fa-caret-right"></i> Disable the captive portal
### <iclass="fa fa-caret-right"></i> Disable the captive portal
It can also prevent the captive portal from starting even if the connection at the 1st-WiFi.begin fails. In this case, [*AutoConnect::begin*](api.md#begin) behaves same as *WiFi.begin*.
It can also prevent the captive portal from starting even if the connection at the 1st-WiFi.begin fails. In this case, [*AutoConnect::begin*](api.md#begin) behaves same as *WiFi.begin*.
@ -519,7 +573,7 @@ Here section describes how to launch on demand the captive portal, and suggests
portal = nullptr;
portal = nullptr;
}
}
}
}
// Here, ordinally sketch logic.
// Here, ordinary sketch logic.
}
}
```
```
@ -638,7 +692,7 @@ The Sketch HOME path is closely related to the [bootUri](apiconfig.md#booturi) t
AutoConnect features a built-in OTA function to update ESP module firmware. You can easily make the Sketch that equips OTA and able to operate with the AutoConnect menu.
AutoConnect features a built-in OTA function to update ESP module firmware. You can easily make the Sketch that equips OTA and able to operate with the AutoConnect menu.
Creates an AutoConnectAux dynamically with the specified URI and integrates it into the menu. Calls with a request handler parameter can use this function as menu registration for a legacy page of ESP8266WebServer/WebServer. If the **handler** parameter specified, also it will register the request handler for the ESP8266WebServer/WebServer.
AutoConnect manages the menu items using a sequence list, and this function always adds the item to the end of the list. Therefore, the order of the menu items is the additional order.
Returns the pointer to created AutoConnectAux instance, the `nullptr` if an AutoConnectAux with the same URI already exists.
<dlclass="apidl">
<dt>**Parameter**</dt>
<dd><spanclass="apidef">uri</span><spanclass="apidesc">A string of the URI.</span></dd>
<dd><spanclass="apidef">title</span><spanclass="apidesc">Title for menu item.</span></dd>
<dd><spanclass="apidef">handler</span><spanclass="apidesc">Request handler function as type of **ESP8266WebServer::THandlerFunction**/**WebServer::THandlerFunction**.</span></dd>
<dt>**Return value**</dt>
<dd>A Pointer to a created AutoConnectAux instance.</dd>
</dl>
!!! note "Necessary ESP8266WebServer/WebServer has materialized"
The WebServer must have instantiated for calling with a request handler parameter. AutoConnect can instantiate and host a WebServer internally, but in that case, the point in time to call the append function with a request handler parameter must be after AutoConnect::begin.
### <iclass="fa fa-caret-right"></i> aux
### <iclass="fa fa-caret-right"></i> aux
```cpp
```cpp
@ -126,6 +160,34 @@ Set SoftAP's WiFi configuration and static IP configuration.
<dd><spanclass="apidef">false</span><spanclass="aidesc">Configuration parameter is invalid, some values out of range.</span></dd>
<dd><spanclass="apidef">false</span><spanclass="aidesc">Configuration parameter is invalid, some values out of range.</span></dd>
</dl>
</dl>
### <iclass="fa fa-caret-right"></i> detach
```cpp
AutoConnectAux* detach(const String& uri)
```
Detach the AutoConnectAux with the specified URI from the management of AutoConnect. An unmanaged AutoConnectAux will no longer appear in menu items, and its page handler will no longer respond even if the URI is accessed directly.
<dlclass="apidl">
<dt>**Parameter**</dt>
<dd><spanclass="apidef">uri</span><spanclass="apidesc">URI of AutoConnectAux to be detached.</span></dd>
</dl>
If the request handler registered in the detaching AutoConnectAux is for a legacy page of the ESP8266WebServer/WebServer, the URI is still valid after detaching. AutoConnect does not delete the request handler registered to ESP8266WebServer/WebServer with the `on` function. (It cannot be removed)
!!! hint "Deleting the AutoConnectAux"
You can use the return value from the AotoConnect::detach to delete the AutoConnectAux instance which dynamically created with the [AutoConnect::append](api.md#append).
### <iclass="fa fa-caret-right"></i> disableMenu
```cpp
void disableMenu(const uint16_t items)
```
Disable the [AutoConnect menu](menu.md) items specified by the items parameter with logical OR value using **AC_MENUITEM_t** constant.
This function only works for AutoConnect primary menu items. It has no effect on disable for AutoConnectAux items. To disable the items by AutoConnectAux, use the [AutoConnectAux::menu](apiaux.md#menu) function.
<dlclass="apidl">
<dt>**Parameter**</dt>
<dd><spanclass="apidef">items</span><spanclass="apidesc">Specify the combined value of **AC_MENUITEM_t** of the items deleting from the AutoConnect menu. It provides the value calculated from the **logical OR** by the AC_MENUITEM_t value of each item. Refer to the [enableMenu](#enablemenu) about AC_MENUITEM_t.</span></dd>
Enable the [AutoConnect menu](menu.md) items specified by the items parameter with logical OR value using **AC_MENUITEM_t** constant.
Enable the [AutoConnect menu](menu.md) items specified by the items parameter with logical OR value using **AC_MENUITEM_t** constant.
This function only works for AutoConnect primary menu items. It has no effect on enable for AutoConnectAux items. To enable the items by AutoConnectAux, use the [AutoConnectAux::menu](apiaux.md#menu) function.
<dlclass="apidl">
<dlclass="apidl">
<dt>**Parameter**</dt>
<dt>**Parameter**</dt>
<dd><spanclass="apidef">items</span><spanclass="apidesc">Specify the combined value of **AC_MENUITEM_t** of the items applying to the AutoConnect menu. It provides the value calculated from the **logical OR** by the AC_MENUITEM_t value of each item applied as a menu. AC_MENUITEM_t is enumeration type to identify each menu item and it has the below values.</span></dd>
<dd><spanclass="apidef">items</span><spanclass="apidesc">Specify the combined value of **AC_MENUITEM_t** of the items applying to the AutoConnect menu. It provides the value calculated from the **logical OR** by the AC_MENUITEM_t value of each item applied as a menu. AC_MENUITEM_t is enumeration type to identify each menu item and it has the below values.</span></dd>
The end function releases the instance of ESP8266WebServer/WebServer and DNSServer. It can not process them after the end function.
The end function releases the instance of ESP8266WebServer/WebServer and DNSServer. It can not process them after the end function.
### <iclass="fa fa-caret-right"></i> disableMenu
```cpp
void disableMenu(const uint16_t items)
```
Disable the [AutoConnect menu](menu.md) items specified by the items parameter with logical OR value using **AC_MENUITEM_t** constant.
<dlclass="apidl">
<dt>**Parameter**</dt>
<dd><spanclass="apidef">items</span><spanclass="apidesc">Specify the combined value of **AC_MENUITEM_t** of the items deleting from the AutoConnect menu. It provides the value calculated from the **logical OR** by the AC_MENUITEM_t value of each item. Refer to the [enableMenu](#enablemenu) about AC_MENUITEM_t.</span></dd>
You can improve your sketches by extending the AutoConnect menu by adding the legacy web pages according to the procedure described in section [*Advanced Usage*](advancedusage.md#casts-the-html-pages-to-be-add-on-into-the-menu).
AutoConnect allows capturing the extra pages handled with ESP8266WebServer or WebServer's legacy into the AutoConnect menu. See Section [*Advanced Usage*](advancedusage.md#capture-the-legacy-web-pages-as-items-into-the-menu) for detailed instructions on how to add the extra pages into its menu.