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
- Committer:
- wgd8700
- Date:
- 2015-09-16
- Revision:
- 11:f57e9de44f6f
- Parent:
- 9:a9bf63017854
File content as of revision 11:f57e9de44f6f:
#include "mbed.h" #include "EthernetInterface.h" #include "mbed_rpc.h" #include "RPCCommand.h" #include "HTTPServer.h" #include "Formatter.h" #include "RequestHandler.h" #include "RPCType.h" #include "WIFIDevice.h" #define SERVER_PORT 80 WIFIDevice wifi; HTTPServer create_simple_server() { HTTPServer srv; srv.add_request_handler("DELETE", new DeleteRequestHandler()); srv.add_request_handler("GET", new GetRequestHandler()); srv.add_request_handler("PUT", new PutRequestHandler()); return srv; } HTTPServer create_interactive_server() { HTTPServer srv(new InteractiveHTMLFormatter()); srv.add_request_handler("GET", new ComplexRequestHandler()); return srv; } int main(void) { RPCType::instance().register_types(); EthernetInterface eth; //wifi.setNetwork("GainSpan_JS", "Delta9999", 0); //wifi.setNetwork("TP-LINK_2.4G_TTWU", "0972753720", 0); wifi.setAccessPoint("NNN40_TTWU", "0123456789", SECURITY_WPA2_TKIP_PSK, 2); if(eth.init()) { printf("Error while initializing the ethernet interface.\n"); return -1; } if(eth.connect(60000)) { printf("Error while starting the ethernet interface.\n"); return -1; } printf("IP Address is %s\n", eth.getIPAddress()); HTTPServer srv = create_interactive_server(); if(!srv.init(SERVER_PORT)) { eth.disconnect(); return -1; } srv.run(); return 0; }