|
RSeries astromech firmware
|
|
Go to the documentation of this file. 1 #ifndef WifiWebServer_h
2 #define WifiWebServer_h
6 #include <WiFiClient.h>
17 virtual String
get() = 0;
18 virtual void set(String val) = 0;
42 WBoolean(
bool (*getValue)(),
void (*setValue)(
bool)) :
48 virtual String
get()
override
53 virtual void set(String val)
override
67 WInteger(
int (*getValue)(),
void (*setValue)(
int)) :
73 virtual String
get()
override
80 virtual void set(String val)
override
94 WString(String (*getValue)(),
void (*setValue)(String)) :
105 virtual String
get()
override
112 virtual void set(String val)
override
128 virtual void emitBody(Print& out)
const = 0;
218 out.println(
"var "+String(
fID)+
"_val_ = '"+
fValue->
get()+
"';\n");
220 out.println(
"var "+String(
fID)+
"_val_ = "+
fValue->
get()+
";\n");
264 static bool sAlign =
true;
332 appendCSSf(
".%s_css { width: 300px; }",
id.c_str());
334 appendBodyf(
"<p>%s: <span id='%s_val'></span></p>\n", title.c_str(),
id.c_str());
336 appendBodyf(
"<span id='%s_val'></span>\n",
id.c_str());
337 appendBodyf(
"<input type='range' min='%d' max='%d' class='%s_css' id='%s_slider' onchange='updateValue_%s(this.value)'/>\n", min, max,
id.c_str(),
id.c_str(),
id.c_str());
339 appendScriptf(
"var %s = document.getElementById('%s_slider');\n",
id.c_str(),
id.c_str());
340 appendScriptf(
"%s.value = %s_val_;\n",
id.c_str(),
id.c_str());
341 appendScriptf(
"var %s_priv = document.getElementById('%s_val'); %s_priv.innerHTML = %s.value;\n",
id.c_str(),
id.c_str(),
id.c_str(),
id.c_str());
342 appendScriptf(
"%s.oninput = function() { %s.value = this.value; %s_priv.innerHTML = this.value; }\n",
id.c_str(),
id.c_str(),
id.c_str());
343 appendScriptf(
"function updateValue_%s(pos) {fetchNoload('%s', pos); {Connection: close};}\n",
id.c_str(),
id.c_str());
355 appendCSSf(
".%s_css { width: 300px; }",
id.c_str());
357 appendBodyf(
"<p><span id='%s_val'></span></p>\n",
id.c_str());
359 appendBodyf(
"<span id='%s_val'></span>\n",
id.c_str());
360 appendBodyf(
"<input type='checkbox' id='%s_cbox' onchange='updateValue_%s(this.checked)'/>\n",
id.c_str(),
id.c_str());
361 appendBodyf(
"<label class='%s_css' for='%s_cbox'>%s</label>\n",
id.c_str(),
id.c_str(), title.c_str());
362 appendScriptf(
"var %s = document.getElementById('%s_cbox');\n",
id.c_str(),
id.c_str());
363 appendScriptf(
"%s.checked = %s_val_;\n",
id.c_str(),
id.c_str());
364 appendScriptf(
"function updateValue_%s(pos) {fetchNoload('%s', pos); {Connection: close};}\n",
id.c_str(),
id.c_str());
377 appendCSSf(
".%s_css { width: 300px; }",
id.c_str());
379 appendBodyf(
"<p><span id='%s_val'></span></p>\n",
id.c_str());
381 appendBodyf(
"<span id='%s_val'></span>\n",
id.c_str());
382 appendBodyf(
"<input type='checkbox' id='%s_cbox' onchange='updateValue_%s(this.checked)'/>\n",
id.c_str(),
id.c_str());
383 appendBodyf(
"<label class='%s_css' for='%s_cbox'>%s</label>\n",
id.c_str(),
id.c_str(), title.c_str());
384 appendScriptf(
"var %s = document.getElementById('%s_cbox');\n",
id.c_str(),
id.c_str());
385 appendScriptf(
"%s.checked = %s_val_;\n",
id.c_str(),
id.c_str());
386 appendScriptf(
"function updateValue_%s(pos) {fetchLoad('%s', pos); {Connection: close};}\n",
id.c_str(),
id.c_str());
393 WButton(String title, String
id,
void (*pressed)()) :
397 appendCSSf(
".%s_css { width: 300px; }",
id.c_str());
399 appendBodyf(
"<p><span id='%s_val'></span></p>\n",
id.c_str());
400 appendBodyf(
"<input type='button' id='%s_btn' value='%s' onclick='pressed_%s()'/>\n",
id.c_str(), title.c_str(),
id.c_str());
401 appendScriptf(
"function pressed_%s() {fetchNoload('%s', true); {Connection: close};}\n",
id.c_str(),
id.c_str());
407 appendCSSf(
".%s_css { width: 300px; }",
id.c_str());
409 appendBodyf(
"<p><span id='%s_val'></span></p>\n",
id.c_str());
410 appendBodyf(
"<input type='button' id='%s_btn' value='%s' onclick='window.location.href=\"%s\"'/>\n",
id.c_str(), title.c_str(), href.c_str());
413 WButton(String title, String
id, String href,
void (*pressed)()) :
418 appendCSSf(
".%s_css { width: 300px; }",
id.c_str());
420 appendBodyf(
"<p><span id='%s_val'></span></p>\n",
id.c_str());
421 appendBodyf(
"<input type='button' id='%s_btn' value='%s' onclick='pressed_%s()'/>\n",
id.c_str(), title.c_str(),
id.c_str());
422 appendScriptf(
"function pressed_%s() {window.location.href='\"%s?%s=true&\"'; {Connection: close};}\n",
id.c_str(), href.c_str(),
id.c_str());
425 WButton(String title, String
id,
bool reload,
void (*pressed)()) :
430 appendCSSf(
".%s_css { width: 300px; }",
id.c_str());
432 appendBodyf(
"<p><span id='%s_val'></span></p>\n",
id.c_str());
433 appendBodyf(
"<input type='button' id='%s_btn' value='%s' onclick='pressed_%s()'/>\n",
id.c_str(), title.c_str(),
id.c_str());
434 appendScriptf(
"function pressed_%s() {fetchLoad('%s', true); {Connection: close};}\n",
id.c_str(),
id.c_str());
442 WButton(title, id, true, pressed)
450 WLabel(String text, String
id,
bool (*enabled)() =
nullptr)
454 appendCSSf(
".%s_css { width: 300px; }",
id.c_str());
455 appendBodyf(
"<p><span id='%s_val'></span></p>\n",
id.c_str());
456 appendBodyf(
"<label class='%s_css'>%s</label>\n",
id.c_str(), text.c_str());
468 appendCSSf(
".%s_css { width: 300px; }",
id.c_str());
469 appendBodyf(
"<p><span id='%s_val'></span></p>\n",
id.c_str());
470 appendBodyf(
"<label class='%s_css' for='%s_fld'>%s</label>\n",
id.c_str(),
id.c_str(), title.c_str());
471 appendBodyf(
"<input type='text' id='%s_fld' onchange='updateValue_%s(this.value)'/>\n",
id.c_str(),
id.c_str());
472 appendScriptf(
"var %s = document.getElementById('%s_fld');\n",
id.c_str(),
id.c_str());
473 appendScriptf(
"%s.value = %s_val_;\n",
id.c_str(),
id.c_str());
474 appendScriptf(
"function updateValue_%s(pos) {fetchNoload('%s', pos); {Connection: close};}\n",
id.c_str(),
id.c_str());
486 appendCSSf(
".%s_css { width: 300px; }",
id.c_str());
487 appendBodyf(
"<p><span id='%s_val'></span></p>\n",
id.c_str());
488 appendBodyf(
"<label class='%s_css' for='%s_fld'>%s</label>\n",
id.c_str(),
id.c_str(), title.c_str());
489 appendBodyf(
"<input type='text' id='%s_fld' onchange='updateValue_%s(this.value)'/>\n",
id.c_str(),
id.c_str());
490 appendScriptf(
"var %s = document.getElementById('%s_fld');\n",
id.c_str(),
id.c_str());
491 appendScriptf(
"setInputFilter(%s, function(value) {",
id.c_str());
494 appendScriptf(
"%s.value = %s_val_;\n",
id.c_str(),
id.c_str());
495 appendScriptf(
"function updateValue_%s(pos) {fetchNoload('%s', pos); {Connection: close};}\n",
id.c_str(),
id.c_str());
507 appendCSSf(
".%s_css { width: 300px; }",
id.c_str());
508 appendBodyf(
"<p><span id='%s_val'></span></p>\n",
id.c_str());
509 appendBodyf(
"<label class='%s_css' for='%s_fld'>%s</label>\n",
id.c_str(),
id.c_str(), title.c_str());
510 appendBodyf(
"<input type='text' id='%s_fld' onkeypress='limitKeypress(event,this.value,%d)' onchange='updateValue_%s(this.value)'/>\n",
511 id.c_str(),
int(log(maxValue) * M_LOG10E + 1),
id.c_str());
512 appendScriptf(
"var %s = document.getElementById('%s_fld');\n",
id.c_str(),
id.c_str());
513 appendScriptf(
"setInputFilter(%s, function(value) {",
id.c_str());
516 appendScriptf(
"%s.value = %s_val_;\n",
id.c_str(),
id.c_str());
517 appendScriptf(
"function updateValue_%s(pos) {if(pos<%d) {",
id.c_str(), minValue);
518 appendScriptf(
" alert('Minimum allowed value is: '+%d);", minValue);
521 appendScriptf(
" alert('Maximum allowed value is: '+%d);", maxValue);
534 WSelect(String title, String
id, String options[],
unsigned numOptions,
int (*
getValue)(),
void (*
setValue)(
int),
bool (*enabled)() =
nullptr) :
539 appendCSSf(
".%s_css { width: 300px; }\n",
id.c_str());
540 appendBodyf(
"<p><span id='%s_val'></span></p>\n",
id.c_str());
541 appendBodyf(
"<label class='%s_css' for='%s_fld'>%s</label>\n",
id.c_str(),
id.c_str(), title.c_str());
542 appendBodyf(
"<select id='%s_fld' onchange='updateValue_%s(this.value)'>\n",
id.c_str(),
id.c_str());
543 for (
unsigned i = 0; i < numOptions; i++)
545 appendBodyf(
"<option value='%d'>%s</option>\n", i, options[i].c_str());
548 appendScriptf(
"var %s = document.getElementById('%s_fld');\n",
id.c_str(),
id.c_str());
549 appendScriptf(
"%s.value = %s_val_;\n",
id.c_str(),
id.c_str());
550 appendScriptf(
"function updateValue_%s(pos) {fetchNoload('%s', pos); {Connection: close};}\n",
id.c_str(),
id.c_str());
553 WSelect(String title, String
id, String options[], String values[],
unsigned numOptions,
int (*
getValue)(),
void (*
setValue)(
int),
bool (*enabled)() =
nullptr) :
558 appendCSSf(
".%s_css { width: 300px; }\n",
id.c_str());
559 appendBodyf(
"<p><span id='%s_val'></span></p>\n",
id.c_str());
560 appendBodyf(
"<label class='%s_css' for='%s_fld'>%s</label>\n",
id.c_str(),
id.c_str(), title.c_str());
561 appendBodyf(
"<select id='%s_fld' onchange='updateValue_%s(this.value)'>\n",
id.c_str(),
id.c_str());
562 for (
unsigned i = 0; i < numOptions; i++)
567 appendScriptf(
"var %s = document.getElementById('%s_fld');\n",
id.c_str(),
id.c_str());
568 appendScriptf(
"%s.value = %s_val_;\n",
id.c_str(),
id.c_str());
569 appendScriptf(
"function updateValue_%s(pos) {fetchNoload('%s', pos); {Connection: close};}\n",
id.c_str(),
id.c_str());
580 appendCSSf(
".%s_css { width: 300px; }",
id.c_str());
582 appendBodyf(
"<p><span id='%s_val'></span></p>\n",
id.c_str());
583 appendBodyf(
"<label class='%s_css' for='%s_fld'>%s</label>\n",
id.c_str(),
id.c_str(), title.c_str());
584 appendBodyf(
"<input type='password' id='%s_fld' onchange='updateValue_%s(this.value)'/>\n",
id.c_str(),
id.c_str());
585 appendScriptf(
"var %s = document.getElementById('%s_fld');\n",
id.c_str(),
id.c_str());
586 appendScriptf(
"%s.value = %s_val_;\n",
id.c_str(),
id.c_str());
587 appendScriptf(
"function updateValue_%s(pos) {fetchNoload('%s', pos); {Connection: close};}\n",
id.c_str(),
id.c_str());
598 appendCSSf(
".%s_css { width: 300px; }",
id.c_str());
600 appendBodyf(
"<p><span id='%s_val'></span></p>\n",
id.c_str());
601 appendBodyf(
"<label class='%s_css' for='%s_file'>%s</label>\n",
id.c_str(),
id.c_str(), title.c_str());
602 appendBodyf(
"<input type='file' id='%s_file' onchange='updateValue_%s(this)'/>\n",
id.c_str(),
id.c_str());
603 appendScriptf(
"var %s = document.getElementById('%s_file');\n",
id.c_str(),
id.c_str());
604 appendScriptf(
"function updateValue_%s(pos) {);}\n",
id.c_str());
614 appendCSSf(
".%s_css { width: 300px; }",
id.c_str());
616 appendBodyf(
"<p><span id='%s_val'></span></p>\n",
id.c_str());
617 appendBodyf(
"<label class='%s_css' for='%s_file'>%s</label>\n",
id.c_str(),
id.c_str(), title.c_str());
618 appendBodyf(
"<input type='file' id='%s_file' accept='.bin' onchange='updateValue_%s(this)'/>\n",
id.c_str(),
id.c_str());
619 appendScriptf(
"var %s = document.getElementById('%s_file');\n",
id.c_str(),
id.c_str());
620 appendScriptf(
"function updateValue_%s(pos) { document.getElementById('%s_upload').disabled = false; }\n",
id.c_str(),
id.c_str());
630 appendCSS(
"."+String(
id)+
"_css { width: 300px; }");
631 appendCSS(
"#"+String(
id)+
"_prg,#"+String(
id)+
"_prgbar{background-color:#f1f1f1;border-radius:10px}");
632 appendCSS(
"#"+String(
id)+
"_bar{background-color:#3498db;width:0%;height:10px}");
634 appendBody(
"<p><span id='"+String(
id)+
"_val'></span></p>\n");
635 appendBody(
"<input type='button' id='"+String(
id)+
"_upload' value='"+title+
"' onclick='upload_"+String(
id)+
"()'/>\n");
637 appendBody(
"<div id='"+String(
id)+
"_prg'></div>\n");
638 appendBody(
"<br><div id='"+String(
id)+
"_prgbar'><div id='"+String(
id)+
"_bar'></div></div><br></form>\n");
639 appendScript(
"var "+String(
id)+
"_upload = document.getElementById('"+String(
id)+
"_upload');\n");
640 appendScript(
"var "+String(
id)+
"_prg = document.getElementById('"+String(
id)+
"_prg');\n");
641 appendScript(
"var "+String(
id)+
"_prgbar = document.getElementById('"+String(
id)+
"_prgbar');\n");
642 appendScript(
"var "+String(
id)+
"_bar = document.getElementById('"+String(
id)+
"_bar');\n");
649 appendScript(
" "+String(
id)+
"_prg.innerHTML = 'progress: ' + Math.round(per*100) + '%';\n");
650 appendScript(
" "+String(
id)+
"_bar.style.width = Math.round(per*100) + '%';\n");
654 appendScript(
" "+String(
id)+
"_prg.innerHTML = 'Upload failed!';\n");
655 appendScript(
" "+String(
id)+
"_bar.style.width = '0%';\n");
658 appendScript(
" "+String(
id)+
"_prg.innerHTML = 'Upload cancelled';\n");
659 appendScript(
" "+String(
id)+
"_bar.style.width = '0%';\n");
662 appendScript(
" "+String(
id)+
"_prg.innerHTML = 'Upload complete. Please wait .';\n");
663 appendScript(
" "+String(
id)+
"_bar.style.width = '0%';\n");
666 appendScript(
" if (xhr.counter++ >= 8) window.location.href='/';\n");
667 appendScript(
" "+String(
id)+
"_prg.innerHTML = "+String(
id)+
"_prg.innerHTML + '.';\n");
670 appendScript(
"xhr.open('POST', 'upload/firmware', true);\n");
687 appendCSSf(
".%s_vertical_menu { width: 300px; margin-left: auto; margin-right: auto; }\n",
id.c_str());
688 appendCSSf(
".%s_vertical_menu a { background-color: #eee; color: black; display: block; padding: 12px; text-decoration: none; }\n",
id.c_str());
689 appendCSSf(
".%s_vertical_menu a:hover { background-color: #ccc; }\n",
id.c_str());
690 appendCSSf(
".%s_vertical_menu a:active { background-color: #4CAF50; color: white; }\n",
id.c_str());
691 appendBodyf(
"<div class='%s_vertical_menu'>\n",
id.c_str());
692 for (
unsigned i = 0; i < menuCount; i++)
695 appendBodyf(
"<a href='%s' class='active'>%s</a>\n", menuData[i].href, menuData[i].title);
697 appendBodyf(
"<a href='%s'>%s</a>\n", menuData[i].href, menuData[i].title);
726 appendBodyf(
"<a href=\"%s\">%s</a>", link.c_str(), text.c_str());
735 appendBody(
"<p><img src='data:image/png;base64, ");
823 appendBodyf(
"<label class='%s_css'>%s</label>\n",
id.c_str(), text.c_str());
835 appendBodyf(
"<input type='text' id='%s_fld' onchange='updateValue_%s(this.value)'/>\n",
id.c_str(),
id.c_str());
836 appendScriptf(
"var %s = document.getElementById('%s_fld');\n",
id.c_str(),
id.c_str());
837 appendScriptf(
"%s.value = %s_val_;\n",
id.c_str(),
id.c_str());
838 appendScriptf(
"function updateValue_%s(pos) {fetchNoload('%s', pos); {Connection: close};}\n",
id.c_str(),
id.c_str());
842 #ifndef HTTP_UPLOAD_BUFLEN
843 #define HTTP_UPLOAD_BUFLEN 1436
871 WPage(String url,
const WElement contents[],
unsigned numElements, String title =
"", String lang =
"en") :
880 WPage(String url, fs::FS* fs, String path,
const WElement contents[],
unsigned numElements) :
890 WPage(String url, fs::FS* fs, String mimeType) :
912 bool needsReload =
true;
913 String prefix =
"GET "+
fURL+
"?";
914 if (header.startsWith(prefix) ||
fAPIProc !=
nullptr)
921 int end = header.indexOf(
' ', prefix.length());
922 fAPIProc(out, header.substring(prefix.length(), end));
926 int pos1 = header.indexOf(
"&?");
930 pos1 = header.indexOf(
'?');
932 int pos2 = header.indexOf(
'=',pos1);
933 int pos3 = header.indexOf(
'&',pos2);
934 if (pos1 != -1 && pos2 != -1 && pos3 != -1)
936 String var = header.substring(pos1+skiplen, pos2);
937 String val = header.substring(pos2+1, pos3);
954 bool compressed =
false;
958 ::printf(
"FILE: %s (compressed=%d)\n",
fTitleOrPath.c_str(), compressed);
959 if (compressed && header.indexOf(
"Accept-Encoding: gzip") == -1)
961 ::printf(
"Client needs to support compression\n");
964 out.println(
"HTTP/1.0 200 OK");
966 out.println(
"Connection: close");
968 out.println(
"Compression required");
972 out.println(
"HTTP/1.0 404 Not Found");
974 out.println(
"Content-type:text/html");
975 out.println(
"Connection: close");
981 size_t fileSize = file.size();
982 out.println(
"HTTP/1.0 200 OK");
984 out.print(
"Content-Length:"); out.println(fileSize);
985 out.println(
"Cache-Control: private, max-age=2592000");
987 out.println(
"Content-Encoding: gzip");
988 out.println(
"Connection: close");
990 char* buffer = (
char*)malloc(1024);
991 while (file.available())
993 size_t bytesRead = file.readBytes(buffer, 1024);
994 out.write(buffer, bytesRead);
1002 out.println(
"HTTP/1.0 404 Not Found");
1004 out.println(
"Content-type:text/html");
1005 out.println(
"Connection: close");
1011 out.println(
"HTTP/1.0 200 OK");
1012 out.println(
"Content-type:text/html");
1013 out.println(
"Connection: close");
1015 out.print(R
"RAW(<!DOCTYPE html><html lang=")RAW");
1018 R"RAW("><head><meta charset="UTF-8"><meta name="viewport", content="width=device-width, initial-scale=1">
1019 <link rel="icon" href="data:,"><title>)RAW");
1023 <style>body { text-align: center; font-family: "Trebuchet MS", Arial; margin-left:auto; margin-right:auto;}
1037 function fetchNoload(key,val) {
1038 var baseurl = window.location.protocol+'//'+window.location.host+location.pathname;
1039 fetch(baseurl+'?'+key+'='+val+'&');
1041 function fetchLoad(key,val) {
1042 var baseurl = window.location.protocol+'//'+window.location.host+location.pathname;
1043 window.location.href=baseurl+'?'+key+'='+val+'&';
1045 function limitKeypress(event, value, maxLength) {
1046 if (value != undefined && value.toString().length >= maxLength) {
1047 event.preventDefault();
1050 function setInputFilter(textbox, inputFilter) {
1051 ["input", "keydown", "keyup", "mousedown", "mouseup", "select", "contextmenu", "drop"].forEach(function(event) {
1052 textbox.addEventListener(event, function() {
1053 if (inputFilter(this.value)) {
1054 this.oldValue = this.value;
1055 this.oldSelectionStart = this.selectionStart;
1056 this.oldSelectionEnd = this.selectionEnd;
1057 } else if (this.hasOwnProperty("oldValue")) {
1058 this.value = this.oldValue;
1059 this.setSelectionRange(this.oldSelectionStart, this.oldSelectionEnd);
1073 {Connection: close};
1081 out.println(
"HTTP/1.0 200 OK");
1082 out.println(
"Content-type:text/html");
1083 out.println(
"Connection: close");
1104 fs::File file =
fFS->open(fileName +
".gz", FILE_READ,
false);
1105 if (file && !file.isDirectory())
1111 return fFS->open(fileName);
1123 void (*
fAPIProc)(Print& out, String queryString) =
nullptr;
1129 WAPI(String url,
void (*apiProc)(Print& out, String queryString)) :
1130 WPage(url, nullptr, 0)
1139 WUpload(String url,
void (*completeProc)(Client& client),
void (*uploaderProc)(
WUploader &uploader)) :
1140 WPage(url, nullptr, 0)
1170 template<
unsigned maxClients = 10,
unsigned numPages = 0>
1193 fConnectedCallback = callback;
1198 fActivityCallback = callback;
1219 for (
unsigned i = 0; i < maxClients; i++)
1233 if (!fEnabled || !fStarted)
1239 for (i = 0; i < maxClients; i++)
1244 if (fActivityCallback !=
nullptr)
1245 fActivityCallback();
1255 fRequest.reserve(4096);
1256 fHeader.reserve(4096);
1257 if (fConnectedCallback)
1258 fConnectedCallback();
1262 if (i >= maxClients)
1265 Serial.println(
"NO CLIENTS AVAILABLE");
1270 for (
unsigned i = 0; i < maxClients; i++)
1275 if (fUploader !=
nullptr)
1290 fUploaderPage =
nullptr;
1291 fUploader =
nullptr;
1299 if (
fClients[i].available() && fActivityCallback !=
nullptr)
1300 fActivityCallback();
1305 if (fUploader !=
nullptr)
1324 if (fRequest.length() == 0)
1326 if (fHeader.startsWith(
"POST /"))
1328 fUploaderPage = getPost();
1329 if (fUploaderPage ==
nullptr)
1331 fClients[i].println(
"HTTP/1.0 404 Not Found");
1332 fClients[i].println(
"Content-type:text/html");
1333 fClients[i].println(
"Connection: close");
1339 int offs = fHeader.indexOf(
"\nContent-Length: ");
1340 unsigned contentLength = 0;
1343 int pos1 = fHeader.indexOf(
'\n', offs+1);
1344 int pos2 = fHeader.lastIndexOf(
' ', pos1);
1345 if (pos1 != 0 && pos2 != 0)
1347 contentLength = fHeader.substring(pos1+1, pos2).toInt();
1352 fUploader->
filename =
"filename.txt";
1353 fUploader->
name =
"name.txt";
1354 fUploader->
type =
"type.txt";
1355 fUploader->
fileSize = contentLength;
1359 String prefix =
"POST "+fUploaderPage->
getURL()+
"?";
1360 if (fHeader.startsWith(prefix))
1362 int end = fHeader.indexOf(
' ', prefix.length());
1363 fUploader->
queryString = fHeader.substring(prefix.length(), end);
1372 else if (fHeader.startsWith(
"GET /robots.txt"))
1378 out.println(
"HTTP/1.0 200 OK");
1379 out.println(
"Content-type:text/html");
1380 out.println(
"Connection: close");
1391 else if (fHeader.startsWith(
"GET /"))
1397 handleGetRequest(out);
1431 bool fEnabled =
true;
1432 bool fStarted =
false;
1436 const WPage* fPages;
1437 const WPage* fUploaderPage =
nullptr;
1439 void (*fConnectedCallback)() =
nullptr;
1440 void (*fWiFiActiveCallback)(
bool ap) =
nullptr;
1441 void (*fActivityCallback)() =
nullptr;
1443 const WPage* getPage()
const
1446 if (fHeader.startsWith(
"GET /"))
1448 int pos1 = fHeader.indexOf(
'\n');
1449 int pos2 = fHeader.lastIndexOf(
' ', pos1);
1450 if (pos1 != -1 && pos2 != -1)
1452 url = fHeader.substring(4, pos2);
1453 if ((pos1 = url.indexOf(
'?')) != -1)
1455 url = url.substring(0, pos1);
1459 for (
unsigned i = 0; i < numPages; i++)
1461 if (fPages[i].getURL() == url && fPages[i].isGet())
1469 const WPage* getPost()
const
1472 if (fHeader.startsWith(
"POST /"))
1474 int pos1 = fHeader.indexOf(
'\n');
1475 int pos2 = fHeader.lastIndexOf(
' ', pos1);
1476 if (pos1 != -1 && pos2 != -1)
1478 url = fHeader.substring(5, pos2);
1479 if ((pos1 = url.indexOf(
'?')) != -1)
1481 url = url.substring(0, pos1);
1485 for (
unsigned i = 0; i < numPages; i++)
1487 if (fPages[i].getURL() == url && !fPages[i].isGet())
1495 void handleGetRequest(Print &out)
1497 const WPage* page = getPage();
1498 if (page !=
nullptr)
1504 out.println(
"HTTP/1.0 404 NOT FOUND");
1505 out.println(
"Connection: close");
Definition: WifiWebServer.h:741
bool enabled()
Definition: WifiWebServer.h:1201
String getID() const
Definition: WifiWebServer.h:147
void setActivity(void(*callback)())
Definition: WifiWebServer.h:1196
WPage(String url, const WElement contents[], unsigned numElements, String title="", String lang="en")
Definition: WifiWebServer.h:871
bool isGet() const
Definition: WifiWebServer.h:905
Definition: WifiWebServer.h:499
Definition: WifiWebServer.h:624
WCheckbox(String title, String id, bool(*getValue)(), void(*setValue)(bool), bool(*enabled)()=nullptr)
Definition: WifiWebServer.h:350
@ UPLOAD_FILE_ABORTED
Definition: WifiWebServer.h:851
WInteger(int(*getValue)(), void(*setValue)(int))
Definition: WifiWebServer.h:67
Definition: WifiWebServer.h:269
WTextFieldInteger(String title, String id, String(*getValue)(), void(*setValue)(String), bool(*enabled)()=nullptr)
Definition: WifiWebServer.h:481
WValue * fValue
Definition: WifiWebServer.h:256
bool fReload
Definition: WifiWebServer.h:258
Definition: WifiWebServer.h:703
void appendCSS(String str)
Definition: WifiWebServer.h:148
Definition: WifiWebServer.h:1136
size_t currentSize
Definition: WifiWebServer.h:864
Definition: WifiAccess.h:25
void appendScriptf(const char *fmt,...)
Definition: WifiWebServer.h:178
void emitBody(Print &out) const
Definition: WifiWebServer.h:201
#define DEBUG_PRINT(s)
Definition: ReelTwo.h:189
@ UPLOAD_FILE_WRITE
Definition: WifiWebServer.h:849
Definition: WifiWebServer.h:298
virtual void emitBody(Print &out) const =0
WLabel(String text, String id, bool(*enabled)()=nullptr)
Definition: WifiWebServer.h:450
WTableColEnd()
Definition: WifiWebServer.h:800
void appendCSSf(const char *fmt,...)
Definition: WifiWebServer.h:152
virtual void set(String val) override
Definition: WifiWebServer.h:53
Definition: WifiWebServer.h:13
size_t fileSize
Definition: WifiWebServer.h:862
void emitCSS(Print &out) const
Definition: WifiWebServer.h:191
void(* fSetValue)(bool)
Definition: WifiWebServer.h:61
void(* fSetValue)(int)
Definition: WifiWebServer.h:88
WSelect(String title, String id, String options[], unsigned numOptions, int(*getValue)(), void(*setValue)(int), bool(*enabled)()=nullptr)
Definition: WifiWebServer.h:534
Definition: WifiAccess.h:166
String(* fGetValue)()
Definition: WifiWebServer.h:119
virtual bool getQuoteValue() override
Definition: WifiWebServer.h:100
void perform()
Definition: WifiWebServer.h:29
WifiWebServer(const WPage pages[], WifiAccess &wifiAccess, uint16_t port=80)
Constructor.
Definition: WifiWebServer.h:1182
WFirmwareFile(String title, String id)
Definition: WifiWebServer.h:611
void callComplete(Client &client) const
Definition: WifiWebServer.h:1048
Definition: WifiWebServer.h:91
WTextFieldIntegerRange(String title, String id, int minValue, int maxValue, String(*getValue)(), void(*setValue)(String), bool(*enabled)()=nullptr)
Definition: WifiWebServer.h:502
void setValue(String val) const
Definition: WifiWebServer.h:241
Definition: WifiWebServer.h:316
WPassword(String title, String id, String(*getValue)(), void(*setValue)(String))
Definition: WifiWebServer.h:576
WTextField(String title, String id, String(*getValue)(), void(*setValue)(String), bool(*enabled)()=nullptr)
Definition: WifiWebServer.h:463
fs::FS * fFS
Definition: WifiWebServer.h:1077
Definition: WifiWebServer.h:347
String fTitleOrPath
Definition: WifiWebServer.h:1075
int(* fGetValue)()
Definition: WifiWebServer.h:87
bool(* fGetValue)()
Definition: WifiWebServer.h:60
void(* fAPIProc)(Print &out, String queryString)
Definition: WifiWebServer.h:1083
#define DEBUG_PRINTLN(s)
Definition: ReelTwo.h:188
virtual void wifiConnected(WifiAccess &access) override
Definition: WifiWebServer.h:1206
bool(* fEnabled)()
Definition: WifiWebServer.h:260
WFirmwareUpload(String title, String id)
Definition: WifiWebServer.h:627
@ UPLOAD_FILE_START
Definition: WifiWebServer.h:848
Definition: WifiWebServer.h:64
virtual void set(String val) override
Definition: WifiWebServer.h:112
void handleGetRequest(Print &out, String &header) const
Definition: WifiWebServer.h:910
WTableTextField(String id, String(*getValue)(), void(*setValue)(String), bool(*enabled)()=nullptr)
Definition: WifiWebServer.h:830
Definition: WifiWebServer.h:447
WTableRow()
Definition: WifiWebServer.h:773
void flush()
Definition: PSRamBufferedPrintStream.h:17
Definition: WifiWebServer.h:325
void(* fUploaderProc)(WUploader &uploader)
Definition: WifiWebServer.h:1082
@ UPLOAD_FILE_END
Definition: WifiWebServer.h:850
Definition: WifiWebServer.h:307
Definition: WifiWebServer.h:478
Definition: WifiWebServer.h:368
Definition: WifiWebServer.h:868
W1(String title)
Definition: WifiWebServer.h:706
virtual bool getQuoteValue()
Definition: WifiWebServer.h:16
WUpload(String url, void(*completeProc)(Client &client), void(*uploaderProc)(WUploader &uploader))
Definition: WifiWebServer.h:1139
WHRef(String link, String text)
Definition: WifiWebServer.h:724
WDynamicElementInt(String id, const WDynamic &dynamicRef, int(*getValue)(), void(*setValue)(int))
Definition: WifiWebServer.h:289
WVerticalAlign()
Definition: WifiWebServer.h:301
WTableLabel(String text, String id, bool(*enabled)()=nullptr)
Definition: WifiWebServer.h:819
String fURL
Definition: WifiWebServer.h:1074
bool needsReload() const
Definition: WifiWebServer.h:146
virtual String get() override
Definition: WifiWebServer.h:105
WiFiClient fClients[maxClients]
Definition: WifiWebServer.h:1174
WSVG(String data)
Definition: WifiWebServer.h:744
const WDynamic * fDynamic
Definition: WifiWebServer.h:259
void appendBodyf(const char *fmt,...)
Definition: WifiWebServer.h:165
WTableCol(String styleClass)
Definition: WifiWebServer.h:788
WSlider(String title, String id, int min, int max, int(*getValue)(), void(*setValue)(int))
Definition: WifiWebServer.h:328
WElement(WAction *action)
Definition: WifiWebServer.h:141
#define HTTP_UPLOAD_BUFLEN
Definition: WifiWebServer.h:843
uint8_t buf[HTTP_UPLOAD_BUFLEN+1]
Definition: WifiWebServer.h:865
bool & verticalAlignment()
Definition: WifiWebServer.h:262
WString(String(*getValue)(), void(*setValue)(String))
Definition: WifiWebServer.h:94
WUploadStatus
Definition: WifiWebServer.h:846
Definition: WifiWebServer.h:752
WTableCol()
Definition: WifiWebServer.h:782
Definition: WifiWebServer.h:286
WTableRowEnd()
Definition: WifiWebServer.h:810
Definition: PSRamBufferedPrintStream.h:6
void handle()
Dispatch any received i2c event to CommandEvent.
Definition: WifiWebServer.h:1231
virtual void set(String val) override
Definition: WifiWebServer.h:80
void(* fSetValue)(String)
Definition: WifiWebServer.h:120
WHorizontalAlign()
Definition: WifiWebServer.h:310
WPage(String url, fs::FS *fs, String mimeType)
Definition: WifiWebServer.h:890
virtual void emitCSS(Print &out) const
Definition: WifiWebServer.h:126
virtual void set(String val)=0
Definition: WifiWebServer.h:770
void(* fCompleteProc)(Client &client)
Definition: WifiWebServer.h:1081
size_t receivedSize
Definition: WifiWebServer.h:863
const String & getURL() const
Definition: WifiWebServer.h:900
WImage(String alt, String data)
Definition: WifiWebServer.h:733
Definition: WifiWebServer.h:21
WAction(void(*action)())
Definition: WifiWebServer.h:24
Definition: WifiWebServer.h:854
Definition: WifiWebServer.h:1126
Definition: WifiWebServer.h:779
Definition: WifiWebServer.h:608
String filename
Definition: WifiWebServer.h:858
String fBody
Definition: WifiWebServer.h:254
WDynamicElement(const WDynamic &dynamicRef)
Definition: WifiWebServer.h:272
void addNotify(WifiAccess::Notify *client)
Definition: WifiAccess.h:173
WHTML(String data)
Definition: WifiWebServer.h:755
WBoolean(bool(*getValue)(), void(*setValue)(bool))
Definition: WifiWebServer.h:42
void appendScript(String str)
Definition: WifiWebServer.h:150
WJavaScript(String data)
Definition: WifiWebServer.h:764
uint8_t fFlags
Definition: WifiWebServer.h:1078
String fCSS
Definition: WifiWebServer.h:253
const WElement * fContents
Definition: WifiWebServer.h:1080
Definition: WifiWebServer.h:133
virtual void wifiDisconnected(WifiAccess &access) override
Definition: WifiWebServer.h:1216
WUploadStatus status
Definition: WifiWebServer.h:857
WStyle(String style)
Definition: WifiWebServer.h:319
Definition: WifiWebServer.h:730
Definition: WifiWebServer.h:573
void emitValue(Print &out) const
Definition: WifiWebServer.h:211
Definition: WifiWebServer.h:797
String fID
Definition: WifiWebServer.h:252
String queryString
Definition: WifiWebServer.h:861
Definition: MallocString.h:8
void appendBody(String str)
Definition: WifiWebServer.h:149
WPage(String url, fs::FS *fs, String path, const WElement contents[], unsigned numElements)
Definition: WifiWebServer.h:880
void(* fAction)()
Definition: WifiWebServer.h:36
virtual String get() override
Definition: WifiWebServer.h:48
void callUploader(WUploader &uploader) const
Definition: WifiWebServer.h:1054
WAction * fAction
Definition: WifiWebServer.h:257
WHR()
Definition: WifiWebServer.h:715
virtual void emitScript(Print &out) const
Definition: WifiWebServer.h:130
String name
Definition: WifiWebServer.h:859
Definition: WifiWebServer.h:816
Definition: WifiWebServer.h:721
String getValue() const
Definition: WifiWebServer.h:234
unsigned fNumElements
Definition: WifiWebServer.h:1079
WDynamicElement(String id, const WDynamic &dynamicRef, WValue *value=nullptr)
Definition: WifiWebServer.h:278
Definition: WifiWebServer.h:712
WElement(WValue *value=nullptr)
Definition: WifiWebServer.h:136
WCheckboxReload(String title, String id, bool(*getValue)(), void(*setValue)(bool), bool(*enabled)()=nullptr)
Definition: WifiWebServer.h:371
Definition: WifiWebServer.h:123
Definition: WifiWebServer.h:460
Definition: WifiWebServer.h:531
Definition: WifiWebServer.h:807
void emitScript(Print &out) const
Definition: WifiWebServer.h:224
WAPI(String url, void(*apiProc)(Print &out, String queryString))
Definition: WifiWebServer.h:1129
fs::File openFileOrCompressed(String fileName, bool &compressed) const
Definition: WifiWebServer.h:1061
String fLanguageOrMimeType
Definition: WifiWebServer.h:1076
Definition: WifiWebServer.h:827
String type
Definition: WifiWebServer.h:860
void setConnect(void(*callback)())
Definition: WifiWebServer.h:1191
WSelect(String title, String id, String options[], String values[], unsigned numOptions, int(*getValue)(), void(*setValue)(int), bool(*enabled)()=nullptr)
Definition: WifiWebServer.h:553
virtual String get() override
Definition: WifiWebServer.h:73
Simple WiFi web server.
Definition: WifiWebServer.h:1171
String fScript
Definition: WifiWebServer.h:255
Definition: WifiWebServer.h:761
Definition: WifiWebServer.h:39