diff --git a/docs/404.html b/docs/404.html index 09b81d4..4193f39 100644 --- a/docs/404.html +++ b/docs/404.html @@ -644,8 +644,8 @@
Since v1.0.0, AutoConnect supports a new attribute with each element that allows automatic transfer of input values across pages without sketching. AutoConnect will copy the input value of the elements declared as global to the same-named global elements on a different custom Web pages at the page transition timing.
+
The global attribute will be useful for echoing input values back to another custom Web pages. This copy operation can be performed between different types. (eg., copy value from AutoConnectInput to AutoConnectText) The following example reflects the input value of PAGE1 to the AutoConnectText field of PAGE2 without sketch code.
+static const char PAGE1[] PROGMEM = R"( +{ + "title": "PAGE1", + "uri": "/page1", + "menu": true, + "element": [ + { + "name": "input1", + "type": "ACInput", + "global": true + }, + { + "name": "send", + "type": "ACSubmit", + "value": "OK", + "uri": "/page2" + } + ] +} +)"; +static const char PAGE2[] PROGMEM = R"( +{ + "title": "PAGE2", + "uri": "/page2", + "menu": false, + "element": [ + { + "name": "input1", + "type": "ACText", + "global": true + } + ] +} +)"; + +AutoConnect portal; +AutoConnectAux page1; +AutoConnectAux page2; + +void setup() { + page1.load(PAGE1); + page2.load(PAGE2); + portal.join( { page1, page2 }); + portal.begin(); +} + +void loop() { + portal.handleClient(); +} +
The value entered in input1 declared in PAGE1 is reflected in input1 of PAGE2 as an AutoConnectText value even if there is no sketch code to transfer it to PAGE2. It's shown as like:
+
+
+
Copy only for same-named and the global
+The input value will be copied only if the global attribute of the destination element is true. If an element with the same name is declared non-global, the value is not copied.
+ESP8266WebServer class and the WebServer class assume that the implementation of the ReqestHandler class contained in the WebServer library will handle the URL requests. Usually, it is sketch code registered by ESP8266WebServer::on function.
-When the page transitions from the custom Web page created by AutoConnectAux to the handler registered by ESP2866WebServer::on function, a little trick is needed to retrieve the values of AutoConnectElements. (i.e. the URI of the ESP8266WebServer::on handler is specified in the uri attribute of AutoConnectSubmit) AutoConnect cannot intervene in the procedure in which the ESP8266WebServer class calls the on-page handler by the sketch. Therefore, it is necessary to retrieve preliminary the values of AutoConnectElements using the AutoConnectAux::fetchElement function for value processing with the on-page handler.
+When a page transition from a custom Web page created by AutoConnectAux to a handler registered with ESP2866WebServer::on function, a little trick is needed to retrieve the values of AutoConnectElements. (i.e. the URI of the ESP8266WebServer::on handler is specified in the uri attribute of AutoConnectSubmit) AutoConnect cannot intervene in the procedure in which the ESP8266WebServer class calls the on-page handler coded with the sketch. Therefore, it is necessary to retrieve preliminary the values of AutoConnectElements using the AutoConnectAux::fetchElement function for value processing with the on-page handler.
The following sketch is an example of extracting values inputted on a custom web page with an on-page handler and then processing it.
ESP8266WebServer server; AutoConnect portal(server); @@ -1745,7 +1822,7 @@ ESP8266WebServer class will parse the query string and rebuilds its arguments wh
It's shown as like:![]()
Check data against on submission¶
-By giving a pattern to AutoConnectInput, you can find errors in data styles while typing in custom Web pages. The pattern is specified by regular expression.2 If the value during input of AutoConnectInput does not match the regular expression specified in the pattern, its background color changes to pink. The following example shows the behavior when checking the IP address in the AutoConnectInput field.
+By giving a pattern to AutoConnectInput, you can find errors in data styles while typing in custom Web pages. The pattern is specified with regular expression.2 If the value during input of AutoConnectInput does not match the regular expression specified in the pattern, its background color changes to pink. The following example shows the behavior when checking the IP address in the AutoConnectInput field.
-{ "title" : "Page-1", "uri" : "/page1", @@ -1761,15 +1838,49 @@ ESP8266WebServer class will parse the query string and rebuilds its arguments wh }-- --
-
If you are not familiar with regular expressions, you may feel that description very strange. And matter of fact, it is a strange description for those unfamiliar with formal languages. If your regular expression can not interpret the intended syntax and semantics, you can use an online tester. The regex101 is an exceptional online site for testing and debugging regular expressions.
-+
Validate input data¶
+
It's shown as like:
+If you are not familiar with regular expressions, you may feel that description very strange. Matter of fact, it's a strange description for those who are unfamiliar with the formal languages. If your regular expression can not interpret the intended syntax and semantics, you can use an online tester. The regex101 is an exceptional online tool for testing and debugging regular expressions.
+
Input data validation¶
The pattern attribute of AutoConnectInput only determines the data consistency on the web browser based on the given regular expression. In order to guarantee the validity of input data, it is necessary to verify it before actually using it.
-You can validate input data from AutoConnectInput using the isValid function before actually processing it. The isValid function determines whether the value currently stored in AutoConnectInput matches the pattern.
+You can validate input data from AutoConnectInput using the isValid function before actually processing it. The isValid function determines whether the value currently stored in AutoConnectInput matches the pattern.
+You can also use the AutoConnectAux::isValid function to verify the data input to all AutoConnectInput elements on the custom Web page at once. The two sketches below show the difference between using AutoConnectInput::isValid and using AutoConnectAux::isValid. In both cases, it verifies the input data of the same AutoConnectInput, but in the case of using AutoConnectAux::isValid, the amount of sketch coding is small.
+A common declaration
++ +const char PAGE[] PROGMEM = R"( +{ + "title": "Custom page", + "uri": "/page", + "menu": true, + "element": [ + { + "name": "input1", + "type": "ACInput", + "pattern": "^[0-9]{4}$" + }, + { + "name": "input2", + "type": "ACInput", + "pattern": "^[a-zA-Z]{4}$" + } + ] +} +)"; +AutoConnectAux page; +page.load(PAGE); +Using AutoConnectInput::isValid
++ +AutoConnectInput& input1 = page["input1"].as<AutoConnectInput>(); +AutoConnectInput& input2 = page["input2"].as<AutoConnectInput>(); +if (!input1.isValid() || !input2.isValid()) + Serial.println("Validation error"); +Using AutoConnectAux::isValid
++if (!page.isValid()) + Serial.println("Validation error"); +Convert data to actually type¶
The values in the AutoConnectElements field of the custom Web page are all typed as String. A sketch needs to be converted to an actual data type if the data type required for sketch processing is not a String type. For the typical data type conversion method, refer to section Tips for data conversion.
Transitions of the custom Web pages¶
diff --git a/docs/acintro.html b/docs/acintro.html index 0be77dc..a0fbeb8 100644 --- a/docs/acintro.html +++ b/docs/acintro.html @@ -728,8 +728,8 @@
The above custom Web page definitions can be loaded in a batch using the AutoConnect::load function.
JSON description for AutoConnectElements describes as an array in the element with arguments of each constructor.
{
@@ -1522,7 +1537,7 @@
It is based on analysis by ArduinoJson, but the semantic analysis is simplified to save memory. Consequently, it is not an error that a custom Web page JSON document to have unnecessary keys. It will be ignored.
There are two main ways to load the custom Web pages into AutoConnect.
+Load directly into AutoConnect
+This way does not require an explicit declaration of AutoConnectAux objects with sketches and is also useful when importing the custom Web pages JSON document from an external file such as SPIFFS because the page definition and sketch coding structure can be separated.
+Using the AutoCoonnect::load function, AutoConnect dynamically generates the necessary AutoConnectAux objects internally based on the custom Web page definition of the imported JSON document content. In the sketch, the generated AutoConnectAux object can be referenced using the AutoConnect::aux function. You can reach the AutoConnectElements you desired using the AutoConnectAux::getElement function of its AutoConnectAux.
+In the following example, it loads in a batch a JSON document of custom Web pages stored in SPIFFS and accesses to the AutoConnectInput element.
+[ + { + "title": "page1", + "uri": "/page1", + "menu": true, + "element": [ + { + "name": "input1", + "type": "ACInput" + } + ] + }, + { + "title": "page2", + "uri": "/page2", + "menu": true, + "element": [ + { + "name": "input2", + "type": "ACInput" + } + ] + } +] +
AutoConnect portal; +File page = SPIFFS.open("/custom_page.json", "r"); +portal.load(page); +page.close(); +AutoConnectAux* aux = portal.aux("/page1"); +AutoConnectInput& input1 = aux->getElement<AutoConnectInput>("input1"); +
Load to AutoConnectAux and join to AutoConnect
+This way declares AutoConnectAux in the sketch and loads the custom Web pages JSON document there. It has an advantage for if you want to define each page of a custom Web page individually or allocate AutoConnectAux objects dynamically on the sketch side.
+After loading a JSON document using the AutoConnectAux::load function by each, integrate those into AutoConnect using the AutoConnect::join function.
+In the following example, you can see the difference between two sketches in a sketch modified using the AutoConnectAux::load.
+{ + "title": "page1", + "uri": "/page1", + "menu": true, + "element": [ + { + "name": "input1", + "type": "ACInput" + } + ] +} +
{ + "title": "page2", + "uri": "/page2", + "menu": true, + "element": [ + { + "name": "input2", + "type": "ACInput" + } + ] +} +
AutoConnect portal; +AutoConnectAux page1; +AutoConnectAux page2; +File page = SPIFFS.open("/custom_page1.json", "r"); +page1.load(page); +page.close(); +page = SPIFFS.open("/custom_page2.json", "r"); +page2.load(page); +page.close(); +portal.join( { page1, page2 } ); +AutoConnectInput& input1 = page1.getElement<AutoConnectInput>("input1"); +
AutoConnect supports loading of JSON document from the following instances:
Registering the "not found" handler is a different way than ESP8266WebServer (WebServer as ESP32). The onNotFound of ESP8266WebServer/WebServer does not work with AutoConnect. AutoConnect overrides ESP8266WebServer::onNotFound/WebServer::onNotFound to handle a captive portal. To register "not found" handler, use AutoConnect::onNotFound.
AutoConnect stores the established WiFi connection in the EEPROM 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 AutoConnectCredential class which provides the access method to the saved credentials in EEPROM. Refer to section Saved credentail access for details.
+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 AutoConnectCredential class which provides the access method to the saved credentials in the flash. Refer to section Saved credentials access for details.
+Where to store credentials in ESP32 with AutoConnect v1.0.0 or later
+Since v1.0.0, credentials are stored in nvs of ESP32. AutoConnect v1.0.0 or later accesses the credentials area using the Preferences class with the arduino esp-32 core. So in ESP32, the credentials are not in the EEPROM, it is in the namespace AC_CREDT of the nvs. See Saved credentials access for details.
+In ESP8266, it is saved in EEPROM as is conventionally done.
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.
The WiFiSTAClass::disconnect 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 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.
-If the autoReconnect option of the AutoConnectConfig 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 EEPROM as AutoConnect's credentials, explicitly apply it with WiFi.begin and rerun.
+If the autoReconnect option of the AutoConnectConfig 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 Portal; AutoConnectConfig Config; Config.autoReconnect = true; @@ -1203,13 +1208,14 @@ Portal.begin();
An autoReconnect option is available to AutoConnect::begin without SSID and pass passphrase.
+An autoReconnect option is available to AutoConnect::begin without SSID and pass Passphrase.
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.
By default, AutoConnect saves the credentials of the established connection in EEPROM. You can disable it with the autoSave parameter specified by AutoConnectConfig.
+By default, AutoConnect saves the credentials of the established connection to the flash. You can disable it with the autoSave parameter specified by AutoConnectConfig.
+See the Saved credentials access chapter for details on accessing stored credentials.
AutoConnect Portal; AutoConnectConfig Config; Config.autoSave = AC_SAVECREDENTIAL_NEVER; @@ -1218,8 +1224,30 @@
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
+Credentials storage location
+The location where AutoConnect saves credentials depends on the module type and the AutoConnect library version, also arduino-esp32 core version. +
AutoConnect | +Arduino core for ESP8266 |
+ Arduino core for ESP32 | +|
---|---|---|---|
1.0.2 earlier + | 1.0.3 later + | ||
v0.9.12 earlier | +EEPROM | +EEPROM (partition) | +Not supported | +
v1.0.0 later | +Preferences (nvs) (Can be used EEPROM with turning off AUTOCONNECT_USE_PREFERENCES macro) |
+ Preferences (nvs) | +
The captive portal will only be activated if the first WiFi::begin fails. Sketch can detect with the AutoConnect::onDetect 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.
@@ -1428,8 +1456,12 @@ Sketch OTA update File system EEPROM WiFi config (SDK)-EEPROM library uses one sector of flash located just after the SPIFFS.
Also, the placement of the EEPROM area of ESP32 is described in the partition table. 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.
+Also, in ESP32 arduino core 1.0.2 earlier, the placement of the EEPROM area of ESP32 is described in the partition table. 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 in AutoConnectConfig specifies the start offset of the credentials storage area. The default value is 0.
+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 boundaryOffet is ignored with the combination of AutoConnect v1.0.0 or later and the arduino-esp32 1.0.3 or later.
+If you do not usually connect to WiFi and need to establish a WiFi connection if necessary, you can combine the autoRise option with the immediateStart option to achieve on-demand connection. This behavior is similar to the WiFiManager's startConfigPortal function. In order to do this, you usually configure only with AutoConnectConfig in setup() and AutoConnect::begin handles in loop().
AutoConnect Portal; diff --git a/docs/api.html b/docs/api.html index dbe7772..794b697 100644 --- a/docs/api.html +++ b/docs/api.html @@ -837,8 +837,8 @@
bool isValid(void) +
bool load(const String& in)
Sets IP address for Soft AP in captive portal. When AutoConnect fails the initial WiFi.begin, it starts the captive portal with the IP address specified this.
Automatically will try to reconnect with the past established access point (BSSID) when the current configured SSID in ESP8266/ESP32 could not be connected. By enabling this option, AutoConnect::begin() function will attempt to reconnect to a known access point using credentials stored in the EEPROM, even if the connection failed by current SSID.
+
Automatically will try to reconnect with the past established access point (BSSID) when the current configured SSID in ESP8266/ESP32 could not be connected. By enabling this option, AutoConnect::begin() function will attempt to reconnect to a known access point using credentials stored in the flash, even if the connection failed by current SSID.
If the connection fails, starts the captive portal in SoftAP+STA mode.
Sets the offset address of the credential storage area for EEPROM. This value must be between greater than 4 and less than flash sector size. (4096 by SDK)
-The default value is 0.
+The default value is 0.
+This option is valid only for ESP8266 or ESP32 arduino core 1.0.2 earlier.
Sets gateway address for Soft AP in captive portal. When AutoConnect fails the initial WiFi.begin, it starts the captive portal with the IP address specified this.
Sets SoftAP to hidden SSID. diff --git a/docs/apielements.html b/docs/apielements.html index b8e7254..758d39b 100644 --- a/docs/apielements.html +++ b/docs/apielements.html @@ -565,6 +565,13 @@ enable + + +
Enable HTML tag generation for the element. AutoConnect will generate the element into HTML only if the enable attribute is true. +
Enable HTML tag generation for the element.
The global attribute copies input values between elements of the same name on different custom Web pages. +
The element name. @@ -2915,13 +3033,19 @@ Returns type of AutoConnectElement.
It indicates the checked status of the checkbox. The value of the checked checkbox element is packed in the query string and sent by submit.
Enable HTML tag generation for the element. AutoConnect will generate the element into HTML only if the enable attribute is true. +
Enable HTML tag generation for the element.
The global attribute copies input values between elements of the same name on different custom Web pages. +
A label is an optional string. A label is always arranged on the right side of the checkbox. Specification of a label will generate an HTML <label>
tag with an id
attribute. The checkbox and the label are connected by the id attribute.
@@ -2974,10 +3098,16 @@ Returns type of AutoConnectElement.
Enable HTML tag generation for the element. AutoConnect will generate the element into HTML only if the enable attribute is true. +
Enable HTML tag generation for the element. +
The global attribute copies input values between elements of the same name on different custom Web pages.
The element name. @@ -3036,10 +3166,16 @@ Casts the reference to the AutoConnectElement the specified type.
Enable HTML tag generation for the element. AutoConnect will generate the element into HTML only if the enable attribute is true. +
Enable HTML tag generation for the element. +
The global attribute copies input values between elements of the same name on different custom Web pages.
A label is an optional string. A label is always arranged on the left side of the file input box. Specification of a label will generate an HTML <label>
tag with an id attribute. The file input box and the label are connected by the id attribute.
@@ -3119,10 +3255,16 @@ Returns type of AutoConnectFile.
Enable HTML tag generation for the element. AutoConnect will generate the element into HTML only if the enable attribute is true. +
Enable HTML tag generation for the element. +
The global attribute copies input values between elements of the same name on different custom Web pages.
A label is an optional string. A label is always arranged on the left side of the input box. Specification of a label will generate an HTML <label>
tag with an id attribute. The input box and the label are connected by the id attribute.
@@ -3205,10 +3347,16 @@ Returns type of AutoConnectElement.
Enable HTML tag generation for the element. AutoConnect will generate the element into HTML only if the enable attribute is true. +
Enable HTML tag generation for the element. +
The global attribute copies input values between elements of the same name on different custom Web pages.
A label is an optional string. A label will be arranged in the left or top of the radio buttons according to the order. @@ -3325,10 +3473,16 @@ Returns current checked option of the radio buttons.
Enable HTML tag generation for the element. AutoConnect will generate the element into HTML only if the enable attribute is true. +
Enable HTML tag generation for the element.
The global attribute copies input values between elements of the same name on different custom Web pages. +
The element name. @@ -3437,10 +3591,10 @@ Returns current selected option of the select list.
Enable HTML tag generation for the element. AutoConnect will generate the element into HTML only if the enable attribute is true. +
Enable HTML tag generation for the element.
The element name. @@ -3476,10 +3630,16 @@ Returns type of AutoConnectElement.
Enable HTML tag generation for the element. AutoConnect will generate the element into HTML only if the enable attribute is true. +
Enable HTML tag generation for the element. +
The global attribute copies input values between elements of the same name on different custom Web pages.
The element name. @@ -3534,10 +3694,10 @@ Returns type of AutoConnectElement.
Enable HTML tag generation for the element. AutoConnect will generate the element into HTML only if the enable attribute is true. +
Enable HTML tag generation for the element.
The conversion format when outputting values. The format string conforms to C-style printf library functions. diff --git a/docs/apiextra.html b/docs/apiextra.html index 4fc654c..c07c333 100644 --- a/docs/apiextra.html +++ b/docs/apiextra.html @@ -686,8 +686,8 @@
AutoConnect stores the established WiFi connection in the EEPROM 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 AutoConnectCredential class which provides the access method to the saved credentials in EEPROM.1
+AutoConnect stores the established WiFi connection in the flash memory of the ESP8266/ESP32 module and equips the class to access the credentials from the sketch. You can read, write or erase the credentials using this class individually. It's AutoConnectCredential class which provides the access method to the saved credentials in the flash.1
+The location where AutoConnect saves credentials depends on the module type and the AutoConnect library version, also arduino-esp32 core version. In either case, the location is flash memory, but EEPROM and Preferences (in the nvs2) are used depending on the library versions.
+AutoConnect | +Arduino core for ESP8266 |
+ Arduino core for ESP32 | +|
---|---|---|---|
1.0.2 earlier + | 1.0.3 later + | ||
v0.9.12 earlier | +EEPROM | +EEPROM (partition) | +Not supported | +
v1.0.0 later | +Preferences (nvs) (Can be used EEPROM with turning off AUTOCONNECT_USE_PREFERENCES macro) |
+ Preferences (nvs) | +
However, sketches do not need to know where to store credentials using the commonly accessible AutoConnectCredential API.
+If you are using an Arduino core for ESP32 1.0.2 earlier and need to use credentials in EEPROM for backward compatibility, turns off the AUTOCONNECT_USE_PREFERENCES3 macro definition in AutoConnectCredentials.h
file. AutoConnect behaves assuming that credentials are stored in EEPROM if AUTOCONNECT_USE_PREFERENCES
is not defined.
#include <AutoConnectCredential.h> @@ -1016,12 +1057,12 @@-AutoConnectCredential();
AutoConnectCredential default constructor. The default offset value is 0. If the offset value is 0, the credential area starts from the top of the EEPROM. AutoConnect sometimes overwrites data when using this area with user sketch.
+AutoConnectCredential default constructor. The default offset value is 0. In ESP8266 or ESP32 with arduino core 1.0.2 earlier, if the offset value is 0, the credential area starts from the top of the EEPROM. If you use this area in a user sketch, AutoConnect may overwrite that data.
AutoConnectCredential(uint16_t offset);
Clear saved credentials
+There is no particular API for batch clearing of all credential data stored by AutoConnect. It is necessary to prepare a sketch function that combines several AutoConnectCredential APIs to erase all saved credentials. +The following function is an implementation example, and you can use it to achieve batch clearing. +
void deleteAllCredentials(void) { + AutoConnectCredential credential; + struct station_config config; + uint8_t ent = credential.entries(); + + while (ent--) { + credential.load(0, &config); + credential.del((const char*)&config.ssid[0]); + } +} +
A structure is included in the ESP8266 SDK. You can use it in the sketch like as follows:
@@ -1098,7 +1155,7 @@A data structure of the credential saving area in EEPROM as the below. 2
+A data structure of the credential saving area in EEPROM as the below. 4