Under the work of v0.9.7 documentation

pull/41/head
Hieromon Ikasamo 5 years ago
parent cbb5300fa6
commit abec10c1bd
  1. 6
      mkdocs.yml
  2. 114
      mkdocs/acelements.md
  3. 6
      mkdocs/acintro.md
  4. 4
      mkdocs/index.md
  5. 2
      src/AutoConnectDefs.h

@ -17,8 +17,8 @@ nav:
- 'Custom Web pages' :
- 'Custom Web pages with AutoConnect' : acintro.md
- 'AutoConnectElements' : acelements.md
- 'AutoConnectAux with JSON' : acjson.md
- 'Handling AutoConnectAux' : achandling.md
- 'Custom Web pages with JSON' : acjson.md
- 'Handling custom Web pages' : achandling.md
- 'Library APIs' :
- 'AutoConnect API': api.md
- 'AutoConnectConfig API': apiconfig.md
@ -36,7 +36,7 @@ repo_url: 'https://github.com/Hieromon/AutoConnect'
edit_uri: ""
# Copyright
copyright: 'Copyright © 2018 Hieromon Ikasamo'
copyright: 'Copyright © 2018-2019 Hieromon Ikasamo'
# Configuration
use_directory_urls: false

@ -1,4 +1,4 @@
## The elements for the custome Web pages
## The elements for the custom Web pages
Representative HTML elements for making the custom Web page are provided as AutoConnectElements.
@ -15,18 +15,30 @@ Each element has a common attribute and its own attributes.
## Layout on custom Web page
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.
You can specify the direction to arrange the radio buttons as [**AutoConnectRadio**](#autoconnectradio) vertically or horizontally. 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.
## Form and AutoConnectElements
All AutoConnectElements placed on a custom Web page are included in one form. Its form is fixed and created by AutoConnect. The form's value (usually the text or checkbox you entered) is sent by [AutoConnectSubmit](#autoconnectsubmit) using the POST method.
**name** and **value** of each AutoConnectElement which own form-data are reflected in the query string when the custom Web page was sent. You can retrieve the value in the sketch as the parameter's value of the query string with [**ESP8266WebServer::arg**](https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266WebServer#getting-information-about-request-arguments) function or **PageArgument** class of [**AutoConnect::on**](api.md#on) handler when the form is submitted.
## 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
### <i class="fa fa-edit"></i> Constructor
```cpp
AutoConnectElement(const char* name, const char* value)
```
### <i class="fa fa-caret-right"></i> 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");
AutoConnectAux customPage("/custom_page", "Custom page");
const char ELEMENT_TEXT[] PROGMEM = R"(
{
"name": "text1",
@ -41,19 +53,19 @@ 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
### <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.
**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>
### type
### <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.
**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) {
for (AutoConnectElement& elm : elements) {
if (elm.typeOf() == AC_Text) {
AutoConnectText& text = reinterpret_cast<AutoConnectText&>(elm);
text.style = "color:gray;";
@ -73,12 +85,76 @@ The enumerators for *ACElement_t* are as follows:
- AutoConnectText: **AC_Text**
- Uninitialized element: **AC_Unknown**
Furthermore, to convert an entity that is not an AutoConnectElement to its native type, you must [re-interpret](https://en.cppreference.com/w/cpp/language/reinterpret_cast) that type with c++.
## AutoConnectButton
AutoConnectButton generates an HTML `button type="button"` tag and locates a clickable button to a custom Web page. Currently AutoConnectButton corresponds only to name, value, an onclick attribute of HTML button tag. An onclick attribute is generated from an `action` member variable of the AutoConnectButton, which is mostly used with a JavaScript to activate a script.
### <i class="fa fa-edit"></i> Constructor
```cpp
AutoConnectButton(const char* name, const char* value, const String& action)
```
### <i class="fa fa-caret-right"></i> name
It is the name of the AutoConnectButton element and matches the name attribute of the button tag. It also becomes the parameter name of the query string when submitted.
### <i class="fa fa-caret-right"></i> value
It becomes a value of the `value` attribute of an HTML button tag.
### <i class="fa fa-caret-right"></i> action
**action** is String data type and is an onclick attribute fire on a mouse click on the element. it is mostly used with a JavaScript to activate a script.[^1] For example, the following code defines a custom Web page that copies a content of `Text1` to `Text2` by clicking `Button`.
[^1]:JavaScript can be inserted into a custom Web page using AutoConnectElement.
```cpp hl_lines="3 4 5 10"
const char* scCopyText = R"(
<script>
function CopyText() {
document.getElementById("Text2").value = document.getElementById("Text1").value;
}
</script>
)";
ACInput(Text1, "Text1");
ACInput(Text2, "Text2");
ACButton(Button, "COPY", "CopyText()");
ACElement(TextCopy, scCopyText);
```
## AutoConnectCheckbox
AutoConnectCheckbox generates an HTML `input type="checkbox"` tag and a `label` tag. It places horizontally on a custom Web page by default.
### <i class="fa fa-edit"></i> Constructor
```cpp
AutoConnectCheckbox(const char* name, const char* value, const char* label, const bool checked)
```
### <i class="fa fa-caret-right"></i> name
It is the name of the AutoConnectCheckbox element and matches the name attribute of the input tag. It also becomes the parameter name of the query string when submitted.
### <i class="fa fa-caret-right"></i> value
It becomes a value of the `value` attribute of an HTML input tag.
### <i class="fa fa-caret-right"></i> label
A label is an optional string. If you specify a label, an `id` attribute is attached to the HTML `checkbox` tag and an HTML `label` tag is generated. Label tag and checkbox will combine by its id attribute. Labels are always placed on the right side of the checkbox. If you do not specify a label, only &#9744; will be displayed.
### <i class="fa fa-caret-right"></i> checked
A checked is a Boolean value and indicates the checked status of the checkbox.
## AutoConnectInput
AutoConnectInput genarates an HTML `input type="text"` tag and a `label` tag. It can also have a placeholder.
## AutoConnectRadio
## AutoConnectSelect
@ -89,6 +165,26 @@ The enumerators for *ACElement_t* are as follows:
## How to coding for the elements
### Definition in sketch
Each element can be defined by a macro. By using the macro, you can treat element names that are String types as variables in sketches.
ACElement( *name* \[, *value* \] )
ACButton( *name* \[, *value* \] \[, *action* \] )
ACCheckbox( *name* \[, *value* \] \[, *label* \] \[, **true** | **false** \] )
ACInput( *name* \[, *value* \] \[, *placeholder* \] \[, *label* \] )
ACRadio( *name* \[, *values* \] \[, *label* \] \[, **AC\_Horitontal** | **AC\_Vertical** \] \[, *checked* ] )
ACSelect( *name* \[, *options* \] \[, *label* \] )
ACSubmit( *name* \[, *value* \] \[, *uri* \] )
ACText( *name* \[, *value* \] \[, *style* \] )
### Variant for AutoConnectElements

@ -134,7 +134,7 @@ The following JSON code and sketch will execute the custom Web page as the examp
```
**The sketch**
```cpp hl_lines="15 16"
```cpp hl_lines="11 12"
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <FS.h>
@ -143,10 +143,6 @@ The following JSON code and sketch will execute the custom Web page as the examp
AutoConnect portal;
void setup() {
delay(1000);
Serial.begin(115200);
Serial.println();
SPIFFS.begin();
File page = SPIFFS.open("/custom_page.json", "r");

@ -77,12 +77,12 @@ Install third-party platform using the *Boards Manager* of Arduino IDE. Package
<i class="fa fa-download"></i> <strong>ESP32 Arduino core</strong>
Also, to apply AutoConnect to ESP32, the [arduino-esp32 core](https://github.com/espressif/arduino-esp32) provided by Espressif is needed. The [latest release](https://github.com/espressif/arduino-esp32/releases/latest) is recommended.
Install third-party platform using the *Boards Manager* of Arduino IDE. You can add multiple URLs into *Additional Board Manager URLs* field, separating them with commas. Package URL is https://dl.espressif.com/dl/package_esp32_index.json
Install third-party platform using the *Boards Manager* of Arduino IDE. You can add multiple URLs into *Additional Board Manager URLs* field, separating them with commas. Package URL is https://dl.espressif.com/dl/package_esp32_index.json for ESP32.
<i class="fa fa-download"></i> <strong>Additional necessary library</strong>
The [PageBuilder](https://github.com/Hieromon/PageBuilder) library to build HTML for ESP8266WebServer is needed.
To install the PageBuilder library into your Arduino IDE, you can use the *Library Manager*. Select the board of ESP8266 series in the Arduino IDE, open the library manager and search keyword '**PageBuilder**' with the topic '**Communication**', then you can see the *PageBuilder*. The latest version is required 1.2.3 later for ESP32.[^1]
To install the PageBuilder library into your Arduino IDE, you can use the *Library Manager*. Select the board of ESP8266 series in the Arduino IDE, open the library manager and search keyword '**PageBuilder**' with the topic '**Communication**', then you can see the *PageBuilder*. The latest version is required 1.2.3 later.[^1]
<img src="./images/lm.png" width="640"/>

@ -11,7 +11,7 @@
#define _AUTOCONNECTDEFS_H_
// Uncomment the following AC_DEBUG to enable debug output.
//#define AC_DEBUG
#define AC_DEBUG
// Debug output destination can be defined externally with AC_DEBUG_PORT
#ifndef AC_DEBUG_PORT

Loading…
Cancel
Save