diff --git a/README.md b/README.md index fb13f97..0ee9939 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,7 @@ Full documentation is available on https://Hieromon.github.io/AutoConnect, some - Changed the bootUri behavior to be an automatic pop-up at the captive portal. (PR #181) - Supports AutoConnect menu configuration. - Supports the built-in OTA feature. +- Supports an attempt order when available APs would be found multiple, and RSSI lower bound on AP signal strength. This option can specify the order of connection attempting according to the WiFi signal strength indicated with RSSI. (PR #187) ### [1.1.4] Feb. 14, 2020 - Supports for overriding text of the menu items with user-defined labels. diff --git a/examples/Elements/Elements.ino b/examples/Elements/Elements.ino index f8f6cfb..45e3d9f 100644 --- a/examples/Elements/Elements.ino +++ b/examples/Elements/Elements.ino @@ -58,7 +58,7 @@ static const char PAGE_ELEMENTS[] PROGMEM = R"( "value": [ "Button-1", "Button-2", - "Butotn-3" + "Button-3" ], "label": "Radio buttons", "arrange": "vertical", diff --git a/mkdocs/advancedusage.md b/mkdocs/advancedusage.md index e3fb4c2..c5175a1 100644 --- a/mkdocs/advancedusage.md +++ b/mkdocs/advancedusage.md @@ -14,11 +14,11 @@ AutoConnect stores the established WiFi connection in the flash of the ESP8266/E ### Automatic reconnect -When the captive portal is started, SoftAP starts and the STA is disconnected. The current SSID setting memorized in ESP8266 will be lost but then the reconnect behavior of ESP32 is somewhat different from this. +AutoConnect changes WIFI mode depending on the situation. The [AutoConnect::begin](lsbegin.md) function starts WIFI in STA mode and starts the webserver if the connection is successful by the 1st-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. -The [*WiFiSTAClass::disconnect*](https://github.com/espressif/arduino-esp32/blob/a0f0bd930cfd2d607bf3d3288f46e2d265dd2e11/libraries/WiFi/src/WiFiSTA.h#L46) 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 [ESP8266WiFiSTAClass](https://github.com/esp8266/Arduino/blob/7e1bdb225da8ab337373517e6a86a99432921a86/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp#L296) 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 arduino-esp32 core. AutoConnect's automatic reconnection is a mechanism independent from the automatic reconnection of the arduino-esp32 core. +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 [station_config](https://github.com/esp8266/Arduino/blob/db75d2c448bfccc6dc308bdeb9fbd3efca7927ff/tools/sdk/include/user_interface.h#L249) structure) is discarded. -If the [**autoReconnect**](apiconfig.md#autoreconnect) option of the [AutoConnectConfig](apiconfig.md) class is enabled, it automatically attempts to reconnect to the disconnected past access point. When the autoReconnect option is specified, AutoConnect will not start SoftAP immediately if the first WiFi.begin fails. It will scan WiFi signal and the same connection information as the detected BSSID is stored in the flash as AutoConnect's credentials, explicitly apply it with WiFi.begin and rerun. +AutoConnect can connect to an access point again using saved credential that has disconnected once, and its control is allowed by [**autoReconnect**](apiconfig.md#autoreconnect). [*AutoConnectConfig::autoReconnect*](apiconfig.md#autoreconnect) 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 1st-WiFi.begin fails when the [**autoReconnct**](apiconfig.md#autoreconnect) 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) ```cpp hl_lines="3" AutoConnect Portal; @@ -28,12 +28,13 @@ Portal.config(Config); Portal.begin(); ``` -An autoReconnect option is available to *AutoConnect::begin* without SSID and pass Passphrase. +An [**autoRecconect**](apiconfig.md#autoreconnect) option is only available for [*AutoConnect::begin*](api.md#begin) without SSID and PASSWORD parameter. -!!! caution "An autoReconnect will work if SSID detection succeeded" - An autoReconnect will not effect if the SSID which stored credential to be connected is a hidden access point. +!!! note "An autoReconnect is not autoreconnect" + The [*WiFiSTAClass::disconnect*](https://github.com/espressif/arduino-esp32/blob/a0f0bd930cfd2d607bf3d3288f46e2d265dd2e11/libraries/WiFi/src/WiFiSTA.h#L46) 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 [ESP8266WiFiSTAClass](https://github.com/esp8266/Arduino/blob/7e1bdb225da8ab337373517e6a86a99432921a86/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp#L296) 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. + -### Auto save Credential +### Autosave Credential By default, AutoConnect saves the credentials of the established connection to the flash. You can disable it with the [**autoSave**](apiconfig.md#autosave) parameter specified by [AutoConnectConfig](apiconfig.md). See the [Saved credentials access](credit.md) chapter for details on accessing stored credentials. @@ -244,40 +245,34 @@ void loop() { For more details, see section [Constructing the menu](menuize.md) of Examples page. -### 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 for the **FSBrowser** as the below. - -
- - ### Change the menu labels -You can change the label of the AutoConnect menu item by rewriting the default label letter in [AutoConnectLabels.h](https://github.com/Hieromon/AutoConnect/blob/master/src/AutoConnectLabels.h) macros. However, changing menu items letter influences all build scenes for the Sketch. - -```cpp -#define AUTOCONNECT_MENULABEL_CONFIGNEW "Configure new AP" -#define AUTOCONNECT_MENULABEL_OPENSSIDS "Open SSIDs" -#define AUTOCONNECT_MENULABEL_DISCONNECT "Disconnect" -#define AUTOCONNECT_MENULABEL_RESET "Reset..." -#define AUTOCONNECT_MENULABEL_HOME "HOME" -#define AUTOCONNECT_BUTTONLABEL_RESET "RESET" -``` -See also: [*Change label text*](changelabel.md) +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. + +1. Overwrite the label literal of library source code directly. + + You can change the label of the AutoConnect menu item by rewriting the default label literal in [AutoConnectLabels.h](https://github.com/Hieromon/AutoConnect/blob/master/src/AutoConnectLabels.h) macros. However, changing menu items literal influences all the sketch's build scenes. + + ```cpp + #define AUTOCONNECT_MENULABEL_CONFIGNEW "Configure new AP" + #define AUTOCONNECT_MENULABEL_OPENSSIDS "Open SSIDs" + #define AUTOCONNECT_MENULABEL_DISCONNECT "Disconnect" + #define AUTOCONNECT_MENULABEL_RESET "Reset..." + #define AUTOCONNECT_MENULABEL_UPDATE "Update" + #define AUTOCONNECT_MENULABEL_HOME "HOME" + #define AUTOCONNECT_MENULABEL_DEVINFO "Device info" + #define AUTOCONNECT_BUTTONLABEL_RESET "RESET" + #define AUTOCONNECT_BUTTONLABEL_UPDATE "UPDATE" + ``` + + !!! note "**build_flags** with PlatformIO will no effect" + The mistake that many people make is to use PlatformIO's build_flags to try to redefine any literal at compile time.
+ 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.
+ And PlatformIO is a build system. Library sources will not be compiled unless AutoConnectLabels.h is updated. + +2. Change the label literals for each Arduino project + + Another way to change the label literal is to provide a header file that defines the label literals, as mentioned in [Appendix](changelabel.md#change-the-items-label-text). You can also use this method to display label text and fixed text in the local language on the AutoConnect page. See [**Appendix:Change the item's label text**](changelabel.md#change-the-items-label-text) for details. ### Combination with mDNS @@ -302,6 +297,56 @@ void loop() { } ``` +### Connects depending on the WiFi signal strength + +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. + +The [*AutoConnectConfig::principle*](apiconfig.md#principle) parameter has the connection disposition, and specifying **AC_PRINCIPLE_RSSI** 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 [*AutoConnectConfig::minRSSI*](apiconfig.md#minrssi). +Combining these two parameters allows you to filter the destination AP when multiple available access points are found. + +[*AutoConnectConfig::principle*](apiconfig.md#principle) affects the behavior of both 1st-WiFi.begin and [**autoReconnect**](advancedusage.md#automatic-reconnect). If you specify **AC_PRINCIPLE_RECENT** for the [**principle**](apiconfig.md#principle), it will try according to the conventional connection rules, but if you specify **AC_PRINCIPLE_RSSI**, 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) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SSID &
Password
AutoConnectConfig
::principle
Which credentials would be selectedStatic IPs
AutoConnect
::begin
NULL specifiedAC_PRINCIPLE_RECENTNothing, depends on SDK savesUse the specified value of AutoConnectConfig
AC_PRINCIPLE_RSSIAuto-selected credentials with max RSSIRestoring static IPs suitable for the SSID from saved credentials
Specified with the sketchNot efectiveBy AutoConnect::begin parametersUse the specified value of AutoConnectConfig
AutoReconnectLoad from
saved credential
AC_PRINCIPLE_RECENTRecently saved SSID would be chosenRestoring static IPs suitable for the SSID from saved credentials
AC_PRINCIPLE_RSSIAuto-selected credentials with max RSSI
+ ### Debug print You can output AutoConnect monitor messages to the **Serial**. A monitor message activation switch is in an include header file [AutoConnectDefs.h](https://github.com/Hieromon/AutoConnect/blob/master/src/AutoConnectDefs.h) of library source. Define [**AC_DEBUG**](https://github.com/Hieromon/AutoConnect/blob/master/src/AutoConnectDefs.h#L14) macro to output the monitor messages.[^1] @@ -344,54 +389,112 @@ portal.begin(); !!! hint "Obtaining chip ID for ESP32" `acConfig.apid = "ESP-" + String((uint32_t)(ESP.getEfuseMac() >> 32), HEX);` -### Move the saving area of EEPROM for the credentials +### On-demand start the captive portal -By default, the credentials saving area is occupied from the beginning of EEPROM area. [ESP8266 Arduino core document](http://arduino-esp8266.readthedocs.io/en/latest/filesystem.html?highlight=eeprom#flash-layout) says that: +The [default behavior of AutoConnect::begin](lsbegin.md) 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. +Here section describes how to launch on demand the captive portal, and suggests two templates that you can use to implement it. -> The following diagram illustrates flash layout used in Arduino environment: +1. Offline for usual operation, connect to WiFi with an external switch -> ```powershell -> |--------------|-------|---------------|--|--|--|--|--| -> ^ ^ ^ ^ ^ -> Sketch OTA update File system EEPROM WiFi config (SDK) -> ``` + 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 [WiFiManager's startConfigPortal](https://github.com/tzapu/WiFiManager#on-demand-configuration-portal) function. + [*AutoConnectConfig::immediateStart*](apiconfig.md#immediatestart) is an option to launch the portal by the SoftAP immediately without attempting 1st-WiFi.begin. Also, by setting the [*AutoConnectConfig::autoRise*](apiconfig.md#autorise) option to false, it is possible to suppress unintended automatic pop-ups of the portal screen when connecting to an ESP module SSID. + To implement this, execute AutoConnect::config within the **setup()** function as usual, and handle AutoConnect::begin inside the **loop()** function. -and + ```cpp hl_lines="9" + #define TRIGGER_PIN 5 // Trigger switch should be LOW active. + #define HOLD_TIMER 3000 -> EEPROM library uses one sector of flash located [just after the SPIFFS](http://arduino-esp8266.readthedocs.io/en/latest/libraries.html?highlight=SPIFFS#eeprom). + AutoConnect Portal; + AutoConnectConfig Config; -Also, in ESP32 arduino core 1.0.2 earlier, the placement of the EEPROM area of ESP32 is described in the [partition table](https://github.com/espressif/arduino-esp32/blob/master/tools/partitions/default.csv). 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. + void setup() { + pinMode(5, INPUT_PULLUP); + Config.immediateStart = true; + // Config.autoRise = false; // If you don't need to automatically pop-up the portal when connected to the ESP module's SSID. + Portal.config(Config); + } -The [**boundaryOffset**](apiconfig.md#boundaryoffset) in [AutoConnectConfig](apiconfig.md) specifies the start offset of the credentials storage area. The default value is 0. + void loop() { + if (digitalRead(TRIGGER_PIN) == LOW) { + unsigned long tm = millis(); + while (digitalRead(TRIGGER_PIN) == LOW) { + yield(); + } + // Hold the switch while HOLD_TIMER time to start connect. + if (millis() - tm > HOLD_TIMER) + Portal.begin(); + } -!!! info "The boundaryOffset ignored with AutoConnect v1.0.0 later on ESP32 arduino core 1.0.3 later" - 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 [boundaryOffset](apiconfig.md#boundaryoffset) is ignored with the combination of AutoConnect v1.0.0 or later and the arduino-esp32 1.0.3 or later. + if (WiFi.status() == WL_CONNECTED) { + // Here, what to do if the module has connected to a WiFi access point + } -### On-demand start the captive portal + // Main process of your sketch -If you do not usually connect to WiFi and need to establish a WiFi connection if necessary, you can combine the [**autoRise**](apiconfig.md#autorise) option with the [**immediateStart**](apiconfig.md#immediatestart) option to achieve on-demand connection. This behavior is similar to the [WiFiManager's startConfigPortal](https://github.com/tzapu/WiFiManager#on-demand-configuration-portal) function. In order to do this, you usually configure only with AutoConnectConfig in *setup()* and [*AutoConnect::begin*](api.md#begin) handles in *loop()*. + Portal.handleClient(); // If WiFi is not connected, handleClient will do nothing. + } + ``` -```cpp hl_lines="5 6" -AutoConnect Portal; -AutoConnectConfig Config; + !!! note "It will not be automatic reconnect" + 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. -void setup() { - Config.autoRise = false; - Config.immediateStart = true; - Portal.config(Config); -} +2. Register new access points on demand -void loop() { - if (digitalRead(TRIGGER_PIN) == LOW) { - while (digitalRead(TRIGGER_PIN) == LOW) - yield(); - Portal.begin(); - } - Portal.handleClient(); -} -``` -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. + 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. + 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. + + ```cpp + AutoConnect* portal = nullptr; + + bool detectSwitch() { + /* + Returns true if an external switch to configure is active. + */ + } + + bool connectWiFi(const char* ssid, const char* password, unsigned long timeout) { + WiFi.mode(WIFI_STA); + delay(100); + WiFi.begin(ssid, password); + unsigned long tm = millis(); + while (WiFi.status() != WL_CONNECTED) { + if (millis() - tm > timeout) + return false; + } + return true; + } + + void setup() { + AutoConnectCredential credt; + station_config_t config; + for (int8_t e = 0; e < credt.entries(); e++) { + credt.load(e, &config); + if (connectWiFi(config.ssid, config.password, 30000)) + break; + } + if (WiFi.status() != WL_CONNECTED) { + // Here, do something when WiFi cannot reach. + } + } + + void loop() { + if (detectSwitch()) { + AutoConnectConfig config; + config.immediateStart= true; + if (!portal) { + portal = new AutoConnect; + } + portal->config(config); + if (portal->begin()) { + portal->end(); + delete portal; + portal = nullptr; + } + } + // Here, ordinally sketch logic. + } + ``` ### Refers the hosted ESP8266WebServer/WebServer @@ -463,31 +566,21 @@ An example sketch used with the PageBuilder as follows and it explains how it ai ## Configuration functions -### Configuration for Soft AP and captive portal +You can adjust the AutoConnect behave at run-time using [AutoConnectConfig](apiconfig.md). 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 [AutoConnect::config](api.md#config) function. -AutoConnect will activate SoftAP at failed the first *WiFi.begin*. It SoftAP settings are stored in [**AutoConnectConfig**](apiconfig.md#autoconnectconfig) as the following parameters. The sketch could be configured SoftAP using these parameters, refer the [AutoConnectConfig API](apiconfig.md#public-member-variables) for details. +AutoConnectConfig can specify the following runtime behavior: -- IP address of SoftAP activated. -- Gateway IP address. -- Subnet mask. -- SSID for SoftAP. -- Password for SoftAP. -- Channel. -- SoftAP name. -- Hidden attribute. -- Station hostname. -- Auto save credential. -- Offset address of the credentials storage area in EEPROM. -- Captive portal time out limit. -- Maintain portal function even after a timeout. -- Length of start up time after reset. -- Automatic starting the captive portal. -- Start the captive portal forcefully. -- Auto reset after connection establishment. -- Home URL of the user sketch application. -- Menu title. -- Ticker signal output. -- Built-in OTA update. +- [Assign user sketch's home path](#assign-user-sketchs-home-path) +- [Built-in OTA update](#built-in-ota-update-feature) +- [Change menu title](#change-menu-title) +- [Change SSID and Password for SoftAP](#change-ssid-and-password-for-softap) +- [Configuration for Soft AP and captive portal](#configuration-for-soft-ap-and-captive-portal) +- [Configure WiFi channel](#configure-wifi-channel) +- [Move the saving area of EEPROM for the credentials](#move-the-saving-area-of-eeprom-for-the-credentials) +- [Relocate the AutoConnect home path](#relocate-the-autoconnect-home-path) +- [Static IP assignment](#static-ip-assignment-2) +- [Station host name](#station-host-name) +- [Ticker for WiFi status](#ticker-for-wifi-status) !!! note "AutoConnect::config before AutoConnect::begin" *AutoConnect::config* must be executed before *AutoConnect::begin*. @@ -514,6 +607,36 @@ The sketch HOME path is closely related to the [bootUri](apiconfig.md#booturi) t | Which page **loads** at the boot time, ROOT or HOME | Appears after module reboot by **RESET** button with AutoConnect menu | AutoConnectConfig::bootURI | AC_ONBOOTURI_ROOT | AC_ONBOOTURI_HOME | | Which page **appears** at the captive portal, ROOT or HOME | Auto pop-up | AutoConnectConfig::bootURI | AC_ONBOOTURI_ROOT | AC_ONBOOTURI_HOME | +### Built-in OTA update feature + +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. + + + +[AutoConnectConfig::ota](apiconfig.md#ota) specifies to import the [built-in OTA update class](otabrowser.md) into the Sketch. +See the [Updates with the Web Browser](otabrowser.md) chapter for details. + +### 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 for the **FSBrowser** as the below. + +
+ + ### Change SSID and Password for SoftAP An **esp8266ap** is default SSID name for SoftAP of captive portal and password is **12345678** for ESP8266. Similarly, **esp32ap** and **12345678** for ESP32. You can change both by setting [apid](apiconfig.md#apid) and [psk](apiconfig.md#psk). @@ -542,9 +665,43 @@ void setup() { } ``` -You can also assign no password to SoftAP launched as a captive portal. Assigning a null string as `String("")` to [AutoConnectConfig::psk](apiconfig.md#psk) does not require a password when connecting to SoftAP. +You can also assign no password to SoftAP launched as a captive portal. Assigning a null string as `String("")` to [*AutoConnectConfig::psk*](apiconfig.md#psk) does not require a password when connecting to SoftAP. But this method is not recommended. The broadcast radio of SSID emitted from SoftAP will leak and reach several tens of meters. +### Configuration for Soft AP and captive portal + +AutoConnect will activate SoftAP at failed the first *WiFi.begin*. It SoftAP settings are stored in [**AutoConnectConfig**](apiconfig.md#autoconnectconfig) as the following parameters. The sketch could be configured SoftAP using these parameters, refer the [AutoConnectConfig API](apiconfig.md#public-member-variables) for details. + +### Configure WiFi channel + +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. + +The default channel when a captive portal starts and AutoConnect itself becomes an access point is the [*AutoConnectConfig::channel*](apiconfig.md#channel) 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. + +### Move the saving area of EEPROM for the credentials + +By default, the credentials saving area is occupied from the beginning of EEPROM area. [ESP8266 Arduino core document](http://arduino-esp8266.readthedocs.io/en/latest/filesystem.html?highlight=eeprom#flash-layout) says that: + + +> The following diagram illustrates flash layout used in Arduino environment: + +> ```powershell +> |--------------|-------|---------------|--|--|--|--|--| +> ^ ^ ^ ^ ^ +> Sketch OTA update File system EEPROM WiFi config (SDK) +> ``` + +and + +> EEPROM library uses one sector of flash located [just after the SPIFFS](http://arduino-esp8266.readthedocs.io/en/latest/libraries.html?highlight=SPIFFS#eeprom). + +Also, in ESP32 arduino core 1.0.2 earlier, the placement of the EEPROM area of ESP32 is described in the [partition table](https://github.com/espressif/arduino-esp32/blob/master/tools/partitions/default.csv). 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. + +The [**boundaryOffset**](apiconfig.md#boundaryoffset) in [AutoConnectConfig](apiconfig.md) specifies the start offset of the credentials storage area. The default value is 0. + +!!! info "The boundaryOffset ignored with AutoConnect v1.0.0 later on ESP32 arduino core 1.0.3 later" + 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 [boundaryOffset](apiconfig.md#boundaryoffset) is ignored with the combination of AutoConnect v1.0.0 or later and the arduino-esp32 1.0.3 or later. + ### Relocate the AutoConnect home path A home path of AutoConnect is **/\_ac** by default. You can access from the browser with http://IPADDRESS/\_ac. You can change the home path by revising [**AUTOCONNECT_URI**](https://github.com/Hieromon/AutoConnect/blob/master/src/AutoConnectDefs.h#L69) macro in the include header file as [AutoConnectDef.h](https://github.com/Hieromon/AutoConnect/blob/master/src/AutoConnectDef.h). @@ -582,7 +739,7 @@ portal.begin(); ### Station host name -[AutoConnectConfig::hostName](apiconfig.md#hostname) assigns the station DHCP hostname which complies with [RFC952](https://tools.ietf.org/html/rfc952). It must satisfy the following constraints. +[*AutoConnectConfig::hostName*](apiconfig.md#hostname) assigns the station DHCP hostname which complies with [RFC952](https://tools.ietf.org/html/rfc952). It must satisfy the following constraints. - Up to 24 characters - Only the alphabet (a-z, A-Z), digits (0-9), minus sign (-) @@ -592,7 +749,7 @@ portal.begin(); 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. -[AutoConnectConfig::ticker](apiconfig.md#ticker) 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. +[*AutoConnectConfig::ticker*](apiconfig.md#ticker) 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. ```cpp AutoConnect portal; @@ -626,11 +783,11 @@ The flicker cycle length is defined by some macros in `AutoConnectDefs.h` header - `AUTOCONNECT_FLICKER_WIDTHAP` and `AUTOCONNECT_FLICKER_WIDTHDC`: Specify the duty rate for each period[ms] in 8-bit resolution. -[AutoConnectConfig::tickerPort](apiconfig.md#tickerport) 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 **LED\_BUILTIN**. You can refer to the Arduino IDE's variant information to find out which pin actually on the module assign to **LED\_BUILTIN**.[^3] +[*AutoConnectConfig::tickerPort*](apiconfig.md#tickerport) 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 **LED\_BUILTIN**. You can refer to the Arduino IDE's variant information to find out which pin actually on the module assign to **LED\_BUILTIN**.[^3] [^3]: It's defined in the `pins_arduino.h` file, located in the sub-folder named **variants** wherein Arduino IDE installed folder. -[AutoConnectConfig::tickerOn](apiconfig.md#tickeron) 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 **LOW**. The logic level of LED_BUILTIN for popular modules are as follows: +[*AutoConnectConfig::tickerOn*](apiconfig.md#tickeron) 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 **LOW**. The logic level of LED_BUILTIN for popular modules are as follows: module | Logic level | LED_BUILTIN Pin | Arduino alias ----|----|:---:|---- @@ -643,15 +800,6 @@ LOLIN32 Pro | Active-low | 5 | SS SparkFun ESP32 Thing | Active-high | 5 Adafruit Feather HUZZAH32 | Active-high | 13 | A12 -### Built-in OTA update feature - -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. - - - -[AutoConnectConfig::ota](apiconfig.md#ota) specifies to import the [built-in OTA update class](otabrowser.md) into the Sketch. -See the [Updates with the Web Browser](otabrowser.md) chapter for details. - " "" "" };