forked from JamesNewton/esp8266WebSerial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.h
55 lines (45 loc) · 1.89 KB
/
example.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#ifndef PAGE_EXAMPLE_H
#define PAGE_EXAMPLE_H
//
// The EXAMPLE PAGE
//
const char PAGE_example[] PROGMEM = R"=====(
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<h1>My Example goes here</h1>
<div id="mydynamicdata">Here comes the Dynamic Data in </div> <!-- added a DIV, where the dynamic data goes to -->
<script>
window.onload = function ()
{
load("style.css","css", function()
{
load("microajax.js","js", function()
{
setValues("/admin/filldynamicdata"); //-- this function calls the function on the ESP
});
});
}
function load(e,t,n){if("js"==t){var a=document.createElement("script");a.src=e,a.type="text/javascript",a.async=!1,a.onload=function(){n()},document.getElementsByTagName("head")[0].appendChild(a)}else if("css"==t){var a=document.createElement("link");a.href=e,a.rel="stylesheet",a.type="text/css",a.async=!1,a.onload=function(){n()},document.getElementsByTagName("head")[0].appendChild(a)}}
</script>
)=====";
#endif
void filldynamicdata(AsyncWebServerRequest *request)
{
String values ="";
values += "mydynamicdata|" + (String) + "This is filled by AJAX. Millis since start: " + (String) millis() + "|div\n"; // Build a string, like this: ID|VALUE|TYPE
request->send ( 200, "text/plain", values);
}
void processExample(AsyncWebServerRequest *request)
{
if (request->args() > 0 ) // Are there any POST/GET Fields ?
{
for ( uint8_t i = 0; i < request->args(); i++ ) { // Iterate through the fields
if (request->argName(i) == "firstname")
{
// Your processing for the transmitted form-variable
String fName = request->arg(i);
}
}
}
request->send ( 200, "text/html", PAGE_example );
}