AutoConnectAux API
Constructor¶
AutoConnectAux¶
AutoConnectAux(const String& uri = String(""), const String& title = String(""), const bool menu = true, const AutoConnectElementVT addons = AutoConnectElementVT())
- Parameters
- uriURI of this custom Web Page.
- titlePage title of this custom Web page. It will appear on the auto connection menu and at the top of that page.
- menuSpecifies whether to display this page on menu.
- addonsReference to AutoConnectElement collection.
Public member functions¶
add¶
void add(AutoConnectElement& addon)
void add(AutoConnectElementVT addons)
- 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>>
.
getElement¶
T& getElement<T>(const String& name)
AutoConnectElement* getElement(const String& name)
- Parameters
- TActual type name of AutoConnectElements as AutoConnectButton, AutoConnectCheckbox, AutoConnectElement, AutoConnectInput, AutoConnectRadio, AutoConnectSelect, AutoConnectSubmit, AutoConnectText.
- nameName of the AutoConnectElements to be retrieved.
- Return value
- A reference of the AutoConnectElements. If a type is not specified returns a pointer.
getElements¶
AutoConnectElementVT& getElements(void)
- Return value
- A reference to std::vector of reference to AutoConnecctElements.
The getElements returns a reference to std::vector of reference to AutoConnecctElements. This function is provided to handle AutoConnectElemets owned by AutoConnectAux in bulk, and you can use each method of std::vector for a return value.
// An example of getting type and name of all AutoConnectElements registered in AutoConnectAux. AutoConnectAux aux; // some code here... AutoConnectElementVt& elements = aux.getElements(); for (AutoConnectElement& elm : elements) { Serial.printf("name<%s> as type %d\n", elm.name.c_str(), (int)elm.typeOf()); }
load¶
bool load(const String& in)
bool load(const __FlashStringHelper* in)
bool load(Stream& in)
- Parameters
- inSpecifies the JSON document to be load. The load function can input the following objects.
- String : Read-only String
- PROGMEM : Character array contained in the flash
- Stream : An entity that inherits stream class, generally SPIFFS or SD.
- Return value
- trueJSON document as the custom Web pages successfully loaded.
- falseJSON document loading failed.
Load multiple custom Web pages separately
Multiple custom Web pages can be loaded at once with JSON as an array. But it will consume a lot of memory. By loading a JSON document by page as much as possible, you can reduce memory consumption.
loadElement¶
bool loadElement(const String& in, const String& name = String(""))
bool loadElement(const __FlashStringHelper* in, const String& name = String(""))
bool loadElement(Stream& in, const String& name = String(""))
- Parameters
- inSpecifies the JSON document to be load. The load function can input the following objects.
- String : Read-only String
- PROGMEM : Character array contained in the flash
- 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.
- Return value
- trueSpecified AutoConnectElements successfully loaded.
- falseJSON document loading failed.
Maybe it is an array
Please note that the JSON document that is the input for loadElement is an array syntax of AutoConnectElements when there are multiple elements. For example, the following JSON document has a syntax error:
{ "name": "Caption", "type": "ACText", "value": "Hello, world" }, { "name": "Server", "type": "ACInput", "label": "Server address" }
[
, ]
is missing.
menu¶
void menu(const bool post)
- Parameters
- trueShow on the menu.
- falseHidden on the menu.
on¶
void on(const AuxHandlerFunctionT handler, const AutoConnectExitOrder_t order = AC_EXIT_AHEAD)
- Register the handler function of the AutoConnectAux.
- Parameters
- handlerA function that behaves when a request to the AutoConnectAux page occurs. AuxHandlerFunctionT type is defined by the following declaration.
String handler(AutoConnectAux&, PageArgument&)
- orderSpecifies when the handler is called with the following enumeration value.
- 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.
release¶
bool release(const String& name)
- Parameters
- nameSpecifies the name of AutoConnectElements to be released.
- Return value
- trueThe AutoConnectElement successfully released.
- falseThe AutoConnectElement can not be released.
saveElement¶
size_t saveElement(Stream& out, std::vector<String> const& names = {})
- Parameters
- outOutput stream to be output. SPIFFS, SD also Serial can be specified generally.
- namesThe array of the name of AutoConnectElements to be output. If the names parameter is not specified, all AutoConnectElements registered in AutoConnectAux are output.
- Return value
- The number of bytes written.
The output format is pretty
The saveElement function outputs a prettified JSON document.
setElementValue¶
bool setElementValue(const String& name, const String value)
bool setElementValue(const String& name, std::vector<String> const& values)
- Parameters
- nameSpecifies the name of the AutoConnectElements that you want to set the value.
- valueSpecifies the value to be set.
- valuesSpecifies a reference of a std::vector of String. It contains the values of the AutoConnectRadio or the AutoConnectSelect.
- Return value
- trueThe value has been set.
- falseAutoConnectElements with the specified name are not registered. Or the type of the value is not consistent with the specified AutoConnectElements.
You can directly access the value member variable.
If you are gripping with the sketch to the AutoConnectElements of the target that sets the value, you can access the value member variable directly. The following sketch code has the same effect.
AutoConnectAux aux; // ... Griping the AutoConnectText here. aux.setElementValue("TEXT_FIELD", "New value");
AutoConnectAux aux; // ... Griping the AutoConnectText here. AutoConnectText& text = aux.getElement<AutoConnectText>("TEXT_FIELD"); text.value = "New value";
setTitle¶
void setTitle(const String& title)
- Parameter
- titleTitle string to be display.
Not the menu title
The setTitle function is not set for the AutoConnect menu title. The effect of this function is that custom Web page only. To change the AutoConnect menu title use AutoConnectConfig::title.