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

    // Connect ethernet

    // 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);


// 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
28:99036ff32459 2016-02-08 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 File  Diff  Annotate
27:0c2d6f598ae5 2015-10-16 Re-enabled folder view by default File  Diff  Annotate
26:3c4c10e989b1 2015-10-13 Added the capability to support a Mutex to control access to the SD card and avoid clashes File  Diff  Annotate
25:ffa1dddd3da4 2015-09-28 Fix problem getting a file from SD card; Changed debug messages File  Diff  Annotate
24:27800de38eab 2015-08-31 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. File  Diff  Annotate
23:0fc3d7b5e596 2015-08-31 Changed blocking options to default non-blocking; Detected OPTIONS HTTP method; Changed to always use keep-alive File  Diff  Annotate
22:598a21373539 2015-08-29 Added Access Control Allow Origin to HTTP header in RdWebServer; Added setName/getName for hostname setting in EthernetInterface; Set hostname to systemName File  Diff  Annotate
21:2dfb56648b93 2015-08-20 Now defaults to support local file system File  Diff  Annotate
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
16:0248bbfdb6c1 2015-05-05 Working on FRDM K64F with two clients ok - browser tends to reopen socket so curl has to wait for timeout but seems to retry ok 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
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