NNN40 run a HTTP server with RPC using Soft AP mode
Dependencies: WIFI_API_32kRAM mbed
Fork of HTTP-Server by
The sample code will run as a WiFi Soft AP mode with given AP configuration setting including SSID name and password. IP address (fixed to 192.168.2.1 for the current version of WIFI_API)of AP router will be print out once Soft AP mode is operating.
User can open their web browser and go to http://192.168.2.1/. and have a try on switch on a led. Firstly, we need to create an object to control a led
Then, led can be switch on using RPC command
More information cab be found from the links below
https://developer.mbed.org/users/feb11/code/HTTP-Server/
https://developer.mbed.org/cookbook/Interfacing-Using-RPC
main.cpp@3:fb0a778f2480, 2013-07-17 (annotated)
- Committer:
- feb11
- Date:
- Wed Jul 17 11:07:06 2013 +0000
- Revision:
- 3:fb0a778f2480
- Parent:
- 0:9e4bcb10b3e3
- Child:
- 9:a9bf63017854
Interactive server by default
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
feb11 | 0:9e4bcb10b3e3 | 1 | #include "mbed.h" |
feb11 | 0:9e4bcb10b3e3 | 2 | #include "EthernetInterface.h" |
feb11 | 0:9e4bcb10b3e3 | 3 | #include "mbed_rpc.h" |
feb11 | 0:9e4bcb10b3e3 | 4 | #include "RPCCommand.h" |
feb11 | 0:9e4bcb10b3e3 | 5 | #include "HTTPServer.h" |
feb11 | 0:9e4bcb10b3e3 | 6 | #include "Formatter.h" |
feb11 | 0:9e4bcb10b3e3 | 7 | #include "RequestHandler.h" |
feb11 | 0:9e4bcb10b3e3 | 8 | #include "RPCType.h" |
feb11 | 0:9e4bcb10b3e3 | 9 | |
feb11 | 0:9e4bcb10b3e3 | 10 | #define SERVER_PORT 80 |
feb11 | 0:9e4bcb10b3e3 | 11 | |
feb11 | 0:9e4bcb10b3e3 | 12 | HTTPServer create_simple_server() |
feb11 | 0:9e4bcb10b3e3 | 13 | { |
feb11 | 0:9e4bcb10b3e3 | 14 | HTTPServer srv; |
feb11 | 0:9e4bcb10b3e3 | 15 | srv.add_request_handler("DELETE", new DeleteRequestHandler()); |
feb11 | 0:9e4bcb10b3e3 | 16 | srv.add_request_handler("GET", new GetRequestHandler()); |
feb11 | 0:9e4bcb10b3e3 | 17 | srv.add_request_handler("PUT", new PutRequestHandler()); |
feb11 | 0:9e4bcb10b3e3 | 18 | return srv; |
feb11 | 0:9e4bcb10b3e3 | 19 | } |
feb11 | 0:9e4bcb10b3e3 | 20 | |
feb11 | 0:9e4bcb10b3e3 | 21 | HTTPServer create_interactive_server() |
feb11 | 0:9e4bcb10b3e3 | 22 | { |
feb11 | 0:9e4bcb10b3e3 | 23 | HTTPServer srv(new InteractiveHTMLFormatter()); |
feb11 | 0:9e4bcb10b3e3 | 24 | srv.add_request_handler("GET", new ComplexRequestHandler()); |
feb11 | 0:9e4bcb10b3e3 | 25 | return srv; |
feb11 | 0:9e4bcb10b3e3 | 26 | } |
feb11 | 0:9e4bcb10b3e3 | 27 | |
feb11 | 0:9e4bcb10b3e3 | 28 | int main(void) |
feb11 | 0:9e4bcb10b3e3 | 29 | { |
feb11 | 0:9e4bcb10b3e3 | 30 | RPCType::instance().register_types(); |
feb11 | 0:9e4bcb10b3e3 | 31 | |
feb11 | 0:9e4bcb10b3e3 | 32 | EthernetInterface eth; |
feb11 | 0:9e4bcb10b3e3 | 33 | eth.init(); |
feb11 | 0:9e4bcb10b3e3 | 34 | eth.connect(); |
feb11 | 0:9e4bcb10b3e3 | 35 | printf("IP Address is %s\n", eth.getIPAddress()); |
feb11 | 0:9e4bcb10b3e3 | 36 | |
feb11 | 3:fb0a778f2480 | 37 | HTTPServer srv = create_interactive_server(); |
feb11 | 0:9e4bcb10b3e3 | 38 | |
feb11 | 0:9e4bcb10b3e3 | 39 | if(!srv.init(SERVER_PORT)) |
feb11 | 0:9e4bcb10b3e3 | 40 | { |
feb11 | 0:9e4bcb10b3e3 | 41 | printf("Error while initializing the server\n"); |
feb11 | 0:9e4bcb10b3e3 | 42 | eth.disconnect(); |
feb11 | 0:9e4bcb10b3e3 | 43 | return -1; |
feb11 | 0:9e4bcb10b3e3 | 44 | } |
feb11 | 0:9e4bcb10b3e3 | 45 | |
feb11 | 0:9e4bcb10b3e3 | 46 | srv.run(); |
feb11 | 0:9e4bcb10b3e3 | 47 | |
feb11 | 0:9e4bcb10b3e3 | 48 | return 0; |
feb11 | 0:9e4bcb10b3e3 | 49 | } |
feb11 | 0:9e4bcb10b3e3 | 50 |