HTTP RPC Server mit vordefinierten Objekten

Dependencies:   EthernetInterface HttpServer Servo mbed-rtos mbed

Fork of RPCHTTPServerVariable by th.iotkit2.ch

Mittels RPCVariable lassen sich lokale Variablen setzen. Diese Variablen können gesetzt write oder gelesen read werden.

Mittels Ticker u.ä. Varianten lassen sich damit auch Objektwerte setzen, welche von RPC nicht unterstützt werden, z.B. Servo's.

Client

Wert setzen: http://<IP-Adresse mbed>/rpc/servo2/write+0.5

Committer:
yueee_yt
Date:
Sat Feb 22 05:55:58 2014 +0000
Revision:
5:bfa9878aa274
Parent:
4:155c6ff99458
Child:
6:c9c7ffa0594e
Remove USB MSD!(donot work)
; mbed-rtos is to double registration(in USBHost).

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yueee_yt 0:050a5d4ffd55 1 //#define DNS_SERVER_ADDRESS(ipaddr) (ip4_addr_set_u32(ipaddr, ipaddr_addr("208.67.222.222"))) /* resolver1.opendns.com */
yueee_yt 0:050a5d4ffd55 2 #include "mbed.h"
yueee_yt 0:050a5d4ffd55 3 #include "rtos.h"
yueee_yt 0:050a5d4ffd55 4 #include "EthernetInterface.h"
yueee_yt 0:050a5d4ffd55 5 #include "HTTPServer.h"
yueee_yt 3:5758cfefe980 6 #include "mbed_rpc.h"
yueee_yt 4:155c6ff99458 7 #include "TextLCD.h"
yueee_yt 5:bfa9878aa274 8
yueee_yt 0:050a5d4ffd55 9 EthernetInterface eth;
yueee_yt 3:5758cfefe980 10
yueee_yt 3:5758cfefe980 11 DigitalOut led4(LED4);
yueee_yt 5:bfa9878aa274 12
yueee_yt 5:bfa9878aa274 13 LocalFileSystem local("local");
yueee_yt 5:bfa9878aa274 14 void LcdWrite(Arguments* arg, Reply* r); //ADD Here!!
yueee_yt 5:bfa9878aa274 15
yueee_yt 4:155c6ff99458 16 TextLCD lcd(p24, p26, p27, p28, p29, p30);
yueee_yt 0:050a5d4ffd55 17
yueee_yt 5:bfa9878aa274 18 void aliveState(void const *args)
yueee_yt 5:bfa9878aa274 19 {
yueee_yt 0:050a5d4ffd55 20 while (true) {
yueee_yt 3:5758cfefe980 21 led4 = !led4;
yueee_yt 0:050a5d4ffd55 22 Thread::wait(1000);
yueee_yt 0:050a5d4ffd55 23 }
yueee_yt 0:050a5d4ffd55 24 }
yueee_yt 0:050a5d4ffd55 25
yueee_yt 0:050a5d4ffd55 26 int main()
yueee_yt 0:050a5d4ffd55 27 {
yueee_yt 0:050a5d4ffd55 28 printf("********* PROGRAM START ***********\r\n");
yueee_yt 0:050a5d4ffd55 29 Thread thread(aliveState);
yueee_yt 3:5758cfefe980 30 RPC::add_rpc_class<RpcDigitalOut>();
yueee_yt 5:bfa9878aa274 31 RPC::construct<RpcDigitalOut, PinName, const char*>(LED1, "led1");
yueee_yt 5:bfa9878aa274 32 RPC::construct<RpcDigitalOut, PinName, const char*>(LED2, "led2");
yueee_yt 5:bfa9878aa274 33 RPC::construct<RpcDigitalOut, PinName, const char*>(LED3, "led3");
yueee_yt 4:155c6ff99458 34 RPCFunction rpcFunc(LcdWrite, "LcdWrite"); //ADD Here!!
yueee_yt 5:bfa9878aa274 35 lcd.cls();
yueee_yt 4:155c6ff99458 36 lcd.locate(0,0);
yueee_yt 3:5758cfefe980 37
yueee_yt 0:050a5d4ffd55 38 printf("EthernetInterface Setting up...\r\n");
yueee_yt 0:050a5d4ffd55 39 if(eth.init()!=0) { //for DHCP Server
yueee_yt 5:bfa9878aa274 40 //if(eth.init(IPAddress,NetMasks,Gateway)!=0) { //for Static IP Address
yueee_yt 0:050a5d4ffd55 41 printf("EthernetInterface Initialize Error \r\n");
yueee_yt 0:050a5d4ffd55 42 return -1;
yueee_yt 0:050a5d4ffd55 43 }
yueee_yt 0:050a5d4ffd55 44 if(eth.connect()!=0) {
yueee_yt 0:050a5d4ffd55 45 printf("EthernetInterface Connect Error \r\n");
yueee_yt 0:050a5d4ffd55 46 return -1;
yueee_yt 0:050a5d4ffd55 47 }
yueee_yt 0:050a5d4ffd55 48 printf("IP Address is %s\r\n", eth.getIPAddress());
yueee_yt 0:050a5d4ffd55 49 printf("NetMask is %s\r\n", eth.getNetworkMask());
yueee_yt 0:050a5d4ffd55 50 printf("Gateway Address is %s\r\n", eth.getGateway());
yueee_yt 0:050a5d4ffd55 51 printf("Ethernet Setup OK\r\n");
yueee_yt 0:050a5d4ffd55 52
yueee_yt 3:5758cfefe980 53 HTTPServerAddHandler<SimpleHandler>("/hello"); //Default handler
yueee_yt 3:5758cfefe980 54 FSHandler::mount("/local", "/");
yueee_yt 3:5758cfefe980 55 HTTPServerAddHandler<FSHandler>("/");
yueee_yt 3:5758cfefe980 56 HTTPServerAddHandler<RPCHandler>("/rpc");
yueee_yt 4:155c6ff99458 57 lcd.locate(0,0);
yueee_yt 4:155c6ff99458 58 lcd.printf("%s",eth.getIPAddress());
yueee_yt 0:050a5d4ffd55 59 HTTPServerStart(80);
yueee_yt 0:050a5d4ffd55 60 }
yueee_yt 0:050a5d4ffd55 61
yueee_yt 4:155c6ff99458 62 void LcdWrite(Arguments* arg, Reply* r) //ADD Here!!
yueee_yt 4:155c6ff99458 63 {
yueee_yt 4:155c6ff99458 64 lcd.locate(0,1);
yueee_yt 4:155c6ff99458 65 lcd.printf("%s",arg->argv[0]);
yueee_yt 4:155c6ff99458 66 }