Gbox 4.20
Grow box automation and monitoring - <a href='https://sites.google.com/site/growboxguy/'>https://sites.google.com/site/growboxguy/</a>
 
Loading...
Searching...
No Matches
ELClientWebServer Class Reference

#include <ELClientWebServer.h>

Public Member Functions

 ELClientWebServer (ELClient *elc)
 Creates a Web-Server instance.
 
void setup ()
 Initializes web-server.
 
URLHandlercreateURLHandler (const char *URL)
 Creates and registers an URL handler.
 
URLHandlercreateURLHandler (const __FlashStringHelper *URL)
 Creates and registers an URL handler.
 
URLHandlercreateURLHandler (const String &s)
 Creates and registers an URL handler.
 
void destroyURLHandler (URLHandler *handler)
 Unregisters an destroys an URL handler.
 
void setArgInt (const char *name, int32_t value)
 Sets integer value of a field.
 
void setArgInt (const __FlashStringHelper *name, int32_t value)
 Sets integer value of a field.
 
void setArgJson (const char *name, const char *value)
 Sets JSON value of a field.
 
void setArgJson (const __FlashStringHelper *name, const char *value)
 Sets JSON value of a field.
 
void setArgJson (const __FlashStringHelper *name, const __FlashStringHelper *value)
 Sets JSON value of a field.
 
void setArgString (const char *name, const char *value)
 Sets string value of a field.
 
void setArgString (const __FlashStringHelper *name, const char *value)
 Sets string value of a field.
 
void setArgString (const __FlashStringHelper *name, const __FlashStringHelper *value)
 Sets string value of a field.
 
void setArgBoolean (const char *name, uint8_t value)
 Sets boolean value of a field.
 
void setArgBoolean (const __FlashStringHelper *name, uint8_t value)
 Sets boolean value of a field.
 
void setArgNull (const char *name)
 Sets null value to a field.
 
void setArgNull (const __FlashStringHelper *name)
 Sets null value to a field.
 
void setArgFloat (const char *name, float f)
 Sets float value of a field.
 
void setArgFloat (const __FlashStringHelper *name, float f)
 Sets float value of a field.
 
int32_t getArgInt ()
 Returns an HTML field value as integer.
 
char * getArgString ()
 Returns an HTML field value as string.
 
uint8_t getArgBoolean ()
 Returns an HTML field value as boolean.
 
float getArgFloat ()
 Returns an HTML field value as float.
 

Static Public Member Functions

static ELClientWebServergetInstance ()
 Returns the singleton web-server instance.
 

Detailed Description

Definition at line 118 of file ELClientWebServer.h.

Constructor & Destructor Documentation

◆ ELClientWebServer()

ELClientWebServer::ELClientWebServer ( ELClient elc)

Creates a Web-Server instance.

ELClientWebServer(ELClient* elClient)

This method creates a web-server object.

Parameters
elClientReference to ELClient object.
Example code
// Initialize a connection to esp-link using the normal hardware serial port
// DEBUG is disabled because of performance reasons
// Initialize the Web-Server client
ELClientWebServer webServer(&esp);
REST rest & esp
Definition demo.ino:11
ESP esp & Serial
Definition demo.ino:9

Definition at line 43 of file ELClientWebServer.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ createURLHandler() [1/3]

URLHandler * ELClientWebServer::createURLHandler ( const __FlashStringHelper *  URL)

Creates and registers an URL handler.

createURLHandler(const __FlashStringHelper * URL)

This method is responsible for creating and registering an URL handler object.

Parameters
URLThe URL the handler handles. URL is "/" + the HTML file name + ".json".
Returns
The created URLHandler object.
Example code
void myLoadCb(char * url) {
...
}
void myRefreshCb(char * url) {
...
}
void myButtonPressCb(char * button_id) {
...
}
void mySetFieldCb(char * field_id) {
...
}
void setup()
{
...
URLHandler *handler = webServer.createURLHandler(F("/mypage.html.json"));
handler->loadCb.attach(&myLoadCb);
handler->refreshCb.attach(&myRefreshCb);
handler->buttonCb.attach(&myButtonPressCb);
handler->setFieldCb.attach(&mySetFieldCb);
...
}
void setup()
Initializes web-server.
void attach(T *item, retT(T::*method)(argT))
Definition FP.h:147
FP< void, char * > setFieldCb
callback for setting a field from a HTML form
FP< void, char * > loadCb
Callback for HTML page loading.
FP< void, char * > buttonCb
callback for a HTML button press
FP< void, char * > refreshCb
Callback for HTML page refresh.

