Reference Home

Send Response

Description

Callback function must prepare and send response to a request.

Usually the response is a HTML page stored in PROGMEM area of Arduino.

To send this page, just use sendResponse function.

Second version allows you to assemble HTML page in pieces (with reusable blocks).

Syntax

HTTP.sendResponse(int socket,prog_char *page)

HTTP.sendResponse(int socket,prog_char* amodule[],uint8_t nm)

Parameters

socket : link socket

a prog_char pointer to string in PROGMEM

amodule : array of prog_char blocks

nm : number of blocks (array dimension)

Returns

none

Send Short Response

Description

In case of Forms or Ajax background request (typically POST method), the responses are usually data. Therefore a more compact and efficient (no chunk format) is preferable.

Syntax

HTTP.sendShortResponse(int socket,char *data)

Parameters

socket : link socket

char pointer to string containing data (for example in JSON format)

Returns

none

Example:

#include <HTTPlib.h> //library include

 

HTTP WIFI; //instance of HTTP (inherits any stuff of MWiFi)

 

prog_char pageindex[] PROGMEM=
"<html><head>"
"<title>Index</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>Welcome to Arduino Server</h1>"
"<p>You can :</p>"
"<h2><ul>"
"<li><a href='/Analog'>read analogic pins</a></li>"
"<li><a href='/RDigital'>read digital pins</a></li>"
"<li><a href='/WDigital'>set digital pins on/off</a></li>"
"<li><a href='/Pwm'>power up/down PWM pins</a></li>"
"</ul></h2>"
"</body></html>";

 

:

:

void pindex(char *query) // call back function

{

WIFI.sendResponse(csocket,pageindex);// send response: pageindex

}

Reference Home