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.
RdWebServerDefs.h@28:99036ff32459, 2016-02-08 (annotated)
- Committer:
- Bobty
- Date:
- Mon Feb 08 13:47:29 2016 +0000
- Revision:
- 28:99036ff32459
- Child:
- 29:46998f2e458f
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
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Bobty | 28:99036ff32459 | 1 | // RdWebServer - Simple Web Server for MBED |
Bobty | 28:99036ff32459 | 2 | // Copyright (C) Rob Dobson 2013-2016, MIT License |
Bobty | 28:99036ff32459 | 3 | // Inspired by Jasper Schuurmans multi-threaded web server for Netduino which now seems to have gone from ... |
Bobty | 28:99036ff32459 | 4 | // http://www.schuurmans.cc/multi-threaded-web-server-for-netduino-plus |
Bobty | 28:99036ff32459 | 5 | // More details at http://robdobson.com/2013/10/moving-my-window-shades-control-to-mbed/ |
Bobty | 28:99036ff32459 | 6 | |
Bobty | 28:99036ff32459 | 7 | #ifndef RD_WEB_SERVER_DEFS |
Bobty | 28:99036ff32459 | 8 | #define RD_WEB_SERVER_DEFS |
Bobty | 28:99036ff32459 | 9 | |
Bobty | 28:99036ff32459 | 10 | // Setting RDWEB_DEBUG to 4 causes all debugging to be shown |
Bobty | 28:99036ff32459 | 11 | #define RDWEB_DEBUG 2 |
Bobty | 28:99036ff32459 | 12 | |
Bobty | 28:99036ff32459 | 13 | // Change the settings below to support a local file system (not available on some MBEDs) |
Bobty | 28:99036ff32459 | 14 | //#define SUPPORT_LOCAL_FILESYSTEM 1 |
Bobty | 28:99036ff32459 | 15 | //#define SUPPORT_LOCAL_FILE_CACHE 1 |
Bobty | 28:99036ff32459 | 16 | //#define SUPPORT_SD_FILESYSTEM 1 |
Bobty | 28:99036ff32459 | 17 | |
Bobty | 28:99036ff32459 | 18 | // Change this to support display of files on the server |
Bobty | 28:99036ff32459 | 19 | // #define SUPPORT_FOLDER_VIEW 1 |
Bobty | 28:99036ff32459 | 20 | |
Bobty | 28:99036ff32459 | 21 | #include "cc3000.h" |
Bobty | 28:99036ff32459 | 22 | #include "TCPSocketConnection.h" |
Bobty | 28:99036ff32459 | 23 | #include "TCPSocketServer.h" |
Bobty | 28:99036ff32459 | 24 | |
Bobty | 28:99036ff32459 | 25 | #endif |