Definition at line 140 of file ELClientWebServer.cpp.

Here is the call graph for this function:

◆ createURLHandler() [2/3]

URLHandler * ELClientWebServer::createURLHandler ( const char *  URL)

Creates and registers an URL handler.

createURLHandler(const char * URL)

This method is responsible for creating and registering an URL handler object.

Parameters
URLThe URL the handler handles. URL is "/" + the HTML file name + ".json".
Returns
The created URLHandler object.
Example code
void myLoadCb(char * url) {
...
}
void myRefreshCb(char * url) {
...
}
void myButtonPressCb(char * button_id) {
...
}
void mySetFieldCb(char * field_id) {
...
}
void setup()
{
...
URLHandler *handler = webServer.createURLHandler("/mypage.html.json");
handler->loadCb.attach(&myLoadCb);
handler->refreshCb.attach(&myRefreshCb);
handler->buttonCb.attach(&myButtonPressCb);
handler->setFieldCb.attach(&mySetFieldCb);
...
}

Definition at line 95 of file ELClientWebServer.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createURLHandler() [3/3]

URLHandler * ELClientWebServer::createURLHandler ( const String &  URL)

Creates and registers an URL handler.

createURLHandler(const String &URL)

This method is responsible for creating and registering an URL handler object.

Parameters
URLThe URL the handler handles. URL is "/" + the HTML file name + ".json".
Returns
The created URLHandler object.
Example code
void myLoadCb(char * url) {
...
}
void myRefreshCb(char * url) {
...
}
void myButtonPressCb(char * button_id) {
...
}
void mySetFieldCb(char * field_id) {
...
}
void setup()
{
...
String url = F("/mypage.html.json");
URLHandler *handler = webServer.createURLHandler(url);
handler->loadCb.attach(&myLoadCb);
handler->refreshCb.attach(&myRefreshCb);
handler->buttonCb.attach(&myButtonPressCb);
handler->setFieldCb.attach(&mySetFieldCb);
...
}

Definition at line 186 of file ELClientWebServer.cpp.

◆ destroyURLHandler()

void ELClientWebServer::destroyURLHandler ( URLHandler handler)

Unregisters an destroys an URL handler.

destroyURLHandler(URLHandler * handler)

This method is responsible destroying an URL handler object.

Parameters
handlerThe handler to destroy.
Example code
URLHandler *handler = ...
destroyURLHandler(handler);

Definition at line 209 of file ELClientWebServer.cpp.

◆ getArgBoolean()

uint8_t ELClientWebServer::getArgBoolean ( )

Returns an HTML field value as boolean.

getArgBoolean()

Returns an HTML field value as boolean. This method is used at setFieldCb. WebServer doesn't know the type of a field, every field arrives as string. This method converts the string to the expected type. Don't call this method outside of setFieldCb, otherwise it can reset/crash/freeze MCU.

Returns
Boolean value of the field
Warning
Use this method only in setFieldCb, otherwise crash, freeze, MCU reset, or other unexpected behaviour can happen.
Example
uint8_t boolean_value;
// this method should be fast to prevent UART receive buffer overrun
void setFieldCb(const char * field_str)
{
String field = field_str;
if( field == F("field_id") )
{
boolean_value = webServer.getArgBoolean();
}
}

Definition at line 1092 of file ELClientWebServer.cpp.

◆ getArgFloat()

float ELClientWebServer::getArgFloat ( )

Returns an HTML field value as float.

getArgFloat()

Returns an HTML field value as float. This method is used at setFieldCb. WebServer doesn't know the type of a field, every field arrives as string. This method converts the string to the expected type. Don't call this method outside of setFieldCb, otherwise it can reset/crash/freeze MCU.

Returns
Float value of the field
Warning
Use this method only in setFieldCb, otherwise crash, freeze, MCU reset, or other unexpected behaviour can happen.
Example
float float_value;
// this method should be fast to prevent UART receive buffer overrun
void setFieldCb(const char * field_str)
{
String field = field_str;
if( field == F("field_id") )
{
float_value = webServer.getArgFloat();
}
}

Definition at line 1127 of file ELClientWebServer.cpp.

◆ getArgInt()

int32_t ELClientWebServer::getArgInt ( )

Returns an HTML field value as integer.

getArgInt()

Returns an HTML field value as integer. This method is used at setFieldCb. WebServer doesn't know the type of a field, every field arrives as string. This method converts the string to the expected type. Don't call this method outside of setFieldCb, otherwise it can reset/crash/freeze MCU.

Returns
Integer value of the field
Warning
Use this method only in setFieldCb, otherwise crash, freeze, MCU reset, or other unexpected behaviour can happen.
Example
int32_t int_value = 0;
// this method should be fast to prevent UART receive buffer overrun
void setFieldCb(const char * field_str)
{
String field = field_str;
if( field == F("field_id") )
{
int_value = webServer.getArgInt();
}
}

Definition at line 1039 of file ELClientWebServer.cpp.

◆ getArgString()

char * ELClientWebServer::getArgString ( )

Returns an HTML field value as string.

getArgString()

Returns an HTML field value as string. Don't call this method outside of setFieldCb, otherwise it can reset/crash/freeze MCU.

Returns
String value of the field
Warning
Use this method only in setFieldCb, otherwise crash, freeze, MCU reset, or other unexpected behaviour can happen.
Example
String str;
// this method should be fast to prevent UART receive buffer overrun
void setFieldCb(const char * field_str)
{
String field = field_str;
if( field == F("field_id") )
{
str = webServer.getArgString();
}
}

Definition at line 1065 of file ELClientWebServer.cpp.

◆ getInstance()

static ELClientWebServer * ELClientWebServer::getInstance ( )
inlinestatic

Returns the singleton web-server instance.

ELClientWebServer::getInstance()

Web-Server is a singleton object. This object can be read by calling ELClientWebServer::getInstance().

Returns
The singleton web-server instance.
Example code
static ELClientWebServer * getInstance()
Returns the singleton web-server instance.

Definition at line 186 of file ELClientWebServer.h.

◆ setArgBoolean() [1/2]

void ELClientWebServer::setArgBoolean ( const __FlashStringHelper *  name,
uint8_t  value 
)

Sets boolean value of a field.

setArgBoolean(const __FlashStringHelper * name, uint8_t value)

Sets boolean value of an HTML field. It can free up RAM memory if string constants are stored in flash instead of RAM.

Parameters
nameThe name of the field (stored in flash)
valueBoolean value
Supported HTML controls
  • INPUT
Warning
Use this method only in refreshCb/loadCb.
Example HTML
<form>
<input name="input" type="checkbox"/>
<input type="submit">
</form>
Example code
void loadCb(const char * url)
{
// sets the default value at loading
webServer.setArgBoolean( F("input"), TRUE );
}

Definition at line 767 of file ELClientWebServer.cpp.

Here is the call graph for this function:

◆ setArgBoolean() [2/2]

void ELClientWebServer::setArgBoolean ( const char *  name,
uint8_t  value 
)

Sets boolean value of a field.

setArgBoolean(const char * name, uint8_t value)

Sets boolean value of an HTML field.

Parameters
nameThe name of the field
valueBoolean value
Supported HTML controls
  • INPUT
Warning
Use this method only in refreshCb/loadCb.
Example HTML
<form>
<input name="input" type="checkbox"/>
<input type="submit">
</form>
Example code
void loadCb(const char * url)
{
// sets the default value at loading
webServer.setArgBoolean( "input", TRUE );
}

Definition at line 729 of file ELClientWebServer.cpp.

Here is the call graph for this function:

◆ setArgFloat() [1/2]

void ELClientWebServer::setArgFloat ( const __FlashStringHelper *  name,
float  value 
)

Sets float value of a field.

setArgFloat(const __FlashStringHelper * name, float value)

Sets float value of an HTML field. It can free up RAM memory if string constants are stored in flash instead of RAM.

Parameters
nameThe name of the field (stored in flash)
valueFloat value
Supported HTML controls
  • INPUT
Warning
Use this method only in refreshCb/loadCb.
Example HTML
<form>
<input name="input" type="number" step="0.01"/>
<input type="submit">
</form>
Example code
void loadCb(const char * url)
{
// sets the default value at loading
webServer.setArgFloat( F("input"), 12.3f );
}

Definition at line 1005 of file ELClientWebServer.cpp.

Here is the call graph for this function:

◆ setArgFloat() [2/2]

void ELClientWebServer::setArgFloat ( const char *  name,
float  value 
)

Sets float value of a field.

setArgFloat(const char * name, float value)

Sets float value of an HTML field.

Parameters
nameThe name of the field
valueFloat value
Supported HTML controls
  • INPUT
Warning
Use this method only in refreshCb/loadCb.
Example HTML
<form>
<input name="input" type="number" step="0.01"/>
<input type="submit">
</form>
Example code
void loadCb(const char * url)
{
// sets the default value at loading
webServer.setArgFloat( "input", 12.3f );
}

Definition at line 967 of file ELClientWebServer.cpp.

Here is the call graph for this function:

◆ setArgInt() [1/2]

void ELClientWebServer::setArgInt ( const __FlashStringHelper *  name,
int32_t  value 
)

Sets integer value of a field.

setArgInt(const __FlashStringHelper * name, int32_t value)

Sets integer value of an HTML field. It can free up RAM memory if string constants are stored in flash instead of RAM.

Parameters
nameThe name of the field (stored in flash)
valueInteger value
Supported HTML controls
  • INPUT
Warning
Use this method only in refreshCb/loadCb.
Example HTML
<form>
<input name="input" type="number"/>
<input type="submit">
</form>
Example code
void loadCb(const char * url)
{
// sets the default value at loading
webServer.setArgInt( F("input"), 123 );
}

Definition at line 845 of file ELClientWebServer.cpp.

Here is the call graph for this function:

◆ setArgInt() [2/2]

void ELClientWebServer::setArgInt ( const char *  name,
int32_t  value 
)

Sets integer value of a field.

setArgInt(const char * name, int32_t value)

Sets integer value of an HTML field.

Parameters
nameThe name of the field
valueInteger value
Supported HTML controls
  • INPUT
Warning
Use this method only in refreshCb/loadCb.
Example HTML
<form>
<input name="input" type="number"/>
<input type="submit">
</form>
Example code
void loadCb(const char * url)
{
// sets the default value at loading
webServer.setArgInt( "input", 123 );
}

Definition at line 807 of file ELClientWebServer.cpp.

Here is the call graph for this function:

◆ setArgJson() [1/3]

void ELClientWebServer::setArgJson ( const __FlashStringHelper *  name,
const __FlashStringHelper *  value 
)

Sets JSON value of a field.

setArgJson(const __FlashStringHelper * name, const __FlashStringHelper * value)

Sets JSON value to display an HTML field (list, table). It can free up RAM memory if string constants are stored in flash instead of RAM.

Parameters
nameThe name of the field (stored in flash)
valueJSON value (stored in flash)
Supported HTML controls
  • UL
  • OL
  • TABLE
Warning
Use this method only in refreshCb/loadCb.
Example List HTML
<UL id="list"/>
Example List code
void refreshCb(const char * url)
{
webServer.setArgJson( F("list"), F("[\"A\",\"B\",\"C\"]") );
}
Example Table HTML
<TABLE id="table"/>
Example Table code
void refreshCb(const char * url)
{
webServer.setArgJson( F("table"), F("[[\"A\",\"B\"],[\"1\",\"2\"]]") );
}

Definition at line 450 of file ELClientWebServer.cpp.

Here is the call graph for this function:

◆ setArgJson() [2/3]

