Callback function must prepare and send response to a request.
Usually the response is a HTML page stored in PROGMEM area of Arduino.
But if response has to send current values it must insert these values into HTML page before to send page.
This task is accomplished by sendDynResponse function.
For this purpose you have to put a tag @ inside the HTML page where you want insert values .
After that, you have to provide values as string to sendDynResponse.
More precisely, you provide an array of string to sendDynResponse.
Each tag @ found inside HTML page will be replaced in sequence by value in array.
If array too short, surplus @ tags are displayed.
(Note: if you want display @ char inside html page use coded form @)
HTTP.sendDynResponset(int socket,prog_char *page,int dimval, char *val[])
socket : link socket
a prog_char pointer to string in PROGMEM
dimension of values array
array of char string containing values to replace tags
none
#include <HTTPlib.h> //library include
HTTP WIFI; //instance of HTTP (inherits any stuff of MWiFi)
prog_char pageanalog[] PROGMEM= //html page with tag @
"<title>Analogic Reading</title>"
"<style type='text/css'>"
"body,td,th {color: #FFF;}"
"body {background-color: #066;}"
"a:link {color: #FF0;}"
"a:visited {color: #F03;}"
"</style></head>"
"<body>"
"<h1>Analogic reading</h1>"
"<h2>"
"<table width='400' border='1'>"
"<tr><td width='232'>A0</td><td width='152'>@</td></tr>"
"<tr><td>A1</td><td>@</td></tr>"
"<tr><td>A2</td><td>@</td></tr>"
"<tr><td>A3</td><td>@</td></tr>"
"<tr><td>A4</td><td>@</td></tr>"
"<tr><td>A5</td><td>@</td></tr>"
"</table>"
"<p><a href='/index'>Home</a></p>"
"</h2>"
"</body></html>";
:
:
void pindex(char *query) // call back function
{
char *val[6]; //array of analogical read values (coded as string)
char val0[5];sprintf(val0,"%d",analogRead(0));val[0]=val0;
char val1[5];sprintf(val1,"%d",analogRead(1));val[1]=val1;
char val2[5];sprintf(val2,"%d",analogRead(2));val[2]=val2;
char val3[5];sprintf(val3,"%d",analogRead(3));val[3]=val3;
char val4[5];sprintf(val4,"%d",analogRead(4));val[4]=val4;
char val5[5];sprintf(val5,"%d",analogRead(5));val[5]=val5;
WIFI.sendDynResponse(csocket,pageanalog,6,val);// send response pageanalog
}