Under the work of v0.9.7 documentation

pull/41/head
Hieromon Ikasamo 6 years ago
parent 58044e6847
commit 37935bbcea
  1. 78
      mkdocs/acelements.md
  2. 7
      mkdocs/achandling.md
  3. 114
      mkdocs/acintro.md
  4. 4
      mkdocs/acjson.md
  5. 2
      mkdocs/api.md
  6. 8
      mkdocs/apiaux.md
  7. 5
      mkdocs/apiconfig.md
  8. 111
      mkdocs/apielements.md

@ -2,23 +2,77 @@
Representative HTML elements for making the custom Web page are provided as AutoConnectElements. Representative HTML elements for making the custom Web page are provided as AutoConnectElements.
- AutoConnectButton: Labeled action button - [AutoConnectButton](#autoconnectbutton): Labeled action button
- AutoConnectCheckbox: Labeled checkbox - [AutoConnectCheckbox](#autoconnectcheckbox): Labeled checkbox
- AutoConnectElement: General tag - [AutoConnectElement](#autoconnectelement-a-basic-class-of-elements): General tag
- AutoConnectInput: Labeled text input box - [AutoConnectInput](#autoconnectinput): Labeled text input box
- AutoConnectRadio: Labeled radio button - [AutoConnectRadio](#autoconnectradio): Labeled radio button
- AutoConnectSelect: Selection list - [AutoConnectSelect](#autoconnectselect): Selection list
- AutoConnectSubmit: Submit button - [AutoConnectSubmit](#autoconnectsubmit): Submit button
- AutoConnectText: Style attributed text - [AutoConnectText](#autoconnecttext): Style attributed text
Each element has a common attribute and its own attributes. Each element has a common attribute and its own attributes.
## Layout on custom Web page ## Layout on custom Web page
You can specify the direction to arrange the radio buttons as **AutoConnectRadio** vertically or horizontally. The checkbox as **AutoConnectCheckbox** is not divided in a line by each element. In order to arrange vertically, it is necessary to clearly indicate the **<br>** tag. Other elements are aligned vertically. This basic layout depends on the CSS of the AutoConnect menu so it can not be changed drastically. You can specify the direction to arrange the radio buttons as [**AutoConnectRadio**](#autoconnectradio) vertically or horizontally. The checkbox as [**AutoConnectCheckbox**](#autoconnectcheckbox) is not divided in a line by each element. In order to arrange vertically, it is necessary to clearly indicate the **<br>** tag. Other elements are arranged vertically in the order of addition to AutoConnectAux. This basic layout depends on the CSS of the AutoConnect menu so it can not be changed drastically.
## AutoConnectElement - <small>A basic class of elements</small> ## AutoConnectElement - <small>A basic class of elements</small>
AutoConnectElement is a base class for other element classes and has common attributes for all elements. It can also be used as a [variant](#variant-for-autoconnectelements) of each element. The following items are attributes that AutoConnectElement has and are common to other elements.
### name
Every 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 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.
### 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.
### 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.
```cpp hl_lines="5"
AutoConnectAux customPage;
AutoConnectElementVT& elements = customPage.getElements();
for (AutoConnectElement& elm : elememts) {
if (elm.typeOf() == AC_Text) {
AutoConnectText& text = reinterpret_cast<AutoConnectText&>(elm);
text.style = "color:gray;";
}
}
```
The enumerators for *ACElement_t* are as follows:
- AutoConnetButton: **AC_Button**
- AutoConnectCheckbox: **AC_Checkbox**
- AutoConnectElement: **AC_Element**
- AutoConnectInput: **AC_Input**
- AutoConnectRadio: **AC_Radio**
- AutoConnectSelect: **AC_Select**
- AutoConnectSubmit: **AC_Submit**
- AutoConnectText: **AC_Text**
- Uninitialized element: **AC_Unknown**
## AutoConnectButton ## AutoConnectButton
## AutoConnectCheckbox ## AutoConnectCheckbox
@ -33,3 +87,9 @@ You can specify the direction to arrange the radio buttons as **AutoConnectRadio
## AutoConnectText ## AutoConnectText
## How to coding for the elements
### Variant for AutoConnectElements

@ -1,7 +1,10 @@
## Handing AutoConnectElements in the sketches
## loading and saving AutoConnectElements ## loading and saving AutoConnectElements
## page transition ## Page transition
## Parameter handling ## Parameter handling
WebServer.args, PageArgument
Handling in 'on' handler

@ -31,20 +31,9 @@ You can create multiple custom pages, integrate them into the AutoConnect menu,
<img align="center" width="520px" src="../images/ac_auxjoin_multi.svg"> <img align="center" width="520px" src="../images/ac_auxjoin_multi.svg">
<ul class="horizontal-list"> <ul class="horizontal-list">
<li><span style="margin-left:20px;float:right;width:320px;height:550px;"><img data-gifffer="../images/aux_menu.gif" data-gifffer-width="320" data-gifffer-height="550" /></span><b>False</b> is specified as the third parameter of &#39;<i>aux2</i>&#39; in the above code. The third parameter of the AutoConnectAux constructor is an indicator of whether it's shown to the AutoConnect menu. Right animation is the execution result of the above code. You will see that the custom web page&#39;s menu is displayed only in the last two lines. Because &#39;<i>aux1</i>&#39; and &#39;<i>aux2</i>&#39; in this example have a pair of page transitions. The sketch of this animation is written to transition to &#39;<i>aux2</i>&#39; by the utility of the <b>AutoConnectSubmit</b> element owned by &#39;<i>aux1</i>&#39;.<sup id="fnref:2"><a class="footnote-ref" href="#fn:2" rel="footnote">2</a></sup><br>An &#39;<i>aux2</i>&#39; page transitions only from the submit button of &#39;<i>aux1</i>&#39;. It is a page that saves the parameters you entered on the previous page as shown in mqttRSSI in the library example. It is to want to hide &#39;<i>aux2</i>&#39; from AutoConnect menu lines. The third parameter of the AutoConnectAux constructor is used for this purpose.</li> <li><span style="margin-left:20px;float:right;width:320px;height:550px;"><img data-gifffer="../images/aux_menu.gif" data-gifffer-width="320" data-gifffer-height="550" /></span><b>False</b> is specified as the third parameter of &#39;<i>aux2</i>&#39; in the above code. The third parameter of the AutoConnectAux constructor is an indicator of whether it's shown to the AutoConnect menu. Right animation is the execution result of the above code. You will see that the custom web page&#39;s menu is displayed only in the last two lines. Because &#39;<i>aux1</i>&#39; and &#39;<i>aux2</i>&#39; in this example have a pair of page transitions. The sketch of this animation is written to transition to &#39;<i>aux2</i>&#39; by the utility of the <a href="acelements.html#autoconnectsubmit"><b>AutoConnectSubmit</b></a> element owned by &#39;<i>aux1</i>&#39;.<sup id="fnref:2"><a class="footnote-ref" href="#fn:2" rel="footnote">2</a></sup><br>An &#39;<i>aux2</i>&#39; page transitions only from the submit button of &#39;<i>aux1</i>&#39;. It is a page that saves the parameters you entered on the previous page as shown in mqttRSSI in the library example. It is to want to hide &#39;<i>aux2</i>&#39; from AutoConnect menu lines. The third parameter of the AutoConnectAux constructor is used for this purpose.</li>
</ul> </ul>
## Basic steps to use custom Web pages
So, the basic procedure is as follows.
1. Create or define AutoConnectAux.
2. Create or define [AutoConnectElement(s)](acelements.md).
3. Add [AutoConnectElement(s)](acelements.md) to AutoConnectAux.
4. Create more AutoConnectAux containing [AutoConnectElement(s)](acelements.md), if necessary.
5. Join prepared AutoConnectAux(s) to [AutoConnect](api.md#autoconnect-api).
6. Invoke [AutoConnect::begin()](api.md#begin).
[^2]: [^2]:
The sketch is actually this: The sketch is actually this:
```cpp ```cpp
@ -75,6 +64,107 @@ So, the basic procedure is as follows.
} }
``` ```
## Basic steps to use custom Web pages
So, the basic procedure is as follows.
1. Create or define AutoConnectAux.
2. Create or define [AutoConnectElement(s)](acelements.md).
3. Add [AutoConnectElement(s)](acelements.md) to AutoConnectAux.
4. Create more AutoConnectAux containing [AutoConnectElement(s)](acelements.md), if necessary.
5. Join prepared AutoConnectAux(s) to [AutoConnect](api.md#join).
6. Invoke [AutoConnect::begin()](api.md#begin).
## Write the custom Web page with JSON
You can also write the custom Web page in JSON without using sketch codes.[^3] It is possible to describe the entire page in JSON and can be described for each element also. The JSON description can be saved in SPIFFS or SD and read using AutoConnect's [**load**](api.md#load) function. If you take this approach, you can further reduce the above basic steps. However, this method consumes a lot of memory.
The following JSON code and sketch will execute the custom Web page as the example in the above figure. That is, the sketch of this code and footnote[^2] is equivalent.
**custom_page.json**
```json
[
{
"title": "MQTT Setting",
"uri": "/mqtt_setting",
"menu": true,
"element": [
{
"name": "header",
"type": "ACText",
"value": "MQTT broker settings"
},
{
"name": "caption1",
"type": "ACText",
"value": "Publishing the WiFi..."
},
{
"name": "save",
"type": "ACSubmit",
"value": "SAVE",
"uri": "/mqtt_save"
}
]
},
{
"title": "MQTT Setting",
"uri": "/mqtt_save",
"menu": false,
"element": [
{
"name": "caption2",
"type": "ACText",
"value": "Save parameters"
},
{
"name": "start",
"type": "ACSubmit",
"value": "START",
"uri": "/mqtt_start"
}
]
},
{
"title": "MQTT Start",
"uri": "/mqtt_start",
"menu": true,
"element": []
}
]
```
**The sketch**
```cpp hl_lines="15 16"
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <FS.h>
#include <AutoConnect.h>
AutoConnect portal;
void setup() {
delay(1000);
Serial.begin(115200);
Serial.println();
SPIFFS.begin();
File page = SPIFFS.open("/custom_page.json", "r");
portal.load(page);
page.close();
SPIFFS.end();
portal.begin();
}
void loop() {
portal.handleClient();
}
```
[^3]: Installation of the [ArduinoJson](https://github.com/bblanchon/ArduinoJson) v.5.13.4 library is required.
<script> <script>
window.onload = function() { window.onload = function() {
Gifffer(); Gifffer();

@ -1 +1,3 @@
To process the described AutoConnect element written in the JSON is you need to install the ArduinoJson library. To process the described AutoConnect element written in the JSON is you need to install the ArduinoJson version 5 library.
The order in which AutoConnectElements are arranged on the custom Web page is the order described in JSON.

@ -112,7 +112,7 @@ bool config(const char* ap, const char* password = nullptr)
Set SoftAP's WiFi configuration and static IP configuration. Set SoftAP's WiFi configuration and static IP configuration.
<dl class="apidl"> <dl class="apidl">
<dt>**Parameters**</dt> <dt>**Parameters**</dt>
<dd><span class="apidef">config</span>Reference to [**AutoConnectConfig**](api.md#autoconnectconfig) containing SoftAP's parameters and static IP parameters.</dd> <dd><span class="apidef">config</span>Reference to [**AutoConnectConfig**](apiconfig.md) containing SoftAP's parameters and static IP parameters.</dd>
<dd><span class="apidef">ap</span>SSID for SoftAP. The default value is **esp8266ap** for ESP8266, **esp32ap** for ESP32.</dd> <dd><span class="apidef">ap</span>SSID for SoftAP. The default value is **esp8266ap** for ESP8266, **esp32ap** for ESP32.</dd>
<dd><span class="apidef">password</span>Password for SodtAP. The default value is **12345678**.</dd> <dd><span class="apidef">password</span>Password for SodtAP. The default value is **12345678**.</dd>
<dt>**Return value**</dt> <dt>**Return value**</dt>

@ -5,6 +5,12 @@
```cpp ```cpp
AutoConnectAux(const String& uri = String(""), const String& title = String(""), const bool menu = true, const AutoConnectElementVT addons = AutoConnectElementVT()) AutoConnectAux(const String& uri = String(""), const String& title = String(""), const bool menu = true, const AutoConnectElementVT addons = AutoConnectElementVT())
``` ```
<dl class="apidl">
<dt>**Parameters**</dt>
<dd><span class="apidef">uri</span>URI of this custom Web Page.</dd>
<dd><span class="apidef">title</span>Page title of this custom web page. It will appear on the auto connection menu and at the top of that page.</dd>
<dd><span class="apidef">addons</span>Reference to AutoConnectElement collection.</dt>
</dl>
## <i class="fa fa-code"></i> Public member functions ## <i class="fa fa-code"></i> Public member functions
@ -16,7 +22,7 @@ void add(AutoConnectElement& addon)
```cpp ```cpp
void add(AutoConnectElementVT addons) void add(AutoConnectElementVT addons)
``` ```
Add an element to the auxiliary page. Add the element set to the auxiliary page. Add an element to the AutoConnectAux. An added element is displayed on the custom Web page invoked from the AutoConnect menu.
template<typename T> template<typename T>

@ -17,6 +17,7 @@ AutoConnectConfig(const char* ap, const char* password);
## <i class="fa fa-code"></i> Public member variables ## <i class="fa fa-code"></i> Public member variables
### apid ### apid
SoftAP's SSID. SoftAP's SSID.
<dl class="apidl"> <dl class="apidl">
<dt>**Type**</dt> <dt>**Type**</dt>
@ -89,7 +90,7 @@ Specify the location to be redirected after module reset in the AutoConnect menu
<dd>AC_ONBOOTURI_t</dd> <dd>AC_ONBOOTURI_t</dd>
<dt>**Value**</dt> <dt>**Value**</dt>
<dd><span class="apidef" style="width:230px;">AC_ONBOOTURI_ROOT</span>Resetting the module redirects it to the AutoConnect root path. The root path is assumed to be AUTOCONNECT_URI defined in AutoConnectDefs.h.</dd> <dd><span class="apidef" style="width:230px;">AC_ONBOOTURI_ROOT</span>Resetting the module redirects it to the AutoConnect root path. The root path is assumed to be AUTOCONNECT_URI defined in AutoConnectDefs.h.</dd>
<dd><span class="apidef" style="width:230px;">AC_ONBOOTURI_HOME</span>It is redirected to the uri specified by [**AutoConnectConfig::homeUri**](api.md#homeuri).</dd> <dd><span class="apidef" style="width:230px;">AC_ONBOOTURI_HOME</span>It is redirected to the uri specified by [**AutoConnectConfig::homeUri**](apiconfig.md#homeuri).</dd>
</dl> </dl>
### boundaryOffset ### boundaryOffset
@ -170,7 +171,7 @@ Sets the station host name of ESP8266/ESP32.
### immediateStart ### immediateStart
Disable the first WiFi.begin() and start the captive portal. If this option is enabled, the module will be in AP_STA mode and the captive portal will be activated regardless of [**autoRise::AutoConnectConfig**](api.md#autorise) specification. Disable the first WiFi.begin() and start the captive portal. If this option is enabled, the module will be in AP_STA mode and the captive portal will be activated regardless of [**AutoConnectConfig::autoRise**](apiconfig.md#autorise) specification.
<dl class="apidl"> <dl class="apidl">
<dt>**Type**</dt> <dt>**Type**</dt>
<dd>bool</dd> <dd>bool</dd>

@ -0,0 +1,111 @@
## AutoConnectButton
## <small><i class="fa fa-code"></i> Constructor</small>
```cpp
AutoConnectButton()
```
```cpp
AutoConnectButton(const char* name)
```
```cpp
AutoConnectButton(const char* name, const char* value)
```
```cpp
AutoConnectButton(const char* name, const char* value, const String& action)
```
<dl class="apidl">
<dt>**Parameters**</dt>
<dd><span class="apidef">name</span>The element name.</dd>
<dd><span class="apidef">value</span>Value of the element.</dd>
<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>
### name
The element name.
<dl class="apidl">
<dt>**Type**</dt>
<dd><span class="apidef" style="width:230px;">String</span></dd>
</dl>
### value
Value of the element.
<dl class="apidl">
<dt>**Type**</dt>
<dd><span class="apidef" style="width:230px;">String</span></dd>
</dl>
### action
Native code of the action script executed when the button is clicked.
<dl class="apidl">
<dt>**Type**</dt>
<dd><span class="apidef" style="width:230px;">String</span></dd>
</dl>
## <small><i class="fa fa-code"></i> Public member functions</small>
### typeOf
```cpp
ACElement_t typeOf(void)
```
Returns type of AutoConnectElement.
<dl class="apidl">
<dt>**Return value**</dt>
<dd>AC_Button</dd>
</dl>
## AutoConnectElement
## <small><i class="fa fa-code"></i> Constructor</small>
```cpp
AutoConnectElement()
```
```cpp
AutoConnectElement(const char* name)
```
```cpp
AutoConnectElement(const char* name, const char* value)
```
<dl class="apidl">
<dt>**Parameters**</dt>
<dd><span class="apidef">name</span>The element name.</dd>
<dd><span class="apidef">value</span>Value of the element.</dd>
</dl>
## <small><i class="fa fa-code"></i> Public member variables</small>
### name
The element name.
<dl class="apidl">
<dt>**Type**</dt>
<dd><span class="apidef" style="width:230px;">String</span></dd>
</dl>
### value
Value of the element.
<dl class="apidl">
<dt>**Type**</dt>
<dd><span class="apidef" style="width:230px;">String</span></dd>
</dl>
## <small><i class="fa fa-code"></i> Public member functions</small>
### typeOf
```cpp
ACElement_t typeOf(void)
```
Returns type of AutoConnectElement.
<dl class="apidl">
<dt>**Return value**</dt>
<dd>AC_Element</dd>
</dl>
Loading…
Cancel
Save