Under the work of v0.9.7 documentation

pull/41/head
Hieromon Ikasamo 5 years ago
parent 5578f61ca6
commit 2b9b3755ab
  1. 2
      mkdocs.yml
  2. 24
      mkdocs/acelements.md
  3. 62
      mkdocs/achandling.md
  4. 25
      mkdocs/api.md
  5. 80
      mkdocs/apiaux.md
  6. 22
      mkdocs/apielements.md

@ -21,8 +21,8 @@ nav:
- 'Handling the custom Web pages' : achandling.md
- 'Library APIs' :
- 'AutoConnect API': api.md
- 'AutoConnectConfig API': apiconfig.md
- 'AutoConnectAux API': apiaux.md
- 'AutoConnectConfig API': apiconfig.md
- 'AutoConnectElements API': apielements.md
- 'Something extra': apiextra.md
- 'Examples' : examples.md

@ -38,31 +38,15 @@ AutoConnectElement(const char* name, const char* value)
### <i class="fa fa-caret-right"></i> name
Each element has a name. **Name** is the String data type. To access its element in the sketches you can identify by the name. Its method is useful for loading elements in JSON. In the load function of AutoConnectElement(s) described [**later**](acjson.md), these objects are not created in advance by sketches. Therefore, access to the attribute of that element by the **name** as follows:
```cpp hl_lines="4 10"
AutoConnectAux customPage("/custom_page", "Custom page");
const char ELEMENT_TEXT[] PROGMEM = R"(
{
"name": "text1",
"type": "ACText",
"value": "Hello, world"
}
)";
customPage.loadElement(ELEMENT_TEXT);
AutoConnectText& text1 = customPage.getElement<AutoConnectText>("text1");
text1.style = "text-align:center;color:#2f4f4f;"
```
The above example accesses the *text1* element which loaded from JSON using AutoConnectAux's [**getElement**](apiaux.md#getelement) function by name and sets the [**style**](#style) attribute.
Each element has a name. The **name** is the String data type. You can identify each element by the name to access it with sketches.
### <i class="fa fa-caret-right"></i> value
**Value** is the source of the HTML code generated with the element and its data type is String. Characteristics of Value vary depending on the element. The value of AutoConnectElement is native HTML code. A string of value is output as HTML as it is.<br>
The **value** is the string which is a source to generate an HTML code. Characteristics of Value vary depending on the element. The value of AutoConnectElement is native HTML code. A string of value is output as HTML as it is.
### <i class="fa fa-caret-right"></i> type
**Type** indicates the type of the element and represented as the *ACElement_t* enumeration type in the sketch. Since AutoConnectElement also acts as a variant of other elements, it can be applied to handle elements collectively. At that time, the type can be referred to by the [**typeOf()**](apielements.md#typeof) function. The following example changes the font color of all [AutoConnectText](#autoconnecttext) elements of a custom Web page to gray.
The **type** indicates the type of the element and represented as the *ACElement_t* enumeration type in the sketch. Since AutoConnectElement also acts as a variant of other elements, it can be applied to handle elements collectively. At that time, the type can be referred to by the [**typeOf()**](apielements.md#typeof) function. The following example changes the font color of all [AutoConnectText](#autoconnecttext) elements of a custom Web page to gray.
```cpp hl_lines="5"
AutoConnectAux customPage;
@ -357,7 +341,7 @@ ACText ( *name* <small>\[</small> , *value* <small>\]</small> <small>\[</small>
### <i class="fa fa-edit"></i> Variant for AutoConnectElements
Some AutoConnectAux APIs specify AutoConnectElement as an argument. There are also functions that returns a pointer to AutoConnectElement. In order to make these interfaces single, AutoConnectElement behaves as a variant type of other elements. Use [reinterpret_cast](https://en.cppreference.com/w/cpp/language/reinterpret_cast) to cast from a variant pointer to an Actual type pointer of AutoConnectElements.
Some AutoConnectAux APIs specify AutoConnectElements as an argument. There are also functions that return a pointer to AutoConnectElements. AutoConnectElement behaves as a variant type of each element class to make these interfaces a single. Use [reinterpret_cast](https://en.cppreference.com/w/cpp/language/reinterpret_cast) to cast from a variant pointer to an Actual type pointer of AutoConnectElements.
```cpp
AutoConnectAux aux;

@ -444,17 +444,67 @@ POST /feels HTTP/1.1
Host: ESP8266_IP_ADDRESS
name1=value1&name2=value2&name3=value3
</pre>
ESP8266WebServer class will parse the query string and rebuilds its arguments when the above request arrives. In the sketches as a handler, you can reach it using with the [ESP8266WebServer::arg](https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266WebServer#getting-information-about-request-arguments) function. The `arg`'s argument specifies the name of the AutoConnectElements. Also, you can choose another way to access arguments without going through the ESP8266WebServer class. The [PageArgument](https://github.com/Hieromon/PageBuilder#arguments-of-invoked-user-function) object of the custom Web page handler argument is a copy of the arg object of the ESP8266WebServer class. Either of these methods is a simple and easy way to access parameters in custom Web page handlers. However, if you need to access from outside of the handler to the value of AutoConnectElements, you need to accomplish it using with the [AutoConnectAux::getElement](#get-autoconnectelement-from-the-autoconnectaux) function.
ESP8266WebServer class will parse the query string and rebuilds its arguments when the above request arrives. A custom page handler registered with the [ESP8266WebServer::on](https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266WebServer#client-request-handlers) function can access the value of AutoConnectElements with [ESP8266WebServe::arg](https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266WebServer#getting-information-about-request-arguments) function. It reaches the values of AutoConnectElements without the intermediation of AutoConnect. Therefore, its handler will not be AutoConnectAux and can send a response to the client directly. The following example is part of a server sketch which has two web pages. The `/hello` page is a custom Web page of AutoConnectAux which has an input box named "input1". Another `/echo` page is a page handler for ESP8266WebServer, which uses the [ESP8266WebServer::send](https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266WebServer#sending-responses-to-the-client) function to echo back the value of an input1 as an http response.
### <i class="fa fa-desktop"></i> Overtyping with LoadElement function
```cpp hl_lines="3 8"
ESP8266WebServer server;
AutoConnect portal(server);
ACInput(input1, "", "INPUT");
ACSubmit(send, "HELLO", "/echo");
AutoConnectAux aux("/hello", { input1, send });
server.on("/echo", []() {
String echo = server.arg("input1");
Serial.println(echo);
server.send(200, "text/plain", echo);
});
portal.join(aux);
portal.begin();
```
Also, you can choose another way to access arguments without going through the ESP8266WebServer class. The [PageArgument](https://github.com/Hieromon/PageBuilder#arguments-of-invoked-user-function) object of the custom Web page handler argument is a copy of the arg object of the ESP8266WebServer class. Either of these methods is a simple and easy way to access parameters in custom Web page handlers. However, if you need to access from outside of the handler to the value of AutoConnectElements, you need to accomplish it using with the [AutoConnectAux::getElement](#get-autoconnectelement-from-the-autoconnectaux) function. The following sketch code replaces the above example with JSON and PageArgument, and its behaves is equivalent basically to the above sketch.
```cpp
const static char auxPage[] PROGMEM = R"raw (
[
{ "title":"Hello", "uri":"/hello", "menu":true, "element":[
{ "name":"input1", "type": "ACInput", "label": "INPUT" },
{ "name":"send", "type":"ACSubmit", "value":"HELLO", "uri":"/echo" }]
},
{ "title":"Echo", "uri":"/echo", "menu":false, "element":[
{ "name":"echo", "type":"ACText" }]
}
]
)raw";
AutoConnect portal;
portal.load(auxPage);
portal.on("/echo", [](AutoConnectAux& aux, PageArgument& args) {
AutoConnectText& ac_echo = aux.getElement<AutoConnectText>("echo");
ac_echo.value = args.arg("input1");
return String();
});
portal.begin();
```
### <i class="fa fa-desktop"></i> Over typing with LoadElement function
The [AutoConnectAux::loadElement](apiaux.md#loadelement) function overwrites its value when loading an AutoConnectElement. If the loadElement function wields an element with an input value, the previous value will be lost by the loaded value. If you need to preserve input values even during page transition operations, we recommend that you load parameters only once at an early stage in the `setup()` of sketches.
## Transitions of the custom Web pages
### The URI of the custom Web pages
The transition of the custom Web page follows the URI of the page, but the ESP8266WebServer class does not know the URI of an AutoConnectAux page. (Registering a custom Web page does not use the *ESP8266WebServer::on*/*WebServer::on* function.) Therefore ESP8266WebServer class does not detect its URI access. If you want to detect an http request to AutoConnectAux's custom Web page, you need to register its URI with the [AutoConnectAux::on](apiaux.md#on) function.
In addition to this, there are restrictions in the handler for the custom Web page as shown in the following section.
### Restrictions
The transition of the custom Web page follows the URI of the page, but the ESP8266WebServer class does not know its URI. (Registering a custom Web page does not use the *ESP8266WebServer::on*/*WebServer::on* function.) Therefore, the custom Web page handler has the following restrictions.
The custom Web pages handler has the following restrictions.
- Do not send HTTP responses from the handler.
@ -466,9 +516,11 @@ The transition of the custom Web page follows the URI of the page, but the ESP82
- Can not handle the custom Web pages during a connection is not established yet.
During the connection attempt, the web browser on the client will send a probe for a captive portal. Its request will cause unintended custom Web page transitions.
During the connection attempt, the web browser of the client will send a probe for a captive portal. Its request will cause unintended custom Web page transitions.
- Can not place URI of the custom Web pages to AUTOCONNECT_URI].
- Can not place URI of the custom Web pages to [AUTOCONNECT_URI](https://).
AutoConnect will not work if you place a custom Web page to [AUTOCONNECT_URI](api.md#defined-macros).
!!! hint "302 Redirect Alternatives"
To transition from a custom Web page to a sketch owned page, execute the link function of JavaScript with the AutoConnectElement element.

@ -71,7 +71,7 @@ AutoConnectAux* aux(const String& uri) const
Returns a pointer to AutoConnectAux with the URI specified by *uri*. If AutoConnectAux with that URI is not bound, it returns **nullptr**.
<dl class="apidl">
<dt>**Parameters**</dt>
<dd><span class="apidef">uri</span>URI string.</dd>
<dd><span class="apidef">uri</span>A string of the URI.</dd>
<dt>**Return value**</dt>
<dd>A Pointer of the AutoConnectAux instance.</dd>
</dl>
@ -219,13 +219,34 @@ bool load(const __FlashStringHelper* aux)
```cpp
bool load(Stream& aux)
```
Load
Load JSON document of AutoConnectAux which contains AutoConnectElements. If there is a syntax error in the JSON document, false is returned.
<dl class="apidl">
<dt>**Parameters**</dt>
<dd><span class="apidef">aux</span>The input string to be loaded.</dd>
<dt>**Return value**</dt>
<dd><span class="apidef">true</span>The JSON document as AutoConnectAux successfully loaded.</dd>
<dd><span class="apidef">false</span>Loading JSON document unsuccessful, probably syntax errors have occurred or insufficient memory. You can diagnose the cause of loading failure using the [ArduinoJson Assistant](https://arduinojson.org/v5/assistant/).</dd>
</dl>
### <i class="fa fa-caret-right"></i> on
```cpp
bool on(const String& uri, const AuxHandlerFunctionT handler, AutoConnectExitOrder_t order = AC_EXIT_AHEAD)
```
Register the handler function of the AutoConnectAux.
<dl class="apidl">
<dt>**Parameters**</dt>
<dd><span class="apidef">uri</span>A string of the URI assigned to the AutoConnectAux page.</dd>
<dd><span class="apidef">handler</span>A function that behaves when a request to the AutoConnectAux page occurs. AuxHandlerFunctionT type is defined by the following declaration.</dd>
<dd><span class="apidef"></span>`String handler(AutoConnectAux&, PageArgument&)`</dd>
<dd><span class="apidef">order</span>Specifies when the handler is called with the following enumeration value.</dd>
: - **AC_EXIT_AHEAD** :
Called before AutoConnect generates the HTML of the page. You set the value of AutoConnectElements in the handler then its value will be displayed on the page.
: - **AC_EXIT_LATER** :
Called after AutoConnect generates the HTML of the page. You can append to HTML generated by AutoConnect.
: - **AC_EXIT_BOTH** :
Called even before generating HTML and after generated.
</dl>
!!! caution "It is not ESP8266WebServer::on, not WebServer::on for ESP32."
This function effects to AutoConnectAux only. However, it coexists with that of ESP8266WebServer::on or WebServer::on of ESP32.

@ -40,34 +40,86 @@ Get registered AutoConnectElement as specified name.
```cpp
AutoConnectElementVT& getElements(void)
```
Get vector of reference of all elements.
### <i class="fa fa-caret-right"></i> load
```cpp
bool load(const String& in)
```
```cpp
bool load(const __FlashStringHelper* in)
```
```cpp
bool load(Stream& in)
```
Load whole elements to AutoConnectAux Pages.
### <i class="fa fa-caret-right"></i> loadElement
```cpp
bool loadElement(const String& in, const String& name = String(""))
```
```cpp
bool loadElement(const __FlashStringHelper* in, const String& name = String(""))
```
```cpp
bool loadElement(Stream& in, const String& name = String(""))
```
Load specified element.
### <i class="fa fa-caret-right"></i> menu
```cpp
void menu(const bool post)
```
Set or reset the display as menu item for this AutoConnectAux.
### <i class="fa fa-caret-right"></i> on
```cpp
void on(const AuxHandlerFunctionT handler, const AutoConnectExitOrder_t order = AC_EXIT_AHEAD)
```
Register the handler function of the AutoConnectAux.
<dl class="apidl">
<dt>**Parameters**</dt>
<dd><span class="apidef">handler</span>A function that behaves when a request to the AutoConnectAux page occurs. AuxHandlerFunctionT type is defined by the following declaration.</dd>
<dd><span class="apidef"></span>`String handler(AutoConnectAux&, PageArgument&)`</dd>
<dd><span class="apidef">order</span>Specifies when the handler is called with the following enumeration value.</dd>
: - **AC_EXIT_AHEAD** :
Called before AutoConnect generates the HTML of the page. You set the value of AutoConnectElements in the handler then its value will be displayed on the page.
: - **AC_EXIT_LATER** :
Called after AutoConnect generates the HTML of the page. You can append to HTML generated by AutoConnect.
: - **AC_EXIT_BOTH** :
Called even before generating HTML and after generated.
</dl>
### <i class="fa fa-caret-right"></i> release
```cpp
bool release(const String& name)
```
Release a specified AutoConnectElement.
### <i class="fa fa-caret-right"></i> saveElement
```cpp
size_t saveElement(Stream& out, std::vector<String> const& names = {})
```
Write elements of AutoConnectAux to the stream.
bool setElementValue(const String& name, const String value); /**< Set value to specified element */
bool setElementValue(const String& name, std::vector<String> const& values); /**< Set values collection to specified element */
void setTitle(const String title) { _title = title; } /**< Set a title of the auxiliary page */
void on(const AuxHandlerFunctionT handler, const AutoConnectExitOrder_t order = AC_EXIT_AHEAD) { _handler = handler; _order = order; } /**< Set user handler */
bool load(const String& in); /**< Load whole elements to AutoConnectAux Page */
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 __FlashStringHelper* in, const String& name = String("")); /**< Load specified element */
bool loadElement(Stream& in, const String& name = String("")); /**< Load specified element */
size_t saveElement(Stream& out, std::vector<String> const& names = {}); /**< Write elements of AutoConnectAux to the stream */
### <i class="fa fa-caret-right"></i> setElementValue
```cpp
bool setElementValue(const String& name, const String value)
```
```cpp
bool setElementValue(const String& name, std::vector<String> const& values)
```
### <i class="fa fa-caret-right"></i> setTitle
```cpp
void setTitle(const String& title)
```
Set the title string of the AutoConnectAux page.

@ -1,6 +1,6 @@
## AutoConnectButton
## <small><i class="fa fa-code"></i> Constructor</small>
## <i class="fa fa-code"></i> Constructor
```cpp
AutoConnectButton()
@ -21,9 +21,9 @@ AutoConnectButton(const char* name, const char* value, const String& action)
<dd><span class="apidef">action</span>Native code of the action script executed when the button is clicked.</dd>
</dl>
## <small><i class="fa fa-code"></i> Public member variables</small>
## <i class="fa fa-code"></i> Public member variables
### name
### <i class="fa fa-caret-right"></i> name
The element name.
<dl class="apidl">
@ -31,7 +31,7 @@ The element name.
<dd><span class="apidef" style="width:230px;">String</span></dd>
</dl>
### value
### <i class="fa fa-caret-right"></i> value
Value of the element.
<dl class="apidl">
@ -39,7 +39,7 @@ Value of the element.
<dd><span class="apidef" style="width:230px;">String</span></dd>
</dl>
### action
### <i class="fa fa-caret-right"></i> action
Native code of the action script executed when the button is clicked.
<dl class="apidl">
@ -49,7 +49,7 @@ Native code of the action script executed when the button is clicked.
## <small><i class="fa fa-code"></i> Public member functions</small>
### typeOf
### <i class="fa fa-caret-right"></i> typeOf
```cpp
ACElement_t typeOf(void)
@ -62,13 +62,13 @@ Returns type of AutoConnectElement.
## AutoConnectElement
## <small><i class="fa fa-code"></i> Constructor</small>
## <i class="fa fa-code"></i> Constructor
```cpp
AutoConnectElement()
```
```cpp
AutoConnectElement(const char* name)
AutoConnectElement(conSst char* name)
```
```cpp
AutoConnectElement(const char* name, const char* value)
@ -81,7 +81,7 @@ AutoConnectElement(const char* name, const char* value)
## <small><i class="fa fa-code"></i> Public member variables</small>
### name
### <i class="fa fa-caret-right"></i> name
The element name.
<dl class="apidl">
@ -89,7 +89,7 @@ The element name.
<dd><span class="apidef" style="width:230px;">String</span></dd>
</dl>
### value
### <i class="fa fa-caret-right"></i> value
Value of the element.
<dl class="apidl">
@ -99,7 +99,7 @@ Value of the element.
## <small><i class="fa fa-code"></i> Public member functions</small>
### typeOf
### <i class="fa fa-caret-right"></i> typeOf
```cpp
ACElement_t typeOf(void)

Loading…
Cancel
Save