diff --git a/docs/achandling.html b/docs/achandling.html index c5b4082..e65e3b5 100644 --- a/docs/achandling.html +++ b/docs/achandling.html @@ -1148,7 +1148,7 @@ AutoConnectElements contained in AutoConnectAux object are uniquely identified b

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. 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. However, it can not save all AutoConnectElements contained in the page as a custom Web page. (ie. AutoConnectAux)

Loading AutoConnectAux & AutoConnectElements with JSON

To load a JSON document as AutoConnectAux use the AutoConnect::load function and load the JSON document of each AutoConnectElement using the AutoConnectAux::loadElement function. Although the functions of both are similar, the structure of the target JSON document is different.

@@ -1216,7 +1216,7 @@ AutoConnectElements contained in AutoConnectAux object are uniquely identified b

Saving AutoConnectElements with JSON

-

To save the AutoConnectElement as a JSON document, use the AutoConnectAux::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 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.

// Open a parameter file on the SPIFFS.
 SPIFFS.begin();
 FILE param = SPIFFS.open("/param", "w");
@@ -1252,6 +1252,7 @@ AutoConnectElements contained in AutoConnectAux object are uniquely identified b
 ]
 
+

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

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 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.

@@ -1361,12 +1362,13 @@ AutoConnectElements contained in AutoConnectAux object are uniquely identified b String feelsOn(AutoConnectAux& aux, PageArgument& args) { // Get the AutoConnectInput named "feels". - // The where() function returns the AutoConnectAux of the page that triggered this handler. - AutoConnectInput& feels = portal.where()->getElement<AutoConnectInput>("feels"); - - // Get the AutoConnectText named "echo". - AutoConnectText& echo = aux.getElement<AutoConnectText>("echo"); - + // The where() function returns an uri string of the AutoConnectAux that triggered this handler. + AutoConnectAux* hello = portal.aux(portal.where()); + AutoConnectInput& feels = hello->getElement<AutoConnectInput>("feels"); + + // Get the AutoConnectText named "echo". + AutoConnectText& echo = aux.getElement<AutoConnectText>("echo"); + // Echo back from input-box to /feels page. echo.value = feels.value + String(" and a bold world!"); return String(""); @@ -1385,7 +1387,7 @@ AutoConnectElements contained in AutoConnectAux object are uniquely identified b

The above example handles in the handler for the values of a custom Web page. An AutoConnect::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 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 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 function. The AutoConnect::where function returns an uri string of the AutoConnectAux object of the custom Web page that caused the HTTP request.

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.

diff --git a/docs/apiaux.html b/docs/apiaux.html index 45f414e..ee60963 100644 --- a/docs/apiaux.html +++ b/docs/apiaux.html @@ -996,7 +996,7 @@ Add an element to the AutoConnectAux. An added element is displayed on the custo
Parameters
addonReference of AutoConnectElements. Specifies one of the AutoConnectElements classes.
-
addonsAn array list of reference of AutoConnectElements. An list initialization of the std::vector can be used for the addons parameter cause the actual definition of type AutoConnectElementVT is std::vector<std::reference_wrapper<AutoConnectElement>>.
+
addonsAn array list of reference of AutoConnectElements. The list initialization with braced-init-list of the std::vector can be used for the addons parameter cause the actual definition of type AutoConnectElementVT is std::vector<std::reference_wrapper<AutoConnectElement>>.

getElement

T& getElement<T>(const String& name)
@@ -1056,10 +1056,16 @@ Load all AutoConnectElements elements from JSON document into AutoConnectAux as
 

loadElement

bool loadElement(const String& in, const String& name = String(""))
 
+
bool loadElement(const String& in, std::vector<String> const& names)
+
bool loadElement(const __FlashStringHelper* in, const String& name = String(""))
 
+
bool loadElement(const __FlashStringHelper* in, std::vector<String> const& names)
+
bool loadElement(Stream& in, const String& name = String(""))
 
+
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. When loading from a JSON document that describes multiple elements, its description must be an array syntax.
Parameters
@@ -1070,6 +1076,7 @@ Load specified element from JSON document into AutoConnectAux. The JSON document
  • Stream : An entity that inherits stream class, generally SPIFFS or SD.
    nameSpecifies the name to be load. If the name is not specified, the loadElement function will load all elements contained in the JSON document.
    +
    names Spefifies an array list of String indicating the name of the element to be loaded. The list initialization with braced-init-list of the std::vector can be used.
    Return value
    trueSpecified AutoConnectElements successfully loaded.
    falseJSON document loading failed.
    @@ -1180,6 +1187,10 @@ Write elements of AutoConnectAux to the stream. The saveElement function outputs

    The output format is pretty

    The saveElement function outputs a prettified JSON document.

  • +
    +

    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 function or AutoConnect::load function.

    +

    setElementValue

    bool setElementValue(const String& name, const String value)
     
    diff --git a/docs/images/ac_load_save.svg b/docs/images/ac_load_save.svg index c5ef733..bf73a2f 100644 --- a/docs/images/ac_load_save.svg +++ b/docs/images/ac_load_save.svg @@ -9,15 +9,61 @@ xmlns="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" - width="134.10013mm" - height="86.830833mm" - viewBox="0 0 134.10013 86.830834" + width="135.15846mm" + height="81.855286mm" + viewBox="0 0 135.15846 81.855286" version="1.1" id="svg8" - inkscape:version="0.92.2 (5c3e80d, 2017-08-06)" + inkscape:version="0.92.4 (5da689c313, 2019-01-14)" sodipodi:docname="ac_load_save.svg"> + id="defs2"> + + + + + + + + + + + transform="translate(-53.740477,-29.775057)"> - - - - - + width="1.699528" + height="2.319947" + x="119.41328" + y="91.30558" + rx="0.053364325" + ry="0.46776518" /> @@ -595,7 +609,7 @@ + AutoConnect::load + AutoConnectAux::loadElement + AutoConnectAux::saveElement + + id="g1498" + transform="translate(-0.16225749)"> + AutoConnectAux::saveElement + transform="translate(-0.16225749,36.803633)" + id="g1498-6"> + + id="rect1046-3-2-3" + style="opacity:1;vector-effect:none;fill:#3366cc;fill-opacity:1;stroke:#3366cc;stroke-width:1.32291663;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:stroke markers fill" /> + id="rect1046-3-6-21-0" + style="opacity:1;vector-effect:none;fill:#3366cc;fill-opacity:1;stroke:#3366cc;stroke-width:1.32291663;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:stroke markers fill" /> - AutoConnect::load - AutoConnectAux::loadElement - AutoConnectAux::saveElement diff --git a/mkdocs/achandling.md b/mkdocs/achandling.md index 5d69668..ea0f04c 100644 --- a/mkdocs/achandling.md +++ b/mkdocs/achandling.md @@ -147,7 +147,7 @@ AutoConnectElementVT& AutoConnectAux::getElements(void) ## 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) @@ -223,7 +223,7 @@ Serial.println(serverName.value); ### 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 // 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 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. @@ -382,8 +384,9 @@ AutoConnect portal; String feelsOn(AutoConnectAux& aux, PageArgument& args) { // Get the AutoConnectInput named "feels". - // The where() function returns the AutoConnectAux of the page that triggered this handler. - AutoConnectInput& feels = portal.where()->getElement("feels"); + // The where() function returns an uri string of the AutoConnectAux that triggered this handler. + AutoConnectAux* hello = portal.aux(portal.where()); + AutoConnectInput& feels = hello->getElement("feels"); // Get the AutoConnectText named "echo". AutoConnectText& echo = aux.getElement("echo"); @@ -407,7 +410,7 @@ void loop() { 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." 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. diff --git a/mkdocs/apiaux.md b/mkdocs/apiaux.md index edd6fcc..0006410 100644 --- a/mkdocs/apiaux.md +++ b/mkdocs/apiaux.md @@ -39,7 +39,7 @@ Add an element to the AutoConnectAux. An added element is displayed on the custo
    **Parameters**
    addonReference of AutoConnectElements. Specifies one of the AutoConnectElements classes.
    -
    addonsAn 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>`.
    +
    addonsAn 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>`.
    ### getElement @@ -115,11 +115,20 @@ Load all AutoConnectElements elements from JSON document into AutoConnectAux as bool loadElement(const String& in, const String& name = String("")) ``` ```cpp +bool loadElement(const String& in, std::vector const& names) +``` +```cpp bool loadElement(const __FlashStringHelper* in, const String& name = String("")) ``` ```cpp +bool loadElement(const __FlashStringHelper* in, std::vector const& names) +``` +```cpp bool loadElement(Stream& in, const String& name = String("")) ``` +```cpp +bool loadElement(Stream& in, std::vector 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.
    **Parameters**
    @@ -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.
    nameSpecifies the name to be load. If the name is not specified, the loadElement function will load all elements contained in the JSON document.
    +
    names 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.
    **Return value**
    trueSpecified AutoConnectElements successfully loaded.
    falseJSON document loading failed.
    @@ -243,6 +253,9 @@ Write elements of AutoConnectAux to the stream. The saveElement function outputs !!! note "The output format is pretty" 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. + ### setElementValue ```cpp diff --git a/mkdocs/images/ac_load_save.svg b/mkdocs/images/ac_load_save.svg index c5ef733..bf73a2f 100644 --- a/mkdocs/images/ac_load_save.svg +++ b/mkdocs/images/ac_load_save.svg @@ -9,15 +9,61 @@ xmlns="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" - width="134.10013mm" - height="86.830833mm" - viewBox="0 0 134.10013 86.830834" + width="135.15846mm" + height="81.855286mm" + viewBox="0 0 135.15846 81.855286" version="1.1" id="svg8" - inkscape:version="0.92.2 (5c3e80d, 2017-08-06)" + inkscape:version="0.92.4 (5da689c313, 2019-01-14)" sodipodi:docname="ac_load_save.svg"> + id="defs2"> + + + + + + + + + + + transform="translate(-53.740477,-29.775057)"> - - - - - + width="1.699528" + height="2.319947" + x="119.41328" + y="91.30558" + rx="0.053364325" + ry="0.46776518" /> @@ -595,7 +609,7 @@ + AutoConnect::load + AutoConnectAux::loadElement + AutoConnectAux::saveElement + + id="g1498" + transform="translate(-0.16225749)"> + AutoConnectAux::saveElement + transform="translate(-0.16225749,36.803633)" + id="g1498-6"> + + id="rect1046-3-2-3" + style="opacity:1;vector-effect:none;fill:#3366cc;fill-opacity:1;stroke:#3366cc;stroke-width:1.32291663;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:stroke markers fill" /> + id="rect1046-3-6-21-0" + style="opacity:1;vector-effect:none;fill:#3366cc;fill-opacity:1;stroke:#3366cc;stroke-width:1.32291663;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:stroke markers fill" /> - AutoConnect::load - AutoConnectAux::loadElement - AutoConnectAux::saveElement diff --git a/src/AutoConnectAux.h b/src/AutoConnectAux.h index ed5e28c..7bd2b02 100644 --- a/src/AutoConnectAux.h +++ b/src/AutoConnectAux.h @@ -75,12 +75,12 @@ class AutoConnectAux : public PageBuilder { bool load(const __FlashStringHelper* in); /**< Load whole elements to AutoConnectAux Page */ bool load(Stream& in); /**< Load whole elements to AutoConnectAux Page */ bool loadElement(const String& in, const String& name = String("")); /**< Load specified element */ - bool loadElement(const String& in, std::vector const& names = {}); /**< Load any specified elements */ - bool loadElement(const __FlashStringHelper* in, const String& name = String("")); /**< Load specified element */ - bool loadElement(const __FlashStringHelper* in, std::vector const& names = {}); /**< Load any specified elements */ + bool loadElement(const String& in, std::vector const& names);/**< Load any specified elements */ + bool loadElement(const __FlashStringHelper* in, const String& name = String("")); /**< Load specified element */ + bool loadElement(const __FlashStringHelper* in, std::vector const& names); /**< Load any specified elements */ bool loadElement(Stream& in, const String& name = String("")); /**< Load specified element */ - bool loadElement(Stream& in, std::vector const& names = {}); /**< Load any specified elements */ - size_t saveElement(Stream& out, std::vector const& names = {}); /**< Write elements of AutoConnectAux to the stream */ + bool loadElement(Stream& in, std::vector const& names); /**< Load any specified elements */ + size_t saveElement(Stream& out, std::vector const& names = {}); /**< Write elements of AutoConnectAux to the stream */ #endif // !AUTOCONNECT_USE_JSON protected: