Working sample which demonstrates the Http Server implementation using WiFlyHTTPServer library.
Dependencies: WiFlyHTTPServer WiflyInterface mbed-rpc mbed
main.cpp@2:b3d211f851dd, 2013-06-02 (annotated)
- Committer:
- leihen
- Date:
- Sun Jun 02 00:53:38 2013 +0000
- Revision:
- 2:b3d211f851dd
- Parent:
- 1:da491ef49a3e
Updates for changes in libraries
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
leihen | 0:71b654aa5846 | 1 | #include "mbed.h" |
leihen | 0:71b654aa5846 | 2 | #include "HTTPServer.h" |
leihen | 0:71b654aa5846 | 3 | #include "FsHandler.h" |
leihen | 0:71b654aa5846 | 4 | #include "RpcHandler.h" |
leihen | 0:71b654aa5846 | 5 | #include "LocalFileSystem.h" |
leihen | 0:71b654aa5846 | 6 | #include "mbed_rpc.h" |
leihen | 0:71b654aa5846 | 7 | |
leihen | 0:71b654aa5846 | 8 | DigitalOut myled(LED1); |
leihen | 0:71b654aa5846 | 9 | |
leihen | 0:71b654aa5846 | 10 | LocalFileSystem local("local"); |
leihen | 0:71b654aa5846 | 11 | |
leihen | 2:b3d211f851dd | 12 | HTTPServer svr(p9, p10, p30, p29, "<Your AP Name>", "<Your Passphrase>", WPA); |
leihen | 0:71b654aa5846 | 13 | |
leihen | 0:71b654aa5846 | 14 | |
leihen | 0:71b654aa5846 | 15 | RpcDigitalOut Led1(LED1, "Led1"); |
leihen | 0:71b654aa5846 | 16 | RpcDigitalOut Led2(LED2, "Led2"); |
leihen | 0:71b654aa5846 | 17 | RpcDigitalOut Led3(LED3, "Led3"); |
leihen | 0:71b654aa5846 | 18 | RpcDigitalOut Led4(LED4, "Led4"); |
leihen | 0:71b654aa5846 | 19 | |
leihen | 0:71b654aa5846 | 20 | int main() { |
leihen | 0:71b654aa5846 | 21 | std::string tim; |
leihen | 0:71b654aa5846 | 22 | |
leihen | 0:71b654aa5846 | 23 | /* Mount the local file system. */ |
leihen | 0:71b654aa5846 | 24 | HTTPFsRequestHandler::mount("/local/", "/"); |
leihen | 0:71b654aa5846 | 25 | |
leihen | 0:71b654aa5846 | 26 | /* Add handler for file system access */ |
leihen | 0:71b654aa5846 | 27 | svr.addHandler<HTTPFsRequestHandler>("/"); |
leihen | 0:71b654aa5846 | 28 | /* Add handler to acces RPC objects */ |
leihen | 0:71b654aa5846 | 29 | svr.addHandler<HTTPRpcRequestHandler>("/rpc/"); |
leihen | 0:71b654aa5846 | 30 | |
leihen | 0:71b654aa5846 | 31 | /* Start the server which will listen for incoming connections on port 80 */ |
leihen | 0:71b654aa5846 | 32 | svr.start(80); |
leihen | 0:71b654aa5846 | 33 | |
leihen | 0:71b654aa5846 | 34 | |
leihen | 0:71b654aa5846 | 35 | while(1) { |
leihen | 0:71b654aa5846 | 36 | /* get the time and the uptime from WiFly */ |
leihen | 2:b3d211f851dd | 37 | tim = svr.getTime(); |
leihen | 2:b3d211f851dd | 38 | printf("Current time is : %s\n", tim.c_str()); |
leihen | 0:71b654aa5846 | 39 | |
leihen | 0:71b654aa5846 | 40 | if (svr.poll(false) >= 0) { |
leihen | 0:71b654aa5846 | 41 | myled = !myled; |
leihen | 0:71b654aa5846 | 42 | } |
leihen | 0:71b654aa5846 | 43 | else { |
leihen | 0:71b654aa5846 | 44 | error("WiFly Polling failed."); |
leihen | 0:71b654aa5846 | 45 | } |
leihen | 0:71b654aa5846 | 46 | |
leihen | 0:71b654aa5846 | 47 | } |
leihen | 0:71b654aa5846 | 48 | } |