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.

Changes

RevisionDateWhoCommit message
29:46998f2e458f 2016-02-08 Bobty Fixed RTOS namespace issue default tip
28:99036ff32459 2016-02-08 Bobty 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
27:0c2d6f598ae5 2015-10-16 Bobty Re-enabled folder view by default
26:3c4c10e989b1 2015-10-13 Bobty Added the capability to support a Mutex to control access to the SD card and avoid clashes
25:ffa1dddd3da4 2015-09-28 Bobty Fix problem getting a file from SD card; Changed debug messages
24:27800de38eab 2015-08-31 Bobty 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.
23:0fc3d7b5e596 2015-08-31 Bobty Changed blocking options to default non-blocking; Detected OPTIONS HTTP method; Changed to always use keep-alive
22:598a21373539 2015-08-29 Bobty Added Access Control Allow Origin to HTTP header in RdWebServer; Added setName/getName for hostname setting in EthernetInterface; Set hostname to systemName
21:2dfb56648b93 2015-08-20 Bobty Now defaults to support local file system
20:e6c7db867593 2015-08-14 Bobty Updated comments
19:f67ac231b570 2015-05-12 Bobty Allow larger buffer on K64F (more RAM), tidied up diagnostics and added code to get message payload
18:5de680c4cfcb 2015-05-11 Bobty 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
17:080f2bed8b36 2015-05-11 Bobty Improved settings
16:0248bbfdb6c1 2015-05-05 Bobty 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
15:0865fa4b046a 2015-05-05 Bobty Pared back for work on stability - ok on LPC1768
14:4b83670854f0 2015-05-05 Bobty Improving robustness
13:4f9c09d3da13 2015-05-04 Bobty Debugging
12:c14ffd4ec125 2015-05-03 Bobty Added debugging macros
11:cec51b430b20 2015-05-03 Bobty Added debugging macros
10:b4b9d4d5e5be 2015-02-22 Bobty Fixed problem with folder listings
9:35668248199b 2015-02-22 Bobty Changed back to non-blocking - seems more stable
8:de915bd70ec1 2015-02-20 Bobty Reinstated some code I'd missed out when changing to run in a thread. The code handles timeouts on the HTTP connection.
7:fe7c33f7fbb8 2015-02-07 Bobty Working with gas count - not tested on actual meter reed switch
6:46285c519af2 2015-02-06 Bobty Working with threaded server and SD card stack extended to stop crashes
5:e6286b529d6b 2015-02-03 Bobty Minor tweak
4:6afb3bbf20a4 2015-02-02 Bobty Updated to use SD or USB
3:594136d34a32 2013-10-04 Bobty Tidied up a little - no functional changes
2:9d8793c23b46 2013-10-04 Bobty Initial Revision Working
1:75bb184de749 2013-09-19 Bobty Added code to support commands - still a lot of test code in place though
0:b5b4d07f7827 2013-09-18 Bobty Initial