@ -1148,7 +1148,7 @@ AutoConnectElements contained in AutoConnectAux object are uniquely identified b
</pre></div>
</pre></div>
<h2id="loading-saving-autoconnectelements-with-json">Loading & saving AutoConnectElements with JSON<aclass="headerlink"href="#loading-saving-autoconnectelements-with-json"title="Permanent link">¶</a></h2>
<h2id="loading-saving-autoconnectelements-with-json">Loading & saving AutoConnectElements with JSON<aclass="headerlink"href="#loading-saving-autoconnectelements-with-json"title="Permanent link">¶</a></h2>
<p>AutoConnect supports reading the custom Web page definitions written in JSON and also supports loading and saving of AutoConnectElements. In both cases, the target object is a <ahref="acjson.html">JSON document for AutoConnect</a>. However, it can not save all AutoConnectElements contained in the page as a custom Web page. (ie. AutoConnectAux)</p>
<p>AutoConnect supports reading the custom Web page definitions written in JSON and also supports loading and saving of AutoConnectAux or AutoConnectElements. In both cases, the target object is a <ahref="acjson.html">JSON document for AutoConnect</a>. However, it can not save all AutoConnectElements contained in the page as a custom Web page. (ie. AutoConnectAux)</p>
<p><imgsrc="images/ac_load_save.svg"></p>
<p><imgsrc="images/ac_load_save.svg"></p>
<h3id="loading-autoconnectaux-autoconnectelements-with-json"><iclass="fa fa-upload"></i> Loading AutoConnectAux & AutoConnectElements with JSON<aclass="headerlink"href="#loading-autoconnectaux-autoconnectelements-with-json"title="Permanent link">¶</a></h3>
<h3id="loading-autoconnectaux-autoconnectelements-with-json"><iclass="fa fa-upload"></i> Loading AutoConnectAux & AutoConnectElements with JSON<aclass="headerlink"href="#loading-autoconnectaux-autoconnectelements-with-json"title="Permanent link">¶</a></h3>
<p>To load a JSON document as AutoConnectAux use the <ahref="api.html#load"><strong>AutoConnect::load</strong></a> function and load the JSON document of each AutoConnectElement using the <ahref="apiaux.html#loadelement"><strong>AutoConnectAux::loadElement</strong></a> function. Although the functions of both are similar, the structure of the target JSON document is different.</p>
<p>To load a JSON document as AutoConnectAux use the <ahref="api.html#load"><strong>AutoConnect::load</strong></a> function and load the JSON document of each AutoConnectElement using the <ahref="apiaux.html#loadelement"><strong>AutoConnectAux::loadElement</strong></a> function. Although the functions of both are similar, the structure of the target JSON document is different.</p>
@ -1216,7 +1216,7 @@ AutoConnectElements contained in AutoConnectAux object are uniquely identified b
</pre></div>
</pre></div>
<h3id="saving-autoconnectelements-with-json"><iclass="fa fa-download"></i> Saving AutoConnectElements with JSON<aclass="headerlink"href="#saving-autoconnectelements-with-json"title="Permanent link">¶</a></h3>
<h3id="saving-autoconnectelements-with-json"><iclass="fa fa-download"></i> Saving AutoConnectElements with JSON<aclass="headerlink"href="#saving-autoconnectelements-with-json"title="Permanent link">¶</a></h3>
<p>To save the AutoConnectElement as a JSON document, use the <ahref="apiaux.html#saveelement">AutoConnectAux::saveElement</a> function. It serializes the contents of the object based on the type of the AutoConnectElement. You can persist a serialized AutoConnectElements as a JSON document to a stream.</p>
<p>To save the AutoConnectAux or the AutoConnectElement as a JSON document, use the <ahref="apiaux.html#saveelement">AutoConnectAux::saveElement</a> function. It serializes the contents of the object based on the type of the AutoConnectElement. You can persist a serialized AutoConnectElements as a JSON document to a stream.</p>
<divclass="codehilite"style="background: #272822"><prestyle="line-height: 125%"><span></span><spanstyle="color: #75715e">// Open a parameter file on the SPIFFS.</span>
<divclass="codehilite"style="background: #272822"><prestyle="line-height: 125%"><span></span><spanstyle="color: #75715e">// Open a parameter file on the SPIFFS.</span>
@ -1252,6 +1252,7 @@ AutoConnectElements contained in AutoConnectAux object are uniquely identified b
<spanstyle="color: #f8f8f2">]</span>
<spanstyle="color: #f8f8f2">]</span>
</pre></div>
</pre></div>
<p>Above JSON document can be loaded as it is into a custom Web page using the loadElement function. The loadElement function also loads the value of the element, so the saved value can be restored on the custom Web page.</p>
<h2id="custom-field-data-handling">Custom field data handling<aclass="headerlink"href="#custom-field-data-handling"title="Permanent link">¶</a></h2>
<h2id="custom-field-data-handling">Custom field data handling<aclass="headerlink"href="#custom-field-data-handling"title="Permanent link">¶</a></h2>
<p>A sketch can access variables of AutoConnectElements in the custom Web page. The value entered into the AutoConnectElements on the page is stored in the member variable of each element by AutoConnect whenever GET/POST transmission occurs. </p>
<p>A sketch can access variables of AutoConnectElements in the custom Web page. The value entered into the AutoConnectElements on the page is stored in the member variable of each element by AutoConnect whenever GET/POST transmission occurs. </p>
<p>The following diagram shows the flow of the input values of a custom Web page into a sketch and is the basis for actions to manipulate the values of custom Web pages using sketches.</p>
<p>The following diagram shows the flow of the input values of a custom Web page into a sketch and is the basis for actions to manipulate the values of custom Web pages using sketches.</p>
@ -1361,12 +1362,13 @@ AutoConnectElements contained in AutoConnectAux object are uniquely identified b
@ -1385,7 +1387,7 @@ AutoConnectElements contained in AutoConnectAux object are uniquely identified b
</pre></div>
</pre></div>
<p>The above example handles in the handler for the values of a custom Web page. An <ahref="api.html#on">AutoConnect::on</a> function registers a handler for the AutoConnectAux page of the specified uri. The argument of the custom Web page handler is an AutoConnectAux of the page itself and the <ahref="https://github.com/Hieromon/PageBuilder#arguments-of-invoked-user-function">PageArgument</a> object.</p>
<p>The above example handles in the handler for the values of a custom Web page. An <ahref="api.html#on">AutoConnect::on</a> function registers a handler for the AutoConnectAux page of the specified uri. The argument of the custom Web page handler is an AutoConnectAux of the page itself and the <ahref="https://github.com/Hieromon/PageBuilder#arguments-of-invoked-user-function">PageArgument</a> object.</p>
<p>To retrieve the values entered in a custom Web page you need to access the AutoConnectElement of the page that caused the request to this page and to do this, you use the <ahref="api.html#where">AutoConnect::where</a> function. The <code>AutoConnect::where</code> function returns a pointer to the AutoConnectAux object of the custom Web page that caused the HTTP request.</p>
<p>To retrieve the values entered in a custom Web page you need to access the AutoConnectElement of the page that caused the request to this page and to do this, you use the <ahref="api.html#where">AutoConnect::where</a> function. The <code>AutoConnect::where</code> function returns an uri string of the AutoConnectAux object of the custom Web page that caused the HTTP request.</p>
<divclass="admonition note">
<divclass="admonition note">
<pclass="admonition-title">The where() function is available for only AutoConnectAux.</p>
<pclass="admonition-title">The where() function is available for only AutoConnectAux.</p>
<p>The <code>AutoConnect::where</code> function is available only for the AutoConnectAux object. It is invalid for HTTP requests from individual pages registered with the <strong>on</strong> handler of ESP8266WebServer/WebServer for ESP32. In other words, the <code>AutoConnect::where</code> function only returns the last AutoConnecAux page called.</p>
<p>The <code>AutoConnect::where</code> function is available only for the AutoConnectAux object. It is invalid for HTTP requests from individual pages registered with the <strong>on</strong> handler of ESP8266WebServer/WebServer for ESP32. In other words, the <code>AutoConnect::where</code> function only returns the last AutoConnecAux page called.</p>
@ -996,7 +996,7 @@ Add an element to the AutoConnectAux. An added element is displayed on the custo
<dlclass="apidl">
<dlclass="apidl">
<dt><strong>Parameters</strong></dt>
<dt><strong>Parameters</strong></dt>
<dd><spanclass="apidef">addon</span><spanclass="apidesc">Reference of AutoConnectElements. Specifies one of the AutoConnectElements classes.</span></dd>
<dd><spanclass="apidef">addon</span><spanclass="apidesc">Reference of AutoConnectElements. Specifies one of the AutoConnectElements classes.</span></dd>
<dd><spanclass="apidef">addons</span><spanclass="apidesc">An array list of reference of AutoConnectElements. An<ahref="https://en.cppreference.com/w/cpp/language/list_initialization">list initialization</a> of the <ahref="https://en.cppreference.com/w/cpp/container/vector">std::vector</a> can be used for the addons parameter cause the actual definition of type <strong>AutoConnectElementVT</strong> is <code>std::vector<std::reference_wrapper<AutoConnectElement>></code>.</span></dd>
<dd><spanclass="apidef">addons</span><spanclass="apidesc">An array list of reference of AutoConnectElements. The<ahref="https://en.cppreference.com/w/cpp/language/list_initialization">list initialization</a> with braced-init-list of the <ahref="https://en.cppreference.com/w/cpp/container/vector">std::vector</a> can be used for the addons parameter cause the actual definition of type <strong>AutoConnectElementVT</strong> is <code>std::vector<std::reference_wrapper<AutoConnectElement>></code>.</span></dd>
Load specified element from JSON document into AutoConnectAux. The JSON document specified by the loadElement function must be the <ahref="acjson.html#json-object-for-autoconnectelements">AutoConnectElement document structure</a>. When loading from a JSON document that describes multiple elements, its description must be an array syntax.
Load specified element from JSON document into AutoConnectAux. The JSON document specified by the loadElement function must be the <ahref="acjson.html#json-object-for-autoconnectelements">AutoConnectElement document structure</a>. When loading from a JSON document that describes multiple elements, its description must be an array syntax.
<dlclass="apidl">
<dlclass="apidl">
<dt><strong>Parameters</strong></dt>
<dt><strong>Parameters</strong></dt>
@ -1070,6 +1076,7 @@ Load specified element from JSON document into AutoConnectAux. The JSON document
<li>Stream : An entity that inherits stream class, generally SPIFFS or SD.
<li>Stream : An entity that inherits stream class, generally SPIFFS or SD.
</span></dd>
</span></dd>
<dd><spanclass="apidef">name</span><spanclass="apidesc">Specifies the name to be load. If the name is not specified, the loadElement function will load all elements contained in the JSON document.</span></dd>
<dd><spanclass="apidef">name</span><spanclass="apidesc">Specifies the name to be load. If the name is not specified, the loadElement function will load all elements contained in the JSON document.</span></dd>
<dd><spanclass="apidef">names</span><spanclass="apidesc"> Spefifies an array list of String indicating the name of the element to be loaded. The <ahref="https://en.cppreference.com/w/cpp/language/list_initialization">list initialization</a> with braced-init-list of the <ahref="https://en.cppreference.com/w/cpp/container/vector">std::vector</a> can be used.</span></dd>
@ -1180,6 +1187,10 @@ Write elements of AutoConnectAux to the stream. The saveElement function outputs
<pclass="admonition-title">The output format is pretty</p>
<pclass="admonition-title">The output format is pretty</p>
<p>The saveElement function outputs a prettified JSON document.</p>
<p>The saveElement function outputs a prettified JSON document.</p>
</div>
</div>
<divclass="admonition info">
<pclass="admonition-title">It is not complementary with loadElement</p>
<p>The saveElement function which missing the names parameter without name list to be saved that saves an entire AutoConnectAux element, not just AutoConnectElements. Its saved JSON document is not a complementary input to the loadElement function. The JSON document describing AutoConnectAux saved without the names parameter must be loaded by the <ahref="apiaux.html#load">AutoConnectAux::load</a> function or <ahref="api.html#load">AutoConnect::load</a> function.</p>
## Loading & saving AutoConnectElements with JSON
## Loading & saving AutoConnectElements with JSON
AutoConnect supports reading the custom Web page definitions written in JSON and also supports loading and saving of AutoConnectElements. In both cases, the target object is a [JSON document for AutoConnect](acjson.md). However, it can not save all AutoConnectElements contained in the page as a custom Web page. (ie. AutoConnectAux)
AutoConnect supports reading the custom Web page definitions written in JSON and also supports loading and saving of AutoConnectAux or AutoConnectElements. In both cases, the target object is a [JSON document for AutoConnect](acjson.md). However, it can not save all AutoConnectElements contained in the page as a custom Web page. (ie. AutoConnectAux)
### <iclass="fa fa-download"></i> Saving AutoConnectElements with JSON
### <iclass="fa fa-download"></i> Saving AutoConnectElements with JSON
To save the AutoConnectElement as a JSON document, use the [AutoConnectAux::saveElement](apiaux.md#saveelement) function. It serializes the contents of the object based on the type of the AutoConnectElement. You can persist a serialized AutoConnectElements as a JSON document to a stream.
To save the AutoConnectAux or the AutoConnectElement as a JSON document, use the [AutoConnectAux::saveElement](apiaux.md#saveelement) function. It serializes the contents of the object based on the type of the AutoConnectElement. You can persist a serialized AutoConnectElements as a JSON document to a stream.
```cpp
```cpp
// Open a parameter file on the SPIFFS.
// Open a parameter file on the SPIFFS.
@ -263,6 +263,8 @@ The example above saves `server` and `period` elements from the AutoConnectAux o
]
]
```
```
Above JSON document can be loaded as it is into a custom Web page using the loadElement function. The loadElement function also loads the value of the element, so the saved value can be restored on the custom Web page.
## Custom field data handling
## Custom field data handling
A sketch can access variables of AutoConnectElements in the custom Web page. The value entered into the AutoConnectElements on the page is stored in the member variable of each element by AutoConnect whenever GET/POST transmission occurs.
A sketch can access variables of AutoConnectElements in the custom Web page. The value entered into the AutoConnectElements on the page is stored in the member variable of each element by AutoConnect whenever GET/POST transmission occurs.
The above example handles in the handler for the values of a custom Web page. An [AutoConnect::on](api.md#on) function registers a handler for the AutoConnectAux page of the specified uri. The argument of the custom Web page handler is an AutoConnectAux of the page itself and the [PageArgument](https://github.com/Hieromon/PageBuilder#arguments-of-invoked-user-function) object.
The above example handles in the handler for the values of a custom Web page. An [AutoConnect::on](api.md#on) function registers a handler for the AutoConnectAux page of the specified uri. The argument of the custom Web page handler is an AutoConnectAux of the page itself and the [PageArgument](https://github.com/Hieromon/PageBuilder#arguments-of-invoked-user-function) object.
To retrieve the values entered in a custom Web page you need to access the AutoConnectElement of the page that caused the request to this page and to do this, you use the [AutoConnect::where](api.md#where) function. The `AutoConnect::where` function returns a pointer to the AutoConnectAux object of the custom Web page that caused the HTTP request.
To retrieve the values entered in a custom Web page you need to access the AutoConnectElement of the page that caused the request to this page and to do this, you use the [AutoConnect::where](api.md#where) function. The `AutoConnect::where` function returns an uri string of the AutoConnectAux object of the custom Web page that caused the HTTP request.
!!! note "The where() function is available for only AutoConnectAux."
!!! note "The where() function is available for only AutoConnectAux."
The `AutoConnect::where` function is available only for the AutoConnectAux object. It is invalid for HTTP requests from individual pages registered with the **on** handler of ESP8266WebServer/WebServer for ESP32. In other words, the `AutoConnect::where` function only returns the last AutoConnecAux page called.
The `AutoConnect::where` function is available only for the AutoConnectAux object. It is invalid for HTTP requests from individual pages registered with the **on** handler of ESP8266WebServer/WebServer for ESP32. In other words, the `AutoConnect::where` function only returns the last AutoConnecAux page called.
@ -39,7 +39,7 @@ Add an element to the AutoConnectAux. An added element is displayed on the custo
<dlclass="apidl">
<dlclass="apidl">
<dt>**Parameters**</dt>
<dt>**Parameters**</dt>
<dd><spanclass="apidef">addon</span><spanclass="apidesc">Reference of AutoConnectElements. Specifies one of the AutoConnectElements classes.</span></dd>
<dd><spanclass="apidef">addon</span><spanclass="apidesc">Reference of AutoConnectElements. Specifies one of the AutoConnectElements classes.</span></dd>
<dd><spanclass="apidef">addons</span><spanclass="apidesc">An array list of reference of AutoConnectElements. An [list initialization](https://en.cppreference.com/w/cpp/language/list_initialization) of the [std::vector](https://en.cppreference.com/w/cpp/container/vector) can be used for the addons parameter cause the actual definition of type **AutoConnectElementVT** is `std::vector<std::reference_wrapper<AutoConnectElement>>`.</span></dd>
<dd><spanclass="apidef">addons</span><spanclass="apidesc">An array list of reference of AutoConnectElements. The [list initialization](https://en.cppreference.com/w/cpp/language/list_initialization) with braced-init-list of the [std::vector](https://en.cppreference.com/w/cpp/container/vector) can be used for the addons parameter cause the actual definition of type **AutoConnectElementVT** is `std::vector<std::reference_wrapper<AutoConnectElement>>`.</span></dd>
</dl>
</dl>
### <iclass="fa fa-caret-right"></i> getElement
### <iclass="fa fa-caret-right"></i> getElement
@ -115,11 +115,20 @@ Load all AutoConnectElements elements from JSON document into AutoConnectAux as
bool loadElement(const String& in, const String& name = String(""))
bool loadElement(const String& in, const String& name = String(""))
```
```
```cpp
```cpp
bool loadElement(const String& in, std::vector<String> const& names)
```
```cpp
bool loadElement(const __FlashStringHelper* in, const String& name = String(""))
bool loadElement(const __FlashStringHelper* in, const String& name = String(""))
```
```
```cpp
```cpp
bool loadElement(const __FlashStringHelper* in, std::vector<String> const& names)
```
```cpp
bool loadElement(Stream& in, const String& name = String(""))
bool loadElement(Stream& in, const String& name = String(""))
```
```
```cpp
bool loadElement(Stream& in, std::vector<String> const& names)
```
Load specified element from JSON document into AutoConnectAux. The JSON document specified by the loadElement function must be the [AutoConnectElement document structure](acjson.md#json-object-for-autoconnectelements). When loading from a JSON document that describes multiple elements, its description must be an array syntax.
Load specified element from JSON document into AutoConnectAux. The JSON document specified by the loadElement function must be the [AutoConnectElement document structure](acjson.md#json-object-for-autoconnectelements). When loading from a JSON document that describes multiple elements, its description must be an array syntax.
<dlclass="apidl">
<dlclass="apidl">
<dt>**Parameters**</dt>
<dt>**Parameters**</dt>
@ -130,6 +139,7 @@ Load specified element from JSON document into AutoConnectAux. The JSON document
- Stream : An entity that inherits stream class, generally SPIFFS or SD.
- Stream : An entity that inherits stream class, generally SPIFFS or SD.
</span></dd>
</span></dd>
<dd><spanclass="apidef">name</span><spanclass="apidesc">Specifies the name to be load. If the name is not specified, the loadElement function will load all elements contained in the JSON document.</span></dd>
<dd><spanclass="apidef">name</span><spanclass="apidesc">Specifies the name to be load. If the name is not specified, the loadElement function will load all elements contained in the JSON document.</span></dd>
<dd><spanclass="apidef">names</span><spanclass="apidesc"> Spefifies an array list of String indicating the name of the element to be loaded. The [list initialization](https://en.cppreference.com/w/cpp/language/list_initialization) with braced-init-list of the [std::vector](https://en.cppreference.com/w/cpp/container/vector) can be used.</span></dd>
@ -243,6 +253,9 @@ Write elements of AutoConnectAux to the stream. The saveElement function outputs
!!! note "The output format is pretty"
!!! note "The output format is pretty"
The saveElement function outputs a prettified JSON document.
The saveElement function outputs a prettified JSON document.
!!! Info "It is not complementary with loadElement"
The saveElement function which missing the names parameter without name list to be saved that saves an entire AutoConnectAux element, not just AutoConnectElements. Its saved JSON document is not a complementary input to the loadElement function. The JSON document describing AutoConnectAux saved without the names parameter must be loaded by the [AutoConnectAux::load](apiaux.md#load) function or [AutoConnect::load](api.md#load) function.