ported HTTP-Server with W5500 Ethernet Shield

Dependencies:   W5500Interface mbed-rpc mbed

Fork of HTTP-Server by Francois Berder

Committer:
feb11
Date:
Wed Jul 17 10:15:05 2013 +0000
Revision:
0:9e4bcb10b3e3
Child:
3:fb0a778f2480
Initial import

Who changed what in which revision?

UserRevisionLine numberNew 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 0:9e4bcb10b3e3 37 HTTPServer srv = create_simple_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