ported HTTP-Server with W5500 Ethernet Shield

Dependencies:   W5500Interface mbed-rpc mbed

Fork of HTTP-Server by F B

Committer:
embeddist
Date:
Tue Apr 28 13:54:18 2015 +0000
Revision:
11:ac3569846176
Parent:
9:a9bf63017854
ported HTTP-Server with W5500 Ethernet Shield

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
embeddist 11:ac3569846176 12 char ipaddr_backup[17];
embeddist 11:ac3569846176 13 uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x00, 0x01, 0x02};
embeddist 11:ac3569846176 14
feb11 0:9e4bcb10b3e3 15 HTTPServer create_simple_server()
feb11 0:9e4bcb10b3e3 16 {
feb11 0:9e4bcb10b3e3 17 HTTPServer srv;
feb11 0:9e4bcb10b3e3 18 srv.add_request_handler("DELETE", new DeleteRequestHandler());
feb11 0:9e4bcb10b3e3 19 srv.add_request_handler("GET", new GetRequestHandler());
feb11 0:9e4bcb10b3e3 20 srv.add_request_handler("PUT", new PutRequestHandler());
feb11 0:9e4bcb10b3e3 21 return srv;
feb11 0:9e4bcb10b3e3 22 }
feb11 0:9e4bcb10b3e3 23
feb11 0:9e4bcb10b3e3 24 HTTPServer create_interactive_server()
feb11 0:9e4bcb10b3e3 25 {
feb11 0:9e4bcb10b3e3 26 HTTPServer srv(new InteractiveHTMLFormatter());
feb11 0:9e4bcb10b3e3 27 srv.add_request_handler("GET", new ComplexRequestHandler());
feb11 0:9e4bcb10b3e3 28 return srv;
feb11 0:9e4bcb10b3e3 29 }
feb11 0:9e4bcb10b3e3 30
feb11 0:9e4bcb10b3e3 31 int main(void)
feb11 0:9e4bcb10b3e3 32 {
feb11 0:9e4bcb10b3e3 33 RPCType::instance().register_types();
embeddist 11:ac3569846176 34 /* //for LPC1768
embeddist 11:ac3569846176 35 SPI spi(p5, p6, p7); // mosi, miso, sclk
embeddist 11:ac3569846176 36 spi.frequency(12500000);
embeddist 11:ac3569846176 37 EthernetInterface eth(&spi, p8, p11); // spi, cs, reset
embeddist 11:ac3569846176 38 */
embeddist 11:ac3569846176 39 SPI spi(D11, D12, D13); // mosi, miso, sclk
embeddist 11:ac3569846176 40 //spi.frequency(12500000);
embeddist 11:ac3569846176 41 EthernetInterface eth(&spi, D10, D9); // spi, cs, reset
feb11 0:9e4bcb10b3e3 42
embeddist 11:ac3569846176 43 //EthernetInterface eth;
embeddist 11:ac3569846176 44 //if(eth.init())
embeddist 11:ac3569846176 45 // int ret = eth.init("192.168.77.34", "255.255.255.0", "192.168.77.1");
embeddist 11:ac3569846176 46 int ret = eth.init(mac_addr, "192.168.77.34", "255.255.255.0", "192.168.77.1");
embeddist 11:ac3569846176 47 if(ret)
feb11 9:a9bf63017854 48 {
feb11 9:a9bf63017854 49 printf("Error while initializing the ethernet interface.\n");
feb11 9:a9bf63017854 50 return -1;
feb11 9:a9bf63017854 51 }
feb11 9:a9bf63017854 52 if(eth.connect())
feb11 9:a9bf63017854 53 {
feb11 9:a9bf63017854 54 printf("Error while starting the ethernet interface.\n");
feb11 9:a9bf63017854 55 return -1;
feb11 9:a9bf63017854 56 }
feb11 9:a9bf63017854 57
feb11 0:9e4bcb10b3e3 58 printf("IP Address is %s\n", eth.getIPAddress());
embeddist 11:ac3569846176 59 strcpy(ipaddr_backup,eth.getIPAddress());
feb11 3:fb0a778f2480 60 HTTPServer srv = create_interactive_server();
feb11 0:9e4bcb10b3e3 61
feb11 0:9e4bcb10b3e3 62 if(!srv.init(SERVER_PORT))
feb11 0:9e4bcb10b3e3 63 {
feb11 0:9e4bcb10b3e3 64 eth.disconnect();
feb11 0:9e4bcb10b3e3 65 return -1;
feb11 0:9e4bcb10b3e3 66 }
feb11 0:9e4bcb10b3e3 67
feb11 0:9e4bcb10b3e3 68 srv.run();
feb11 0:9e4bcb10b3e3 69
feb11 0:9e4bcb10b3e3 70 return 0;
feb11 0:9e4bcb10b3e3 71 }
feb11 0:9e4bcb10b3e3 72