Working sample implementation for the EthernetInterface HTTPServer.
Dependencies: EthernetInterface HTTPServer mbed-rpc mbed-rtos mbed
Sample application which shows basic functionality of my HTTPServer library.
Import libraryHTTPServer
Single instance HTTP Server using new Ethernet Interface.
.
Revision 1:6cbd17e628f1, committed 2013-08-17
- Comitter:
- leihen
- Date:
- Sat Aug 17 12:32:09 2013 +0000
- Parent:
- 0:28a67716dfec
- Child:
- 2:6554da6c762b
- Commit message:
- Updated the example to reflect the modification of the HTTPServer library, which allows to provide an EthernetInterface object at the time of starting the HTTPServer. This allows to make Connections and perform other Network Tasks before svr start.
Changed in this revision
--- a/EthernetInterface.lib Sat Jun 22 15:50:41 2013 +0000 +++ b/EthernetInterface.lib Sat Aug 17 12:32:09 2013 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/EthernetInterface/#40640efbfcae +http://mbed.org/users/mbed_official/code/EthernetInterface/#196410fbb211
--- a/HTTPServer.lib Sat Jun 22 15:50:41 2013 +0000 +++ b/HTTPServer.lib Sat Aug 17 12:32:09 2013 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/leihen/code/HTTPServer/#aa5338a5e452 +http://mbed.org/users/leihen/code/HTTPServer/#011edcd33e86
--- a/main.cpp Sat Jun 22 15:50:41 2013 +0000 +++ b/main.cpp Sat Aug 17 12:32:09 2013 +0000 @@ -3,14 +3,23 @@ #include "FsHandler.h" #include "LocalFileSystem.h" +#define ALTERNATIVE +//#undef ALTERNATIVE +// Use LED1 to indicate that the main loop is still executing DigitalOut myled(LED1); - +// Use the serial connection 'pc' to dump debug information Serial pc(USBTX, USBRX, "pc"); - +// Instantiate a HTTPServer to handle incoming requests HTTPServer svr; +// Instantiate a local file system handler named 'local' which will be used later to access files on the mbed. +LocalFileSystem local("local"); -LocalFileSystem local("local"); +#ifdef ALTERNATIVE +// Create the EthernetInterface. This is optional, please see the documentation of HTTP Server's start method. +EthernetInterface eth; +#endif + int main() { @@ -18,7 +27,15 @@ HTTPFsRequestHandler::mount("/local/", "/"); svr.addHandler<HTTPFsRequestHandler>("/"); +#ifdef ALTERNATIVE + // Initialize the EthernetInterface and initiate a connection using DHCP. + eth.init(); + eth.connect(); + + if (!svr.start(80, ð)) { +#else if (!svr.start()) { +#endif error("Server not starting !"); exit(0); }