void ELClientWebServer::setArgJson ( const __FlashStringHelper *  name,
const char *  value 
)

Sets JSON value of a field.

setArgJson(const __FlashStringHelper * name, const char * value)

Sets JSON value to display an HTML field (list, table). It can free up RAM memory if string constants are stored in flash instead of RAM.

Parameters
nameThe name of the field (stored in flash)
valueJSON value
Supported HTML controls
  • UL
  • OL
  • TABLE
Warning
Use this method only in refreshCb/loadCb.
Example List HTML
<UL id="list"/>
Example List code
void refreshCb(const char * url)
{
webServer.setArgJson( F("list"), "[\"A\",\"B\",\"C\"]" );
}
Example Table HTML
<TABLE id="table"/>
Example Table code
void refreshCb(const char * url)
{
webServer.setArgJson( F("table"), "[[\"A\",\"B\"],[\"1\",\"2\"]]" );
}

Definition at line 500 of file ELClientWebServer.cpp.

Here is the call graph for this function:

◆ setArgJson() [3/3]

void ELClientWebServer::setArgJson ( const char *  name,
const char *  value 
)

Sets JSON value of a field.

setArgJson(const char * name, const char * value)

Sets JSON value to display an HTML field (list, table).

Parameters
nameThe name of the field
valueJSON value
Supported HTML controls
  • UL
  • OL
  • TABLE
Warning
Use this method only in refreshCb/loadCb.
Example List HTML
<UL id="list"/>
Example List code
void refreshCb(const char * url)
{
webServer.setArgJson( "list", "[\"A\",\"B\",\"C\"]" );
}
Example Table HTML
<TABLE id="table"/>
Example Table code
void refreshCb(const char * url)
{
webServer.setArgJson( "table", "[[\"A\",\"B\"],[\"1\",\"2\"]]" );
}

Definition at line 404 of file ELClientWebServer.cpp.

Here is the call graph for this function:

◆ setArgNull() [1/2]

void ELClientWebServer::setArgNull ( const __FlashStringHelper *  name)

Sets null value to a field.

setArgNull(const __FlashStringHelper * name)

Sets null value to an HTML field. It can free up RAM memory if string constants are stored in flash instead of RAM.

Parameters
nameThe name of the field (stored in flash)
Supported HTML controls
  • P
  • DIV
  • TR
  • TH
  • TD
  • TEXTAREA
  • SPAN
  • INPUT
  • SELECT
Warning
Use this method only in refreshCb/loadCb.
Example HTML
<DIV id="div"/>
Example code
void refreshCb(const char * url)
{
webServer.setArgNull( F("div") );
}

Definition at line 928 of file ELClientWebServer.cpp.

Here is the call graph for this function:

◆ setArgNull() [2/2]

void ELClientWebServer::setArgNull ( const char *  name)

Sets null value to a field.

setArgNull(const char * name)

Sets null value to an HTML field.

Parameters
nameThe name of the field
Supported HTML controls
  • P
  • DIV
  • TR
  • TH
  • TD
  • TEXTAREA
  • SPAN
  • INPUT
  • SELECT
Warning
Use this method only in refreshCb/loadCb.
Example HTML
<DIV id="div"/>
Example code
void refreshCb(const char * url)
{
webServer.setArgNull( "div" );
}

Definition at line 888 of file ELClientWebServer.cpp.

Here is the call graph for this function:

◆ setArgString() [1/3]

void ELClientWebServer::setArgString ( const __FlashStringHelper *  name,
const __FlashStringHelper *  value 
)

Sets string value of a field.

setArgString(const __FlashStringHelper * name, const __FlashStringHelper * value)

Sets the string or inner HTML value of an HTML field. It can free up RAM memory if string constants are stored in flash instead of RAM.

