45 #ifndef __OmWebPages__
46 #define __OmWebPages__
49 #include "OmXmlWriter.h"
51 #include "OmWebRequest.h"
54 #ifdef ARDUINO_ARCH_ESP8266
55 #include "ESP8266WiFi.h"
57 #ifdef ARDUINO_ARCH_ESP32
62 #define String std::string
63 typedef unsigned char IPAddress[4];
67 #define UNUSED(x) (void)(x)
71 typedef void (* OmWebActionProc)(
const char *pageName,
const char *parameterName,
int value,
int ref1,
void *ref2);
74 typedef void (* HtmlProc)(
OmXmlWriter &writer,
int ref1,
void *ref2);
98 void setVisible(
bool visible,
const char *name,
int value);
114 const char *bonjourName =
"";
115 long long uptimeMillis;
116 const char *ssid =
"";
144 void addPageLink(
const char *pageLink, OmWebActionProc proc = NULL,
int ref1 = 0,
void *ref2 = 0);
147 OmWebPageItem *
addButton(
const char *buttonName, OmWebActionProc proc = NULL,
int ref1 = 0,
void *ref2 = 0);
155 OmWebPageItem *
addSlider(
const char *sliderName, OmWebActionProc proc = NULL,
int value = 0,
int ref1 = 0,
void *ref2 = 0);
158 OmWebPageItem *
addSlider(
int rangeLow,
int rangeHigh,
const char *sliderName, OmWebActionProc proc = NULL,
int value = 0,
int ref1 = 0,
void *ref2 = 0);
161 OmWebPageItem *
addTime(
const char *itemName, OmWebActionProc proc = NULL,
int value = 0,
int ref1 = 0,
void *ref2 = 0);
164 OmWebPageItem *
addColor(
const char *itemName, OmWebActionProc proc = NULL,
int value = 0,
int ref1 = 0,
void *ref2 = 0);
167 OmWebPageItem *
addSelect(
const char *itemName, OmWebActionProc proc = NULL,
int value = 0,
int ref1 = 0,
void *ref2 = 0);
175 OmWebPageItem *
addCheckbox(
const char *itemName,
const char *checkboxName, OmWebActionProc proc = NULL,
int value = 0,
int ref1 = 0,
void *ref2 = 0);
177 void addCheckboxX(
const char *checkboxName,
int value = 0);
181 void addHtml(HtmlProc proc,
int ref1 = 0,
void *ref2 = 0);
197 void addUrlHandler(
const char *path, OmUrlHandlerProc proc,
int ref1 = 0,
void *ref2 = 0);
200 void addUrlHandler(OmUrlHandlerProc proc,
int ref1 = 0,
void *ref2 = 0);
264 static void renderPageBeginningWithRedirect(
OmXmlWriter &w,
const char *redirectUrl,
int redirectSeconds,
const char *pageTitle =
"",
int bgColor = 0xffffff);
266 void setValue(
const char *pageName,
const char *itemName,
int value);
267 int getValue(
const char *pageName,
const char *itemName);
276 const char *url =
"";
277 OmUrlHandlerProc handlerProc = NULL;
282 bool doAction(
const char *pageName,
const char *itemName);
283 static void renderStyle(
OmXmlWriter &w,
int bgColor = 0xffffff);
289 Page *findPage(
const char *pageName,
bool byId =
false);
290 PageItem *findPageItem(
const char *pageName,
const char *itemName,
bool byId =
false);
292 Page *homePage = NULL;
293 std::vector<Page *> pages;
294 std::vector<UrlHandler *>urlHandlers;
295 Page *currentPage = 0;
297 UrlHandler urlHandler;
302 HtmlProc headerProc = NULL;
303 HtmlProc footerProc = NULL;
307 int bgColor = 0xffffff;
309 const char *__date__;
310 const char *__time__;
311 const char *__file__;
void addSelectOption(const char *optionName, int optionValue)
Add one selectable item, and its integer value if selected.
Definition: OmWebPages.cpp:809
void setValue(int value)
changes the value, but only visible on next browser load or refresh
Definition: OmWebPages.cpp:91
void renderHttpResponseHeader(const char *contentType, int response)
in a OmUrlHandlerProc, set the mimetype (like "text/plain") and response code (200 is OK)
Definition: OmWebPages.cpp:1467
Definition: OmXmlWriter.h:91
void allowHeader(bool allowHeader)
By default, any header proc is used on every page. Disable for current page here.
Definition: OmWebPages.cpp:703
unsigned int greatestRenderLength
Definition: OmWebPages.h:248
void addStaticHtml(String staticHtml)
Add a string of static prebuilt HTML. Included in web page unchecked, you're on your own!
Definition: OmWebPages.cpp:852
OmWebPageItem * addButtonWithLink(const char *buttonName, const char *url, OmWebActionProc proc=NULL, int ref1=0, void *ref2=0)
Add a button on the current page, which fires a page redirect after the button-up....
Definition: OmWebPages.cpp:745
OmWebPageItem * addButton(const char *buttonName, OmWebActionProc proc=NULL, int ref1=0, void *ref2=0)
Add a button on the current page. Calls the action proc with value 1 for press, 0 for release.
Definition: OmWebPages.cpp:734
void addPageLink(const char *pageLink, OmWebActionProc proc=NULL, int ref1=0, void *ref2=0)
Add a link on the current page that goes to another page. Also can call an action proc.
Definition: OmWebPages.cpp:723
OmWebPageItem * addSelect(const char *itemName, OmWebActionProc proc=NULL, int value=0, int ref1=0, void *ref2=0)
Begin a menu select control. Choices are added with addSelectOption()
Definition: OmWebPages.cpp:796
unsigned int requestsParam
Definition: OmWebPages.h:245
Definition: OmWebRequest.h:54
void addUrlHandler(const char *path, OmUrlHandlerProc proc, int ref1=0, void *ref2=0)
Add an arbitrary URL handler.
Definition: OmWebPages.cpp:1447
void setBgColor(int bgColor)
set the background color for next web request, 0xRRGGBB
Definition: OmWebPages.cpp:1442
void addHtml(HtmlProc proc, int ref1=0, void *ref2=0)
Add a block of custom dynamic HTML to the page. Your proc is called each time the page is requested.
Definition: OmWebPages.cpp:842
bool handleRequest(OmIByteStream *consumer, const char *pathAndQuery, OmRequestInfo *requestInfo)
Explicitly process a request. (Not typically used.) If you used omWebServer.setHandler(omWebPages),...
Definition: OmWebPages.cpp:1293
OmWebPageItem * addCheckbox(const char *itemName, const char *checkboxName, OmWebActionProc proc=NULL, int value=0, int ref1=0, void *ref2=0)
Add a single checkbox. If checkboxName is NULL, then the first checkbox will be added by addCheckboxX...
Definition: OmWebPages.cpp:818
Definition: OmXmlWriter.h:53
void allowFooter(bool allowFooter)
By default, any footer proc is used on every page. Disable for current page here.
Definition: OmWebPages.cpp:708
void setVisible(bool visible)
show or hide
Definition: OmWebPages.cpp:74
int getValue()
current value
Definition: OmWebPages.cpp:87
const char * getName()
current name
Definition: OmWebPages.cpp:64
void setHeaderProc(HtmlProc headerProc)
Override the default header html.
Definition: OmWebPages.cpp:713
OmWebPageItem * addTime(const char *itemName, OmWebActionProc proc=NULL, int value=0, int ref1=0, void *ref2=0)
Add a time-input.
Definition: OmWebPages.cpp:772
A class that routes and serves web pages, and manages control values, typically works with OmWebServe...
Definition: OmWebPages.h:122
void renderPageButton(OmXmlWriter &w, const char *pageName)
Within an HtmlProc: Adds a floating link-button to another page.
Definition: OmWebPages.cpp:1230
Definition: OmWebPages.cpp:31
unsigned int requestsAll
Definition: OmWebPages.h:242
void setName(const char *name)
change name
Definition: OmWebPages.cpp:69
OmWebPageItem * addSlider(const char *sliderName, OmWebActionProc proc=NULL, int value=0, int ref1=0, void *ref2=0)
Add a slider control on the current page. The range is 0 to 100, and calls your param proc when chang...
Definition: OmWebPages.cpp:753
OmWebPageItem * addColor(const char *itemName, OmWebActionProc proc=NULL, int value=0, int ref1=0, void *ref2=0)
Add a color-input, int value is 0xRRGGBB.
Definition: OmWebPages.cpp:784
OmWebPages()
Definition: OmWebPages.cpp:625
void setFooterProc(HtmlProc footerProc)
Override the default footer html.
Definition: OmWebPages.cpp:718
void addCheckboxX(const char *checkboxName, int value=0)
Add additional checkboxes.
Definition: OmWebPages.cpp:833
void setBuildDateAndTime(const char *date, const char *time, const char *file=NULL)
say p.setBuildDateAndTime(DATE, TIME) so the info web page can display it.
Definition: OmWebPages.cpp:660
void beginPage(const char *pageName)
Start defining a new page. Subsequent calls like addButton() affect this page. If a page of this name...
Definition: OmWebPages.cpp:679
Definition: OmWebPages.h:88
Definition: OmWebPages.h:108
Definition: OmWebPages.cpp:97
static void renderPageBeginning(OmXmlWriter &w, const char *pageTitle="", int bgColor=0xffffff)
in a OmUrlHandlerProc Render the beginning of the page, leaving <body> element open and ready.
Definition: OmWebPages.cpp:1148