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.h

Revision Date Message Actions
20:e6c7db867593 2015-08-14 Updated comments File  Diff  Annotate
19:f67ac231b570 2015-05-12 Allow larger buffer on K64F (more RAM), tidied up diagnostics and added code to get message payload File  Diff  Annotate
18:5de680c4cfcb 2015-05-11 Tidied up - still resets connection when it receives two requests in very short succession - not sure if this is a bug in lwip or something to do with socket limits or lack of threading File  Diff  Annotate
17:080f2bed8b36 2015-05-11 Improved settings File  Diff  Annotate
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
12:c14ffd4ec125 2015-05-03 Added debugging macros File  Diff  Annotate
11:cec51b430b20 2015-05-03 Added debugging macros 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
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