WebServer – the Webduino class/constructor


When creating an instance of the WebServer class you can specify a prefix for the local part of the URLs and a TCP port to listen on.

To be able to access the object both in the setup() and loop() functions of your sketch you should construct the object outside of either function.


WebServer webserver;
WebServer webserver(urlPrefix);
WebServer webserver(urlPrefix, port);


Specify a prefix to be used on the local part of all URLs. Array of char. Optional. Defaults to an empty string (i.e. no prefix). Should never end in a slash, i.e. if you want your URLs to be /lights/on and /lights/off you need to specify a prefix of /lights (see examples below)
Specify a TCP port to listen on. Int. Optional. Defaults to 80.


Constructors never return anything (not even void).


Instantiate with default values (no prefix, port 80):

#include "WebServer.h"
WebServer webserver;

Instatiate without a prefix, but listening on an alternative port:

#include "WebServer.h"
WebServer webserver("", 8000);

Instatiate with a prefix, so that your URLs will be /lights/on and /lights/off (listening on the default port 80):

#include "WebServer.h"
WebServer webserver("/lights");

void setup() {
  // Ethernet stuff here, e.g. set MAC and IP address
  webserver.addCommand("on", &onCmd);
  webserver.addCommand("off", &offCmd);

« back to Webduino


Your email address will not be published.