45 #ifndef __OmWebPages__
46 #define __OmWebPages__
49 #include "OmXmlWriter.h"
51 #include "OmWebRequest.h"
55 #ifdef ARDUINO_ARCH_ESP8266
56 #include "ESP8266WiFi.h"
58 #ifdef ARDUINO_ARCH_ESP32
63 #define String std::string
64 typedef unsigned char IPAddress[4];
68 #define UNUSED(x) (void)(x)
72 typedef void (* OmWebActionProc)(
const char *pageName,
const char *parameterName,
int value,
int ref1,
void *ref2);
75 typedef void (* OmHtmlProc)(
OmXmlWriter &writer,
int ref1,
void *ref2);
99 void setVisible(
bool visible,
const char *name,
int value);
115 const char *bonjourName =
"";
116 long long uptimeMillis;
117 const char *ssid =
"";
142 void *
beginPage(
const char *pageName,
bool listed =
true);
144 void resumePage(
void *previousPage);
151 void addPageLink(
const char *pageLink, OmWebActionProc proc = NULL,
int ref1 = 0,
void *ref2 = 0);
157 OmWebPageItem *
addButton(
const char *buttonName, OmWebActionProc proc = NULL,
int ref1 = 0,
void *ref2 = 0);
165 OmWebPageItem *
addSlider(
const char *sliderName, OmWebActionProc proc = NULL,
int value = 0,
int ref1 = 0,
void *ref2 = 0);
168 OmWebPageItem *
addSlider(
int rangeLow,
int rangeHigh,
const char *sliderName, OmWebActionProc proc = NULL,
int value = 0,
int ref1 = 0,
void *ref2 = 0);
171 OmWebPageItem *
addTime(
const char *itemName, OmWebActionProc proc = NULL,
int value = 0,
int ref1 = 0,
void *ref2 = 0);
174 OmWebPageItem *
addColor(
const char *itemName, OmWebActionProc proc = NULL,
int value = 0,
int ref1 = 0,
void *ref2 = 0);
177 OmWebPageItem *
addSelectWithLink(
const char *itemName,
const char *url, OmWebActionProc proc = NULL,
int value = 0,
int ref1 = 0,
void *ref2 = 0);
179 OmWebPageItem *
addSelect(
const char *itemName, OmWebActionProc proc = NULL,
int value = 0,
int ref1 = 0,
void *ref2 = 0);
187 OmWebPageItem *
addCheckbox(
const char *itemName,
const char *checkboxName, OmWebActionProc proc = NULL,
int value = 0,
int ref1 = 0,
void *ref2 = 0);
189 void addCheckboxX(
const char *checkboxName,
int value = 0);
193 void addHtml(OmHtmlProc proc,
int ref1 = 0,
void *ref2 = 0);
209 void addUrlHandler(
const char *path, OmUrlHandlerProc proc,
int ref1 = 0,
void *ref2 = 0);
212 void addUrlHandler(OmUrlHandlerProc proc,
int ref1 = 0,
void *ref2 = 0);
237 void addEepromConfigForm(OmHtmlProc callbackProc,
int eepromFieldGroup);
280 static void renderPageBeginningWithRedirect(
OmXmlWriter &w,
const char *redirectUrl,
int redirectSeconds,
const char *pageTitle =
"",
int bgColor = 0xffffff,
OmWebPages *p = NULL);
282 void setValue(
const char *pageName,
const char *itemName,
int value);
283 int getValue(
const char *pageName,
const char *itemName);
293 const char *url =
"";
294 OmUrlHandlerProc handlerProc = NULL;
299 bool doAction(
const char *pageName,
const char *itemName);
300 static void renderStyle(
OmXmlWriter &w,
int bgColor = 0xffffff);
306 Page *findPage(
const char *pageName,
bool byId =
false);
307 PageItem *findPageItem(
const char *pageName,
const char *itemName,
bool byId =
false);
309 Page *homePage = NULL;
310 std::vector<Page *> pages;
311 std::vector<UrlHandler *>urlHandlers;
312 Page *currentPage = 0;
314 UrlHandler urlHandler;
319 OmHtmlProc headerProc = NULL;
320 OmHtmlProc footerProc = NULL;
324 int bgColor = 0xffffff;
326 const char *__date__;
327 const char *__time__;
328 const char *__file__;
330 OmHtmlProc eepromConfigCallbackProc = NULL;
339 uint32_t omGetChipId();
void addSelectOption(const char *optionName, int optionValue)
Add one selectable item, and its integer value if selected.
Definition: OmWebPages.cpp:914
void setValue(int value)
changes the value, but only visible on next browser load or refresh
Definition: OmWebPages.cpp:138
void setFooterProc(OmHtmlProc footerProc)
Override the default footer html.
Definition: OmWebPages.cpp:808
void setHeaderProc(OmHtmlProc headerProc)
Override the default header html.
Definition: OmWebPages.cpp:803
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:1671
static void renderPageBeginning(OmXmlWriter &w, const char *pageTitle="", int bgColor=0xffffff, OmWebPages *p=NULL)
in a OmUrlHandlerProc Render the beginning of the page, leaving <body> element open and ready.
Definition: OmWebPages.cpp:1325
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:793
void * beginPage(const char *pageName, bool listed=true)
Start defining a new page. Subsequent calls like addButton() affect this page. If a page of this name...
Definition: OmWebPages.cpp:745
unsigned int greatestRenderLength
Definition: OmWebPages.h:264
void addStaticHtml(String staticHtml)
Add a string of static prebuilt HTML. Included in web page unchecked, you're on your own!
Definition: OmWebPages.cpp:957
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:844
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:833
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:813
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:895
unsigned int requestsParam
Definition: OmWebPages.h:261
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:1651
void setBgColor(int bgColor)
set the background color for next web request, 0xRRGGBB
Definition: OmWebPages.cpp:1646
void addPageLinkMini(const char *pageLink, const char *label)
Add a small-button style link to a page.
Definition: OmWebPages.cpp:824
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:1482
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:923
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:798
void setVisible(bool visible)
show or hide
Definition: OmWebPages.cpp:121
void setPageArrivalAction(OmWebActionProc arrivalAction, int ref1, void *ref2)
Definition: OmWebPages.cpp:777
int getValue()
current value
Definition: OmWebPages.cpp:134
const char * getName()
current name
Definition: OmWebPages.cpp:111
OmWebPageItem * addTime(const char *itemName, OmWebActionProc proc=NULL, int value=0, int ref1=0, void *ref2=0)
Add a time-input.
Definition: OmWebPages.cpp:871
A class that routes and serves web pages, and manages control values, typically works with OmWebServe...
Definition: OmWebPages.h:123
void renderPageButton(OmXmlWriter &w, const char *pageName)
Within an HtmlProc: Adds a floating link-button to another page.
Definition: OmWebPages.cpp:1419
Definition: OmWebPages.cpp:40
unsigned int requestsAll
Definition: OmWebPages.h:258
void setName(const char *name)
change name
Definition: OmWebPages.cpp:116
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:852
OmWebPageItem * addSelectWithLink(const char *itemName, const char *url, 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:900
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:883
OmWebPages()
Definition: OmWebPages.cpp:690
void addCheckboxX(const char *checkboxName, int value=0)
Add additional checkboxes.
Definition: OmWebPages.cpp:938
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:726
void addHtml(OmHtmlProc 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:947
Definition: OmWebPages.h:89
static char httpBase[32]
Most recent server ip. Nastily global.
Definition: OmWebPages.h:286
Definition: OmWebPages.h:109
Definition: OmWebPages.cpp:144