EmbAJAX
Simplistic framework for creating and handling displays and controls on a web page served by an embeddable device (Arduino or other microcontroller with Arduino support).
Public Member Functions | Protected Attributes | List of all members
EmbAJAXPage< NUM > Class Template Reference

The main interface class. More...

#include <EmbAJAX.h>

Inheritance diagram for EmbAJAXPage< NUM >:
Inheritance graph
[legend]
Collaboration diagram for EmbAJAXPage< NUM >:
Collaboration graph
[legend]

Public Member Functions

 EmbAJAXPage (EmbAJAXBase *children[NUM], const char *title, const char *header_add=0, uint16_t min_interval=100)
 
void printPage () override
 
void print () const override
 
void handleRequest (void(*change_callback)()=0) override
 
bool hasActiveClient (uint64_t latency_ms=5000) const
 
- Public Member Functions inherited from EmbAJAXContainer< NUM >
 EmbAJAXContainer (EmbAJAXBase *children[NUM])
 
bool sendUpdates (uint16_t since, bool first) override
 
EmbAJAXElementfindChild (const char *id) const override final
 
- Public Member Functions inherited from EmbAJAXBase
virtual EmbAJAXElementtoElement ()
 
void setVisible (bool visible)
 
void setEnabled (bool enabled)
 

Protected Attributes

const char * _title
 
const char * _header_add
 
uint16_t _min_interval
 
uint64_t _latest_ping
 
- Protected Attributes inherited from EmbAJAXContainer< NUM >
EmbAJAXBase ** _children
 

Additional Inherited Members

- Public Types inherited from EmbAJAXBase
enum  Property {
  Visibility , Enabledness , Value , FirstElementSpecificProperty ,
  HTMLAllowed
}
 
- Static Public Member Functions inherited from EmbAJAXBase
static void setDriver (EmbAJAXOutputDriverBase *driver)
 
- Protected Member Functions inherited from EmbAJAXContainer< NUM >
void setBasicProperty (uint8_t num, bool status) override
 
- Protected Member Functions inherited from EmbAJAXBase
void printChildren (EmbAJAXBase **children, size_t num) const
 
bool sendUpdates (EmbAJAXBase **children, size_t num, uint16_t since, bool first)
 
EmbAJAXElementfindChild (EmbAJAXBase **children, size_t num, const char *id) const
 
void printPage (EmbAJAXBase **children, size_t num, const char *_title, const char *_header, uint16_t _min_interval) const
 
void handleRequest (EmbAJAXBase **children, size_t num, void(*change_callback)())
 
- Static Protected Attributes inherited from EmbAJAXBase
static EmbAJAXOutputDriverBase_driver
 
static char itoa_buf [8]
 
constexpr static const char null_string [1]
 

Detailed Description

template<size_t NUM>
class EmbAJAXPage< NUM >

The main interface class.

This is the main interface class. Create a web-page with a list of elements on it, and arrange for print() (for page loads) adn handleRequest() (for AJAX calls) to be called on requests. By default, both page loads, and AJAX are handled on the same URL, but the first via GET, and the second via POST.

Constructor & Destructor Documentation

◆ EmbAJAXPage()

template<size_t NUM>
EmbAJAXPage< NUM >::EmbAJAXPage ( EmbAJAXBase children[NUM],
const char *  title,
const char *  header_add = 0,
uint16_t  min_interval = 100 
)
inline

Create a web page.

Parameters
childrenlist of elements on the page
titletitle (may be 0). This string is not copied, please do not use a temporary string.
header_addliteral text (may be 0) to be added to the header, e.g. CSS (linked or in-line). This string is not copied, please do not use a temporary string).
min_intervalminimum interval (ms) between two requests sent by a single client. A lower value may reduce latency at the cost of traffic/CPU.

Member Function Documentation

◆ handleRequest()

template<size_t NUM>
void EmbAJAXPage< NUM >::handleRequest ( void(*)()  change_callback = 0)
inlineoverridevirtual

Handle AJAX client request. You should arrange for this function to be called, whenever there is a POST request to whichever URL you served the page itself, from.

Parameters
change_callbackIf some value has changed in the client, this function will be called. While it is optional to specify this, if there are any changes that may need to be sent back to the client in response to the change, you should specify this function, and handle the change inside it. This way, an update can be sent back to the client, immediately, for a smooth UI experience. (Otherwise the client will be updated on the next poll).

Implements EmbAJAXPageBase.

◆ hasActiveClient()

template<size_t NUM>
bool EmbAJAXPage< NUM >::hasActiveClient ( uint64_t  latency_ms = 5000) const
inline

Returns true if a client seems to be connected (connected clients should send a ping at least once per second; by default this function returns whether a ping has been seen within the last 5000 ms.

Parameters
latency_msNumber of milliseconds to consider as maximum silence period for an active connection

◆ print()

template<size_t NUM>
void EmbAJAXPage< NUM >::print ( ) const
inlineoverridevirtual

Serve the page including headers and all child elements. You should arrange for this function to be called, whenever there is a GET request to the desired URL.

Reimplemented from EmbAJAXContainer< NUM >.

◆ printPage()

template<size_t NUM>
void EmbAJAXPage< NUM >::printPage ( )
inlineoverridevirtual

Duplication of print(), needed for internal reasons. Use print(), instead!

Implements EmbAJAXPageBase.


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