Parameters
nameThe name of the field (stored in flash)
valueString value (stored in flash)
Supported HTML controls
HTML Field Type
P Inner HTML
DIV Inner HTML
TR Inner HTML
TH Inner HTML
TD Inner HTML
TEXTAREA Inner HTML
SPAN Inner HTML
INPUT String value
SELECT String value
Warning
Use this method only in refreshCb/loadCb.
Example for inner HTML (HTML)
<DIV id="div"/>
Example for inner HTML (code)
void refreshCb(const char * url)
{
webServer.setArgString( F("div"), F("Line 1 <br/> Line 2") );
}
Example for string value (HTML)
<form>
<input name="input" type="text"/>
<input type="submit">
</form>
Example for string value (code)
void loadCb(const char * url)
{
// sets the default value at loading
webServer.setArgString( F("input"), F("This is the value") );
}

Definition at line 625 of file ELClientWebServer.cpp.

Here is the call graph for this function:

◆ setArgString() [2/3]

void ELClientWebServer::setArgString ( const __FlashStringHelper *  name,
const char *  value 
)

Sets string value of a field.

setArgString(const __FlashStringHelper * name, const char * value)

Sets the string or inner HTML value of an HTML field. It can free up RAM memory if string constants are stored in flash instead of RAM.

Parameters
nameThe name of the field (stored in flash)
valueString value
Supported HTML controls
HTML Field Type
P Inner HTML
DIV Inner HTML
TR Inner HTML
TH Inner HTML
TD Inner HTML
TEXTAREA Inner HTML
SPAN Inner HTML
INPUT String value
SELECT String value
Warning
Use this method only in refreshCb/loadCb.
Example for inner HTML (HTML)
<DIV id="div"/>
Example for inner HTML (code)
void refreshCb(const char * url)
{
webServer.setArgString( F("div"), "Line 1 <br/> Line 2" );
}
Example for string value (HTML)
<form>
<input name="input" type="text"/>
<input type="submit">
</form>
Example for string value (code)
void loadCb(const char * url)
{
// sets the default value at loading
webServer.setArgString( F("input"), "This is the value" );
}

Definition at line 688 of file ELClientWebServer.cpp.

Here is the call graph for this function:

◆ setArgString() [3/3]

void ELClientWebServer::setArgString ( const char *  name,
const char *  value 
)

Sets string value of a field.

setArgString(const char * name, const char * value)

Sets the string or inner HTML value of an HTML field.

Parameters
nameThe name of the field
valueString value
Supported HTML controls
HTML Field Type
P Inner HTML
DIV Inner HTML
TR Inner HTML
TH Inner HTML
TD Inner HTML
TEXTAREA Inner HTML
SPAN Inner HTML
INPUT String value
SELECT String value
Warning
Use this method only in refreshCb/loadCb.
Example for inner HTML (HTML)
<DIV id="div"/>
Example for inner HTML (code)
void refreshCb(const char * url)
{
webServer.setArgString( "div", "Line 1 <br/> Line 2" );
}
Example for string value (HTML)
<form>
<input name="input" type="text"/>
<input type="submit">
</form>
Example for string value (code)
void loadCb(const char * url)
{
// sets the default value at loading
webServer.setArgString( "input", "This is the value" );
}

Definition at line 564 of file ELClientWebServer.cpp.

Here is the call graph for this function:

◆ setup()

void ELClientWebServer::setup ( )

Initializes web-server.

setup()

Initialization means to subscribe to Web-Server callback of Esp-Link.

Example code
void resetCb(void) {
Serial.println("EL-Client (re-)starting!");
bool ok = false;
do {
ok = esp.Sync(); // sync up with esp-link, blocks for up to 2 seconds
if (!ok) Serial.println("EL-Client sync failed!");
} while(!ok);
Serial.println("EL-Client synced!");
webServer.setup();
}
void setup()
{
Serial.begin(115200);
URLHandler *handler = webServer.createURLHandler(F("/mypage.html.json"));
handler->loadCb.attach(&myLoadCb);
handler->refreshCb.attach(&myRefreshCb);
handler->buttonCb.attach(&myButtonPressCb);
handler->setFieldCb.attach(&mySetFieldCb);
esp.resetCb = resetCb;
}
void resetCb(void)
Definition test.ino:35

Definition at line 264 of file ELClientWebServer.cpp.

Here is the call graph for this function:

The documentation for this class was generated from the following files: