HTTP (RPC) Server mit UI

Dependencies:   EthernetInterface mbed-rpc mbed-rtos mbed

Fork of IoTKit_RPC-Server by th.iotkit.ch

HTTP (RPC) Server mit eigener UI Oberfläche.

Board mit dem Ethernet verbinden. Console starten und angezeigte IP-Adresse notieren und in Browser öffnen.

Create Object

Type: DigitalOut Name: led1 arg(optional): PTB22

und Create Button drücken.

Call a function

Command: /led1/write 1

eingeben und Send drücken. Das rote LED auf dem Board geht aus. Mittels /led1/write 0 wird es wieder eingeschaltet.

Für die komplette Dokumentation siehe /users/feb11/code/HTTP-Server/

Committer:
feb11
Date:
Thu Jul 18 09:39:35 2013 +0000
Revision:
9:a9bf63017854
Parent:
3:fb0a778f2480
Child:
12:e04008977007
Improved error message

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 9:a9bf63017854 33 if(eth.init())
feb11 9:a9bf63017854 34 {
feb11 9:a9bf63017854 35 printf("Error while initializing the ethernet interface.\n");
feb11 9:a9bf63017854 36 return -1;
feb11 9:a9bf63017854 37 }
feb11 9:a9bf63017854 38 if(eth.connect())
feb11 9:a9bf63017854 39 {
feb11 9:a9bf63017854 40 printf("Error while starting the ethernet interface.\n");
feb11 9:a9bf63017854 41 return -1;
feb11 9:a9bf63017854 42 }
feb11 9:a9bf63017854 43
feb11 0:9e4bcb10b3e3 44 printf("IP Address is %s\n", eth.getIPAddress());
feb11 0:9e4bcb10b3e3 45
feb11 3:fb0a778f2480 46 HTTPServer srv = create_interactive_server();
feb11 0:9e4bcb10b3e3 47
feb11 0:9e4bcb10b3e3 48 if(!srv.init(SERVER_PORT))
feb11 0:9e4bcb10b3e3 49 {
feb11 0:9e4bcb10b3e3 50 eth.disconnect();
feb11 0:9e4bcb10b3e3 51 return -1;
feb11 0:9e4bcb10b3e3 52 }
feb11 0:9e4bcb10b3e3 53
feb11 0:9e4bcb10b3e3 54 srv.run();
feb11 0:9e4bcb10b3e3 55
feb11 0:9e4bcb10b3e3 56 return 0;
feb11 0:9e4bcb10b3e3 57 }
feb11 0:9e4bcb10b3e3 58