Working sample which demonstrates the Http Server implementation using WiFlyHTTPServer library.
Dependencies: WiFlyHTTPServer WiflyInterface mbed-rpc mbed
main.cpp
- Committer:
- leihen
- Date:
- 2013-06-01
- Revision:
- 1:da491ef49a3e
- Parent:
- 0:71b654aa5846
- Child:
- 2:b3d211f851dd
File content as of revision 1:da491ef49a3e:
#include "mbed.h" #include "WiflyInterface.h" #include "HTTPServer.h" #include "FsHandler.h" #include "RpcHandler.h" #include "LocalFileSystem.h" #include "mbed_rpc.h" DigitalOut myled(LED1); WiflyInterface wifly(p9, p10, p25, p26, "<Your AP Name>", "<Your Passphrase>", WPA); LocalFileSystem local("local"); HTTPServer svr; RpcDigitalOut Led1(LED1, "Led1"); RpcDigitalOut Led2(LED2, "Led2"); RpcDigitalOut Led3(LED3, "Led3"); RpcDigitalOut Led4(LED4, "Led4"); int main() { std::string tim; /* Mount the local file system. */ HTTPFsRequestHandler::mount("/local/", "/"); /* Start the wifly interface and connect to an AP */ wifly.init(); while(!wifly.connect()); /* Add handler for file system access */ svr.addHandler<HTTPFsRequestHandler>("/"); /* Add handler to acces RPC objects */ svr.addHandler<HTTPRpcRequestHandler>("/rpc/"); /* Start the server which will listen for incoming connections on port 80 */ svr.start(80); while(1) { /* get the time and the uptime from WiFly */ tim = wifly.getTime(false); printf("Current time is : %s\n", tim); if (svr.poll(false) >= 0) { myled = !myled; } else { error("WiFly Polling failed."); } } }