<ahref="https://Hieromon.github.io/AutoConnect/"title="AutoConnect for ESP8266/ESP32"aria-label="AutoConnect for ESP8266/ESP32"class="md-header-nav__button md-logo">
<p>Registering the "not found" handler is a different way than ESP8266WebServer (WebServer as ESP32). The <em>onNotFound</em> of ESP8266WebServer/WebServer does not work with AutoConnect. AutoConnect overrides <em>ESP8266WebServer::onNotFound</em>/<em>WebServer::onNotFound</em> to handle a captive portal. To register "not found" handler, use <ahref="api.html#onnotfound"><em>AutoConnect::onNotFound</em></a>.</p>
<h3id="access-to-saved-credentials"><iclass="fa fa-caret-right"></i> Access to saved credentials<aclass="headerlink"href="#access-to-saved-credentials"title="Permanent link">¶</a></h3>
<p>AutoConnect stores the established WiFi connection in the flash of the ESP8266/ESP32 module and equips the class to access it from the Sketch. You can read, write or erase the credentials using this class individually. It's <ahref="credit.html#autoconnectcredential">AutoConnectCredential</a> class which provides the access method to the saved credentials in the flash. Refer to section <ahref="credit.html">Saved credentials access</a> for details.</p>
<pclass="admonition-title">Where to store credentials in ESP32 with AutoConnect v1.0.0 or later</p>
<p>Since v1.0.0, credentials are stored in nvs of ESP32. AutoConnect v1.0.0 or later accesses the credentials area using the <strong>Preferences</strong> class with the arduino esp-32 core. So in ESP32, the credentials are not in the EEPROM, it is in the namespace <strong>AC_CREDT</strong> of the nvs. See <ahref="credit.html">Saved credentials access</a> for details.<br/>
In ESP8266, it is saved in EEPROM as is conventionally done.</p>
<p>AutoConnect changes WIFI mode depending on the situation. The <ahref="lsbegin.html">AutoConnect::begin</a> function starts WIFI in STA mode and starts the webserver if the connection is successful by the 1<sup>st</sup>-WiFi.begin. But if the connection fails with the least recently established access point, AutoConnect will switch the WIFI mode to AP_STA and starts the DNS server to be able to launch a captive portal.</p>
<p>When the captive portal is started, SoftAP starts and the STA is disconnected. At this point, the station configuration information that the ESP module has stored on its own (it is known as the SDK's <ahref="https://github.com/esp8266/Arduino/blob/db75d2c448bfccc6dc308bdeb9fbd3efca7927ff/tools/sdk/include/user_interface.h#L249">station_config</a> structure) is discarded.</p>
<p>AutoConnect can connect to an access point again using saved credential that has disconnected once, and its control is allowed by <ahref="apiconfig.html#autoreconnect"><strong>autoReconnect</strong></a>. <ahref="apiconfig.html#autoreconnect"><em>AutoConnectConfig::autoReconnect</em></a> option specifies to attempt to reconnect to the past established access point that stored in saved credentials. AutoConnect does not start SoftAP immediately even if 1<sup>st</sup>-WiFi.begin fails when the <ahref="apiconfig.html#autoreconnect"><strong>autoReconnct</strong></a> is enabled. It will scan the WiFi signal, and if the same BSSID as the detected BSSID is stored in flash as AutoConnect credentials, explicitly apply it and reruns WiFi.begin still WIFI_STA mode. (The autoReconnect works effectively even if the SSID is a hidden access point)</p>
<p>An <ahref="apiconfig.html#autoreconnect"><strong>autoRecconect</strong></a> option is only available for <ahref="api.html#begin"><em>AutoConnect::begin</em></a> without SSID and PASSWORD parameter.</p>
<divclass="admonition note">
<pclass="admonition-title">An autoReconnect is not autoreconnect</p>
<p>The <ahref="https://github.com/espressif/arduino-esp32/blob/a0f0bd930cfd2d607bf3d3288f46e2d265dd2e11/libraries/WiFi/src/WiFiSTA.h#L46"><em>WiFiSTAClass::disconnect</em></a> function implemented in the arduino-esp32 has extended parameters than the ESP8266's arduino-core. The second parameter of WiFi.disconnect on the arduino-esp32 core that does not exist in the <ahref="https://github.com/esp8266/Arduino/blob/7e1bdb225da8ab337373517e6a86a99432921a86/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp#L296">ESP8266WiFiSTAClass</a> has the effect of deleting the currently connected WiFi configuration and its default value is "false". On the ESP32 platform, even if WiFi.disconnect is executed, WiFi.begin() without the parameters in the next turn will try to connect to that AP. That is, automatic reconnection is implemented in arduino-esp32 already. Although this behavior appears seemingly competent, it is rather a disadvantage in scenes where you want to change the access point each time. When explicitly disconnecting WiFi from the Disconnect menu, AutoConnect will erase the AP connection settings saved by the arduino-esp32 core. AutoConnect's automatic reconnection is a mechanism independent from the automatic reconnection of the arduino-esp32 core.</p>
<p>By default, AutoConnect saves the credentials of the established connection to the flash. You can disable it with the <ahref="apiconfig.html#autosave"><strong>autoSave</strong></a> parameter specified by <ahref="apiconfig.html">AutoConnectConfig</a>.<br/>
See the <ahref="credit.html">Saved credentials access</a> chapter for details on accessing stored credentials.</p>
<p>The captive portal will only be activated if 1<sup>st</sup>-WiFi::begin 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>Basically, the captive portal launch is subject to 1<sup>st</sup>-WiFi.begin result, but Sketch can control it. The Sketch can direct the following four actions by configuring AutoConnect with two parameters, <ahref="apiconfig.html#immediatestart"><em>AutoConnectConfig::immediateStart</em></a> and <ahref="apiconfig.html#autorise"><em>AutoConnectConfig::autoRise</em></a>.</p>
<td>Skip 1st-WiFi.begin<br>ESP module becomes SoftAP and the captive portal starts immediately.<br></td>
<td>Not attempt WiFi connection.<br>Only WebServer will start in STA mode.</td>
</tr>
<tr>
<td>false</td>
<td>Attempts WiFi connection in STA mode.<br>In some cases, the autoReconnect may restore the connection even if 1st-WiFiBeing fails.<br>If the connection is completely lost, the captive portal will be launched.<br><b>This is the default.</b></td>
<td>Attempts WiFi connection in STA mode.<br>In some cases, the autoReconnect may restore the connection even if 1st-WiFiBeing fails.<br>ESP module stays in STA mode and WebServer will start.</td>
<p>Once AutoConnect has entered the captive portal state due to the above conditions, it will not exit until a WiFi connection can be established. (But that is the default behavior)</p>
<p>The Sketch can abort the <ahref="api.html#begin"><em>AutoConnect::begin</em></a> by setting the captive portal timeout and returns control to Sketch. 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 <ahref="api.html#begin"><em>AutoConnect::begin</em></a>. The default value is macro defined by <ahref="api.html#defined-macros"><strong>AUTOCONNECT_TIMEOUT</strong></a> in the <strong>AutoConnectDefs.h</strong> file.</p>
<p>The other timeout control is for the captive portal itself. It is useful when you want to continue sketch execution with offline even if the WiFi connection is not possible. You can also combine it with the <ahref="#on-demand-start-the-captive-portal"><strong>immediateStart</strong></a> option to create sketches with high mobility.</p>
<p>The timeout of the captive portal is specified together with <ahref="apiconfig.html#portaltimeout"><em>AutoConnectConfig::portalTimeout</em></a> as follows.</p>
<spanstyle="background-color: #49483e"><spanstyle="color: #f8f8f2">config.portalTimeout</span><spanstyle="color: #f92672">=</span><spanstyle="color: #ae81ff">60000</span><spanstyle="color: #f8f8f2">;</span><spanstyle="color: #75715e">// It will time out in 60 seconds</span>
Also, if you want to stop AutoConnect completely when the captive portal is timed out, you need to call the <ahref="api.html#end"><em>AutoConnect::end</em></a> function. It looks like the following code:</p>
<spanstyle="color: #f8f8f2">config.portalTimeout</span><spanstyle="color: #f92672">=</span><spanstyle="color: #ae81ff">60000</span><spanstyle="color: #f8f8f2">;</span><spanstyle="color: #75715e">// It will time out in 60 seconds</span>
<p>There is another option related to timeout in AutoConnectConfig. It can make use of the captive portal function even after a timeout. The <ahref="apiconfig.html#retainportal"><em>AutoConnectConfig::retainPortal</em></a> option will not stop the SoftAP when the captive portal is timed out. If you enable the ratainPortal option, you can try to connect to the AP at any time while continuing to sketch execution with offline even after the captive portal timed-out. Compared to the above code specified no option with the following example code, the captive portal will remain available even after a timeout without changing the logic of the Sketch.</p>
<spanstyle="color: #f8f8f2">config.portalTimeout</span><spanstyle="color: #f92672">=</span><spanstyle="color: #ae81ff">60000</span><spanstyle="color: #f8f8f2">;</span><spanstyle="color: #75715e">// It will time out in 60 seconds</span>
<h3id="casts-the-html-pages-to-be-add-on-into-the-menu"><iclass="fa fa-caret-right"></i> Casts the HTML pages to be add-on into the menu<aclass="headerlink"href="#casts-the-html-pages-to-be-add-on-into-the-menu"title="Permanent link">¶</a></h3>
<p>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 <ahref="acelements.html">AutoConnectElements</a>, this allows to legacy web pages registered by <em>ESP8266WebServer::on</em> or <em>WebServer::on</em> function.</p>
<p>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:</p>
<li>Register AutoConnectAux declared with #1 to AutoConnect using <ahref="api.html#join"><em>AutoConnect::join</em></a> function. It serves as a menu item.</li>
<h3id="change-the-menu-labels"><iclass="fa fa-caret-right"></i> Change the menu labels<aclass="headerlink"href="#change-the-menu-labels"title="Permanent link">¶</a></h3>
<p>You can change the label text for each menu item but cannot change them at run time. There are two ways to change the label text, both of which require coding the label literal.</p>
<ol>
<li>
<p>Overwrite the label literal of library source code directly.</p>
<p>You can change the label of the AutoConnect menu item by rewriting the default label literal in <ahref="https://github.com/Hieromon/AutoConnect/blob/master/src/AutoConnectLabels.h">AutoConnectLabels.h</a> macros. However, changing menu items literal influences all the Sketch's build scenes.</p>
<pclass="admonition-title"><strong>build_flags</strong> with PlatformIO will no effect</p>
<p>The mistake that many people make is to use PlatformIO's build_flags to try to redefine any literal at compile time.<br>
The AutoConnect library statically contains the label literals which are embedded as binary data when compiling the library code. The label literals will not change without compiling the library source.<br>
And PlatformIO is a build system. Library sources will not be compiled unless AutoConnectLabels.h is updated.</p>
</div>
</li>
<li>
<p>Change the label literals for each Arduino project</p>
<p>Another way to change the label literal is to provide a header file that defines the label literals, as mentioned in <ahref="changelabel.html#change-the-items-label-text">Appendix</a>. You can also use this method to display label text and fixed text in the local language on the AutoConnect page. See <ahref="changelabel.html#change-the-items-label-text"><strong>Appendix:Change the item's label text</strong></a> for details.</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>
<h3id="connects-depending-on-the-wifi-signal-strength"><iclass="fa fa-caret-right"></i> Connects depending on the WiFi signal strength<aclass="headerlink"href="#connects-depending-on-the-wifi-signal-strength"title="Permanent link">¶</a></h3>
<p>When the ESP module found the multiple available access points (ie. AutoConnect has connected in the past), the default behavior AutoConnect will attempt to connect to the least recent one. However, If the ESP module can operate properly with any access point, it is advantageous to establish a connection with the best one of the reception sensitivity. </p>
<p>The <ahref="apiconfig.html#principle"><em>AutoConnectConfig::principle</em></a> parameter has the connection disposition, and specifying <strong>AC_PRINCIPLE_RSSI</strong> will attempt to connect to one of the highest RSSI value among multiple available access points. Also You can expect stable WiFi connection by specifying the lower limit of signal strength using <ahref="apiconfig.html#minrssi"><em>AutoConnectConfig::minRSSI</em></a>.<br/>
Combining these two parameters allows you to filter the destination AP when multiple available access points are found.</p>
<p><ahref="apiconfig.html#principle"><em>AutoConnectConfig::principle</em></a> affects the behavior of both 1<sup>st</sup>-WiFi.begin and <ahref="advancedusage.html#automatic-reconnect"><strong>autoReconnect</strong></a>. If you specify <strong>AC_PRINCIPLE_RECENT</strong> for the <ahref="apiconfig.html#principle"><strong>principle</strong></a>, it will try according to the conventional connection rules, but if you specify <strong>AC_PRINCIPLE_RSSI</strong>, it will try to connect to the access point that is sending the strongest WiFi signal at that time instead of the last accessed AP. Also, the static IPs will be restored from a saved credential instead of AutoConnectConfig. (The values specified by AutoConnectConfig is ignored)</p>
<p>You can output AutoConnect monitor messages to the <strong>Serial</strong>. A monitor message activation switch is in an include header file <ahref="https://github.com/Hieromon/AutoConnect/blob/master/src/AutoConnectDefs.h">AutoConnectDefs.h</a> of library source. Define <ahref="https://github.com/Hieromon/AutoConnect/blob/master/src/AutoConnectDefs.h#L14"><strong>AC_DEBUG</strong></a> macro to output the monitor messages.<supid="fnref:1"><aclass="footnote-ref"href="#fn:1">1</a></sup></p>
<p>It can also prevent the captive portal from starting even if the connection at the 1<sup>st</sup>-WiFi.begin fails. In this case, <ahref="api.html#begin"><em>AutoConnect::begin</em></a> behaves same as <em>WiFi.begin</em>.</p>
<p>For disabling the captive portal, <ahref="apiconfig.html#autorise"><strong>autoRise</strong></a> sets to false with <ahref="apiconfig.html">AutoConnectConfig</a>.</p>
<h3id="make-ssid-of-softap-unique"><iclass="fa fa-caret-right"></i> Make SSID of SoftAP unique<aclass="headerlink"href="#make-ssid-of-softap-unique"title="Permanent link">¶</a></h3>
<p>You can change SoftAP's SSID and password programmatically when the captive portal starts up. By using chip specific ID of esp8266/esp32 you can make SSID of SoftAP unique. SSID and password for SoftAP is <ahref="apiconfig.html#apid"><em>AutoConnectConfig::apid</em></a> and <ahref="apiconfig.html#psk"><em>AutoConnectConfig::psk</em></a>.</p>
<p>The <ahref="lsbegin.html">default behavior of AutoConnect::begin</a> gives priority to connect to the least recently established access point. In general, We expect this behavior in most situations, but will intentionally launch the captive portal on some occasion.</p>
<p>Here section describes how to launch on demand the captive portal, and suggests two templates that you can use to implement it.</p>
<ol>
<li>
<p>Offline for usual operation, connect to WiFi with an external switch</p>
<p>You can use this template if the ESP module does not connect to WiFi at an ordinal situation and need to establish by a manual trigger. In this case, it is desirable that AutoConnect not start until an external switch fires. This behavior is similar to the <ahref="https://github.com/tzapu/WiFiManager#on-demand-configuration-portal">WiFiManager's startConfigPortal</a> function.<br/>
<ahref="apiconfig.html#immediatestart"><em>AutoConnectConfig::immediateStart</em></a> is an option to launch the portal by the SoftAP immediately without attempting 1<sup>st</sup>-WiFi.begin. Also, by setting the <ahref="apiconfig.html#autorise"><em>AutoConnectConfig::autoRise</em></a> option to false, it is possible to suppress unintended automatic pop-ups of the portal screen when connecting to an ESP module SSID.<br/>
To implement this, execute AutoConnect::config within the <strong>setup()</strong> function as usual, and handle AutoConnect::begin inside the <strong>loop()</strong> function.</p>
</span><spanstyle="color: #75715e">// Config.autoRise = false; // If you don't need to automatically pop-up the portal when connected to the ESP module's SSID.</span>
<pclass="admonition-title">It will not be automatic reconnect</p>
<p>The above example does not connect to WiFi until TRIGGER_PIN goes LOW. When TRIGGER_PIN goes LOW, the captive portal starts and you can connect to WiFi. Even if you reset the module, it will not automatically reconnect.</p>
</div>
</li>
<li>
<p>Register new access points on demand</p>
<p>The following template is useful for controlling the registration of unknown access points. In this case, the ESP module establishes a WiFi connection using WiFi.begin natively without relying on AutoConnect.<br/>
Known access point credentials are saved by AutoConnect, to the ESP module can use the saved credentials to handle WiFi.begin natively. This means that you can explicitly register available access points when needed, and the ESP module will not use unknown access points under normal situations.</p>
<p>Constructing an AutoConnect object variable without parameters then creates and starts an ESP8266WebServer/WebServer inside the AutoConnect. This object variable could be referred by <ahref="api.html#host"><em>AutoConnect::host</em></a> function to access ESP8266WebServer/WebServer instance as like below.</p>
<p>The Sketch can handle URL requests using ESP8266WebServer or WebServer that AutoConnect started internally. ESP8266WebServer/WebServer instantiated dynamically by AutoConnect can be referred to by <ahref="api.html#host"><em>AutoConnect::host</em></a> function. The Sketch can use the '<strong>on</strong>' function, '<strong>send</strong>' function, '<strong>client</strong>' function and others by ESP8266WebServer/WebServer reference of its return value.</p>
<pclass="admonition-title">Do not use with ESP8266WebServer::begin or WebServer::begin</p>
<p>ESP8266WebServer/WebServer is already running inside the AutoConnect.</p>
</div>
<h3id="use-with-the-pagebuilder-library"><iclass="fa fa-caret-right"></i> Use with the <ahref="https://github.com/Hieromon/PageBuilder">PageBuilder</a> library<aclass="headerlink"href="#use-with-the-pagebuilder-library"title="Permanent link">¶</a></h3>
<p>In ordinary, the URL handler will respond the request by sending some HTML. <ahref="https://github.com/Hieromon/PageBuilder">PageBuilder</a> library is HTML assembly aid. it can handle predefined HTML as like a template and simplify an HTML string assemble logic, and also the generated HTML send automatically.</p>
<p>An example sketch used with the PageBuilder as follows and it explains how it aids for the HTML generating. Details for <ahref="https://github.com/Hieromon/PageBuilder">Github repository</a>.</p>
<p>You can adjust the AutoConnect behave at run-time using <ahref="apiconfig.html">AutoConnectConfig</a>. AutoConnectConfig is a class that has only AutoConnect configuration data. You define the behavior of AutoConnect using AutoConnectConfig member variables and give it to AutoConnect via the <ahref="api.html#config">AutoConnect::config</a> function.</p>
<p>AutoConnectConfig can specify the following runtime behavior:</p>
<pclass="admonition-title">AutoConnect::config before AutoConnect::begin</p>
<p><em>AutoConnect::config</em> must be executed before <em>AutoConnect::begin</em>.</p>
</div>
<h3id="assign-user-sketchs-home-path"><iclass="fa fa-caret-right"></i> Assign user sketch's home path<aclass="headerlink"href="#assign-user-sketchs-home-path"title="Permanent link">¶</a></h3>
<p><strong>HOME</strong> for returning to the user's sketch homepage will display at the bottom of the AutoConnect menu. It could be set using the <ahref="api.html#home"><em>AutoConnect::home</em></a> function.</p>
<p>The Sketch HOME path is closely related to the <ahref="apiconfig.html#booturi">bootUri</a> that specifies the access path on module restart. AutoConnect has the following three parameters concerning control the URIs:</p>
The <strong>ROOT</strong> of AutoConnect. It is defined in <code>AutoConnectDefs.h</code> and is assigned an <ahref="menu.html#where-the-from">AutoConnect statistics screen</a> by default.</li>
Which page appears at the captive portal, AUTOCONNECT_URI or the homeUri. Its page will pop up automatically when you visit the captive portal.</li>
</ul>
<table>
<thead>
<tr>
<th>The definition of <strong>HOME</strong></th>
<th>Behavior</th>
<th>Specified by</th>
<th>Default value</th>
<th>Possible value</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>ROOT</strong> of AutoConnect</td>
<td>Default for AC_ONBOOTURI_ROOT</td>
<td><code>#define AUTOCONNECT_URI</code> in <code>AutoConnectDefs.h</code></td>
<td><code>/_ac</code></td>
<td>URI string</td>
</tr>
<tr>
<td><strong>HOME</strong> for Application-specific</td>
<td>Listed on the <strong>menu list</strong> as <strong>HOME</strong><br>Also, It may be linked from the <strong>menu title</strong> and is <strong>redundant</strong> with the HOME menu item.<br>eg. Case of bootURI = AC_ONBOOTURI_HOME</td>
<td>AutoConnectConfig::homeURI</td>
<td><code>/</code></td>
<td>URI string</td>
</tr>
<tr>
<td>Which page <strong>loads</strong> at the boot time, ROOT or HOME</td>
<td>Appears after module reboot by <strong>RESET</strong> button with AutoConnect menu</td>
<td>AutoConnectConfig::bootURI</td>
<td>AC_ONBOOTURI_ROOT</td>
<td>AC_ONBOOTURI_HOME</td>
</tr>
<tr>
<td>Which page <strong>appears</strong> at the captive portal, ROOT or HOME</td>
<td>Auto pop-up</td>
<td>AutoConnectConfig::bootURI</td>
<td>AC_ONBOOTURI_ROOT</td>
<td>AC_ONBOOTURI_HOME</td>
</tr>
</tbody>
</table>
<h3id="built-in-ota-update-feature"><iclass="fa fa-caret-right"></i> Built-in OTA update feature<aclass="headerlink"href="#built-in-ota-update-feature"title="Permanent link">¶</a></h3>
<p>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.</p>
<p><ahref="apiconfig.html#ota"><em>AutoConnectConfig::ota</em></a> specifies to import the <ahref="otabrowser.html">built-in OTA update class</a> into the Sketch.<br/>
See the <ahref="otabrowser.html">Updates with the Web Browser</a> chapter for details.</p>
<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"><em>AutoConnectConfig::title</em></a>. To set the menu title properly, you must set before calling <ahref="api.html#begin"><em>AutoConnect::begin</em></a>.</p>
<h3id="change-ssid-and-password-for-softap"><iclass="fa fa-caret-right"></i> Change SSID and Password for SoftAP<aclass="headerlink"href="#change-ssid-and-password-for-softap"title="Permanent link">¶</a></h3>
<p>An <strong>esp8266ap</strong> is default SSID name for SoftAP of captive portal and password is <strong>12345678</strong> for ESP8266. Similarly, <strong>esp32ap</strong> and <strong>12345678</strong> for ESP32. You can change both by setting <ahref="apiconfig.html#apid">apid</a> and <ahref="apiconfig.html#psk">psk</a>.</p>
<p>You can also assign no password to SoftAP launched as a captive portal. Assigning a null string as <code>String("")</code> to <ahref="apiconfig.html#psk"><em>AutoConnectConfig::psk</em></a> does not require a password when connecting to SoftAP.<br/>
<h3id="configuration-for-soft-ap-and-captive-portal"><iclass="fa fa-caret-right"></i> Configuration for Soft AP and captive portal<aclass="headerlink"href="#configuration-for-soft-ap-and-captive-portal"title="Permanent link">¶</a></h3>
<p>AutoConnect will activate SoftAP at failed the 1<sup>st</sup>-WiFi.begin. It SoftAP settings are stored in <ahref="apiconfig.html#autoconnectconfig"><strong>AutoConnectConfig</strong></a> as the following parameters. The Sketch could be configured SoftAP using these parameters, refer the <ahref="apiconfig.html#public-member-variables">AutoConnectConfig API</a> for details.</p>
<p>Appropriately specifying the WiFi channel to use for ESP8266 and ESP32 is essential for a stable connection with the access point. AutoConnect remembers the WiFi channel with a credential of the access point once connected and reuses it.</p>
<p>The default channel when a captive portal starts and AutoConnect itself becomes an access point is the <ahref="apiconfig.html#channel"><em>AutoConnectConfig::channel</em></a> member. If this channel is different from the channel of the access point you will attempt to connect, WiFi.begin may fail. The cause is that the ESP module shares the same channel in AP mode and STA mode. If the connection attempt is not stable, specifying a proper channel using AutoConnectConfig::channel may result in a stable connection.</p>
<h3id="move-the-saving-area-of-eeprom-for-the-credentials"><iclass="fa fa-caret-right"></i> Move the saving area of EEPROM for the credentials<aclass="headerlink"href="#move-the-saving-area-of-eeprom-for-the-credentials"title="Permanent link">¶</a></h3>
<p>By default, the credentials saving area is occupied from the beginning of EEPROM area. <ahref="http://arduino-esp8266.readthedocs.io/en/latest/filesystem.html?highlight=eeprom#flash-layout">ESP8266 Arduino core document</a> says that:</p>
<blockquote>
<p>The following diagram illustrates flash layout used in Arduino environment:</p>
<p>EEPROM library uses one sector of flash located <ahref="http://arduino-esp8266.readthedocs.io/en/latest/libraries.html?highlight=SPIFFS#eeprom">just after the SPIFFS</a>.</p>
</blockquote>
<p>Also, in ESP32 arduino core 1.0.2 earlier, the placement of the EEPROM area of ESP32 is described in the <ahref="https://github.com/espressif/arduino-esp32/blob/master/tools/partitions/default.csv">partition table</a>. So in the default state, the credential storage area used by AutoConnect conflicts with data owned by the user sketch. It will be destroyed together saved data in EEPROM by user sketch and AutoConnect each other. But you can move the storage area to avoid this.</p>
<p>The <ahref="apiconfig.html#boundaryoffset"><strong>boundaryOffset</strong></a> in <ahref="apiconfig.html">AutoConnectConfig</a> specifies the start offset of the credentials storage area. The default value is 0.</p>
<divclass="admonition info">
<pclass="admonition-title">The boundaryOffset ignored with AutoConnect v1.0.0 later on ESP32 arduino core 1.0.3 later</p>
<p>For ESP32 arduino core 1.0.3 and later, AutoConnect will store credentials to Preferences in the nvs. Since it is defined as the namespace dedicated to AutoConnect and separated from the area used for user sketches. Therefore, the <ahref="apiconfig.html#boundaryoffset">boundaryOffset</a> is ignored with the combination of AutoConnect v1.0.0 or later and the arduino-esp32 1.0.3 or later.</p>
<h3id="relocate-the-autoconnect-home-path"><iclass="fa fa-caret-right"></i> Relocate the AutoConnect home path<aclass="headerlink"href="#relocate-the-autoconnect-home-path"title="Permanent link">¶</a></h3>
<p>A home path of AutoConnect is <strong>/_ac</strong> by default. You can access from the browser with <ahref="http://IPADDRESS/">http://IPADDRESS/</a>_ac. You can change the home path by revising <ahref="https://github.com/Hieromon/AutoConnect/blob/master/src/AutoConnectDefs.h#L69"><strong>AUTOCONNECT_URI</strong></a> macro in the include header file as <ahref="https://github.com/Hieromon/AutoConnect/blob/master/src/AutoConnectDefs.h">AutoConnectDefs.h</a>.</p>
<p>It is also possible to assign static IP Address to ESP8266/ESP32 in STA mode. By default DHCP is enabled and it becomes the IP address assigned by the DHCP server with <em>WiFi.begin</em>.</p>
<p>To assign a static IP to ESP8266/ESP32 with WIFI_MODE_STA, the following parameters are required:</p>
<p><ahref="apiconfig.html#hostname"><em>AutoConnectConfig::hostName</em></a> assigns the station DHCP hostname which complies with <ahref="https://tools.ietf.org/html/rfc952">RFC952</a>. It must satisfy the following constraints.</p>
<h3id="ticker-for-wifi-status"><iclass="fa fa-caret-right"></i> Ticker for WiFi status<aclass="headerlink"href="#ticker-for-wifi-status"title="Permanent link">¶</a></h3>
<p>Flicker signal can be output from the ESP8266/ESP32 module according to WiFi connection status. If you connect the LED to the signal output pin, you can know the WiFi connection status during behavior inside AutoConnect::begin through the LED blink.</p>
<p><ahref="apiconfig.html#ticker"><em>AutoConnectConfig::ticker</em></a> option specifies flicker signal output. The following sketch is an example of flashing the active-high LED connected to pin #16 according to WiFi connection during the AutoConnect::begin.</p>
<p><ahref="apiconfig.html#tickerport"><em>AutoConnectConfig::tickerPort</em></a> specifies a port that outputs the flicker signal. If you are using an LED-equipped ESP module board, you can assign a LED pin to the tick-port for the WiFi connection monitoring without the external LED. The default pin is arduino valiant's <strong>LED_BUILTIN</strong>. You can refer to the Arduino IDE's variant information to find out which pin actually on the module assign to <strong>LED_BUILTIN</strong>.<supid="fnref:3"><aclass="footnote-ref"href="#fn:3">3</a></sup></p>
<p><ahref="apiconfig.html#tickeron"><em>AutoConnectConfig::tickerOn</em></a> specifies the active logic level of the flicker signal. This value indicates the active signal level when driving the ticker. For example, if the LED connected to tickPort lights by LOW, the tickerOn is <strong>LOW</strong>. The logic level of LED_BUILTIN for popular modules are as follows:</p>
<p>The source code placement of common macros for AutoConnect since v0.9.7 has changed. <aclass="footnote-backref"href="#fnref:1"title="Jump back to footnote 1 in the text">↩</a></p>
<p>Static IP address assignment is available from version 0.9.3. <aclass="footnote-backref"href="#fnref:2"title="Jump back to footnote 2 in the text">↩</a></p>
<p>It's defined in the <code>pins_arduino.h</code> file, located in the sub-folder named <strong>variants</strong> wherein Arduino IDE installed folder. <aclass="footnote-backref"href="#fnref:3"title="Jump back to footnote 3 in the text">↩</a></p>