- Sat May 16, 2015 9:34 am
#17566
To server different webpages you need multiple calls to the server.on() event. It'll look like this:
void setup(void)
{
server.on("/", handle_root);
server.on("/page1", handle_page1);
server.on("/page2", handle_page2);
}
Then each of those you make a function like this:
function handle_root(){
}
function handle_page1(){
}
function handle_page2(){
}
Inside those function you have to call the server.send() function. like this: server.send(200, "text/plain", "hello world"); You put those in each of the functions, that last string is the html for the page:
function handle_root(){
server.send(200, "text/plain", "I am the <b>root</b> page");
}
function handle_page1(){
server.send(200, "text/plain", "I am page <i>one</i>");
}
function handle_page2(){
server.send(200, "text/plain", "I am page <span style='color:red'>two</span>");
}
Finally... in the loop, you have to call the server.handleClient(); method. like this:
void loop(void){
server.handleClient();
}
Look at the helloServer example. It has all this in it.