A simple web server mainly based on ideas from Jasper Schuurmans Netduino web server

Dependents:   RdBlindsServer SpideyWallWeb RdGasUseMonitor

A fast and reliable web server for MBED! http://robdobson.com/2015/08/a-reliable-mbed-webserver/

It has a very neat way to implement REST commands and can serve files from local storage (on LPC1768 for instance) and from SD cards. It also has a caching facility which is particularly useful for serving files from local storage.

The server can be run in the main() thread (and has a sub-2ms response time if this is done) or in a mbed-rtos thread which increases the response time to (a still respectable) 30ms or so.

The latest project that uses this is here - https://developer.mbed.org/users/Bobty/code/SpideyWallWeb/

int main (void)
{
    // Ethernet interface
    EthernetInterface::init();

    // Connect ethernet
    EthernetInterface::connect();

    // Init the web server
    pc.printf("Starting web server\r\n");
    char* baseWebFolder = "/sd/";  // should be /sd/ for SDcard files - not used for local file system
    RdWebServer webServer;
    
    // Add commands to handle the home page and favicon
    webServer.addCommand("", RdWebServerCmdDef::CMD_LOCALFILE, NULL, "index.htm", true);
    webServer.addCommand("favicon.ico", RdWebServerCmdDef::CMD_LOCALFILE, NULL, NULL, true);
    
    // Add the lightwall control commands
    webServer.addCommand("name", RdWebServerCmdDef::CMD_CALLBACK, &lightwallGetSystemName);
    webServer.addCommand("clear", RdWebServerCmdDef::CMD_CALLBACK, &lightwallClear);
    webServer.addCommand("rawfill", RdWebServerCmdDef::CMD_CALLBACK, &lightwallRawFill);
    webServer.addCommand("fill", RdWebServerCmdDef::CMD_CALLBACK, &lightwallFill);
    webServer.addCommand("showleds", RdWebServerCmdDef::CMD_CALLBACK, &lightwallShowLeds);
    
    // Start the server
    webServer.init(WEBPORT, &led4, baseWebFolder);
    webServer.run();

}

// Get system name - No arguments required
char* lightwallGetSystemName(int method, char*cmdStr, char* argStr, char* msgBuffer, int msgLen, 
                int contentLen, unsigned char* pPayload, int payloadLen, int splitPayloadPos)
{
    // Perform any required actions here ....

    // ...

    // Return the system name
    return systemName;
}

This server was originally based on a Netduino web server from Jasper Schuurmans but has been optimised for speed.

History

Fixed RTOS namespace issue default tip

2016-02-08, by Bobty [Mon, 08 Feb 2016 14:08:42 +0000] rev 29

Fixed RTOS namespace issue


Restructured to allow support for alternative IP stacks - e.g. CC3000; Also removed dependency on Mutex when SD card not used; And removed dependency on std::vector as it seems unstable

2016-02-08, by Bobty [Mon, 08 Feb 2016 13:47:29 +0000] rev 28

Restructured to allow support for alternative IP stacks - e.g. CC3000; Also removed dependency on Mutex when SD card not used; And removed dependency on std::vector as it seems unstable


Re-enabled folder view by default

2015-10-16, by Bobty [Fri, 16 Oct 2015 08:41:02 +0000] rev 27

Re-enabled folder view by default


Added the capability to support a Mutex to control access to the SD card and avoid clashes

2015-10-13, by Bobty [Tue, 13 Oct 2015 18:33:57 +0000] rev 26

Added the capability to support a Mutex to control access to the SD card and avoid clashes


Fix problem getting a file from SD card; Changed debug messages

2015-09-28, by Bobty [Mon, 28 Sep 2015 10:29:45 +0000] rev 25

Fix problem getting a file from SD card; Changed debug messages


Implemented handling of split-payloads in HTTP requests. This is done by sending a registered command each chunk of payload data as it arrives with an index indicating where the data fits in the original message.

2015-08-31, by Bobty [Mon, 31 Aug 2015 15:00:41 +0000] rev 24

Implemented handling of split-payloads in HTTP requests. This is done by sending a registered command each chunk of payload data as it arrives with an index indicating where the data fits in the original message.


Changed blocking options to default non-blocking; Detected OPTIONS HTTP method; Changed to always use keep-alive

2015-08-31, by Bobty [Mon, 31 Aug 2015 08:54:17 +0000] rev 23

Changed blocking options to default non-blocking; Detected OPTIONS HTTP method; Changed to always use keep-alive


Added Access Control Allow Origin to HTTP header in RdWebServer; Added setName/getName for hostname setting in EthernetInterface; Set hostname to systemName

2015-08-29, by Bobty [Sat, 29 Aug 2015 06:08:00 +0000] rev 22

Added Access Control Allow Origin to HTTP header in RdWebServer; Added setName/getName for hostname setting in EthernetInterface; Set hostname to systemName


Now defaults to support local file system

2015-08-20, by Bobty [Thu, 20 Aug 2015 07:40:20 +0000] rev 21

Now defaults to support local file system


Updated comments

2015-08-14, by Bobty [Fri, 14 Aug 2015 11:52:16 +0000] rev 20

Updated comments