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.

Revisions of RdWebServer.cpp

Revision Date Message Actions
15:0865fa4b046a 2015-05-05 Pared back for work on stability - ok on LPC1768 File  Diff  Annotate
14:4b83670854f0 2015-05-05 Improving robustness File  Diff  Annotate
13:4f9c09d3da13 2015-05-04 Debugging File  Diff  Annotate
12:c14ffd4ec125 2015-05-03 Added debugging macros File  Diff  Annotate
11:cec51b430b20 2015-05-03 Added debugging macros File  Diff  Annotate
10:b4b9d4d5e5be 2015-02-22 Fixed problem with folder listings File  Diff  Annotate
9:35668248199b 2015-02-22 Changed back to non-blocking - seems more stable File  Diff  Annotate
8:de915bd70ec1 2015-02-20 Reinstated some code I'd missed out when changing to run in a thread. The code handles timeouts on the HTTP connection. File  Diff  Annotate
7:fe7c33f7fbb8 2015-02-07 Working with gas count - not tested on actual meter reed switch File  Diff  Annotate
6:46285c519af2 2015-02-06 Working with threaded server and SD card stack extended to stop crashes File  Diff  Annotate
5:e6286b529d6b 2015-02-03 Minor tweak File  Diff  Annotate
4:6afb3bbf20a4 2015-02-02 Updated to use SD or USB File  Diff  Annotate
3:594136d34a32 2013-10-04 Tidied up a little - no functional changes File  Diff  Annotate
2:9d8793c23b46 2013-10-04 Initial Revision Working File  Diff  Annotate
1:75bb184de749 2013-09-19 Added code to support commands - still a lot of test code in place though File  Diff  Annotate
0:b5b4d07f7827 2013-09-18 Initial File  Diff  Annotate