![](/media/cache/profiles/0314c9b108b8c39f1cf878ed93fdd5ae.50x50_q85.jpg)
Web Server and send X10 RF orders to X10 RF transceivers Switch On/Off Appliance No weather Rx at the moment...
Dependencies: EthernetNetIf mbed HTTPServer
main.cpp@0:7f9517ce9e71, 2011-08-27 (annotated)
- Committer:
- lotfi_baghli
- Date:
- Sat Aug 27 16:45:11 2011 +0000
- Revision:
- 0:7f9517ce9e71
V0.21
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lotfi_baghli | 0:7f9517ce9e71 | 1 | #include "mbed.h" |
lotfi_baghli | 0:7f9517ce9e71 | 2 | #include "EthernetNetIf.h" |
lotfi_baghli | 0:7f9517ce9e71 | 3 | //#include "HTTPClient.h" |
lotfi_baghli | 0:7f9517ce9e71 | 4 | #include "HTTPServer.h" |
lotfi_baghli | 0:7f9517ce9e71 | 5 | #include "RPCFunction.h" |
lotfi_baghli | 0:7f9517ce9e71 | 6 | #include "x10rf.h" |
lotfi_baghli | 0:7f9517ce9e71 | 7 | |
lotfi_baghli | 0:7f9517ce9e71 | 8 | EthernetNetIf eth( |
lotfi_baghli | 0:7f9517ce9e71 | 9 | IpAddr(192,168,1,25), //IP Address |
lotfi_baghli | 0:7f9517ce9e71 | 10 | IpAddr(255,255,255,0), //Network Mask |
lotfi_baghli | 0:7f9517ce9e71 | 11 | IpAddr(192,168,1,1), //Gateway |
lotfi_baghli | 0:7f9517ce9e71 | 12 | IpAddr(192,168,1,1) //DNS |
lotfi_baghli | 0:7f9517ce9e71 | 13 | ); |
lotfi_baghli | 0:7f9517ce9e71 | 14 | //HTTPClient http; |
lotfi_baghli | 0:7f9517ce9e71 | 15 | HTTPServer svr; |
lotfi_baghli | 0:7f9517ce9e71 | 16 | |
lotfi_baghli | 0:7f9517ce9e71 | 17 | DigitalOut led1(LED1, "led1"); |
lotfi_baghli | 0:7f9517ce9e71 | 18 | DigitalOut led2(LED2, "led2"); |
lotfi_baghli | 0:7f9517ce9e71 | 19 | DigitalOut led3(LED3, "led3"); |
lotfi_baghli | 0:7f9517ce9e71 | 20 | DigitalOut led4(LED4, "led4"); |
lotfi_baghli | 0:7f9517ce9e71 | 21 | |
lotfi_baghli | 0:7f9517ce9e71 | 22 | LocalFileSystem fs("webfs"); |
lotfi_baghli | 0:7f9517ce9e71 | 23 | |
lotfi_baghli | 0:7f9517ce9e71 | 24 | //Create a function of the required format |
lotfi_baghli | 0:7f9517ce9e71 | 25 | void rpcX10rf(char * input, char * output); |
lotfi_baghli | 0:7f9517ce9e71 | 26 | //Attach it to an RPC object |
lotfi_baghli | 0:7f9517ce9e71 | 27 | RPCFunction rpc_foo(&rpcX10rf, "rpcX10rf"); |
lotfi_baghli | 0:7f9517ce9e71 | 28 | |
lotfi_baghli | 0:7f9517ce9e71 | 29 | void rpcX10rf(char * input, char * output) { |
lotfi_baghli | 0:7f9517ce9e71 | 30 | char houseCode; |
lotfi_baghli | 0:7f9517ce9e71 | 31 | short int numberCode, action; |
lotfi_baghli | 0:7f9517ce9e71 | 32 | printf("%s\r\n", input); |
lotfi_baghli | 0:7f9517ce9e71 | 33 | sscanf(input, " %c,%d,%d", &houseCode, &numberCode, &action); |
lotfi_baghli | 0:7f9517ce9e71 | 34 | printf("%c, %d,%d\r\n", houseCode, numberCode, action); |
lotfi_baghli | 0:7f9517ce9e71 | 35 | // calls the X10RFLib |
lotfi_baghli | 0:7f9517ce9e71 | 36 | SendX10rf( houseCode, numberCode, action); |
lotfi_baghli | 0:7f9517ce9e71 | 37 | |
lotfi_baghli | 0:7f9517ce9e71 | 38 | //nothing to send back - sprintf(output, "%i, %i", x, y ); |
lotfi_baghli | 0:7f9517ce9e71 | 39 | } |
lotfi_baghli | 0:7f9517ce9e71 | 40 | |
lotfi_baghli | 0:7f9517ce9e71 | 41 | int main() { |
lotfi_baghli | 0:7f9517ce9e71 | 42 | Base::add_rpc_class<DigitalOut>(); |
lotfi_baghli | 0:7f9517ce9e71 | 43 | EthernetErr ethErr = eth.setup(); |
lotfi_baghli | 0:7f9517ce9e71 | 44 | if (ethErr) { |
lotfi_baghli | 0:7f9517ce9e71 | 45 | printf("Error %d in setup.\n", ethErr); |
lotfi_baghli | 0:7f9517ce9e71 | 46 | return -1; |
lotfi_baghli | 0:7f9517ce9e71 | 47 | } |
lotfi_baghli | 0:7f9517ce9e71 | 48 | printf("\r\nSetup OK\r\n"); |
lotfi_baghli | 0:7f9517ce9e71 | 49 | |
lotfi_baghli | 0:7f9517ce9e71 | 50 | FSHandler::mount("/webfs", "/files"); //Mount /webfs path on /files web path |
lotfi_baghli | 0:7f9517ce9e71 | 51 | FSHandler::mount("/webfs", "/"); //Mount /webfs path on web root path |
lotfi_baghli | 0:7f9517ce9e71 | 52 | |
lotfi_baghli | 0:7f9517ce9e71 | 53 | //svr.addHandler<SimpleHandler>("/hello"); |
lotfi_baghli | 0:7f9517ce9e71 | 54 | svr.addHandler<RPCHandler>("/rpc"); |
lotfi_baghli | 0:7f9517ce9e71 | 55 | svr.addHandler<FSHandler>("/files"); |
lotfi_baghli | 0:7f9517ce9e71 | 56 | svr.addHandler<FSHandler>("/"); //Default handler |
lotfi_baghli | 0:7f9517ce9e71 | 57 | //Example : Access to mbed.htm : http://a.b.c.d/mbed.htm or http://a.b.c.d/files/mbed.htm |
lotfi_baghli | 0:7f9517ce9e71 | 58 | svr.bind(80); |
lotfi_baghli | 0:7f9517ce9e71 | 59 | |
lotfi_baghli | 0:7f9517ce9e71 | 60 | printf("Listening...\n"); |
lotfi_baghli | 0:7f9517ce9e71 | 61 | |
lotfi_baghli | 0:7f9517ce9e71 | 62 | Timer tm; |
lotfi_baghli | 0:7f9517ce9e71 | 63 | tm.start(); |
lotfi_baghli | 0:7f9517ce9e71 | 64 | //Listen indefinitely |
lotfi_baghli | 0:7f9517ce9e71 | 65 | while (1) { |
lotfi_baghli | 0:7f9517ce9e71 | 66 | Net::poll(); |
lotfi_baghli | 0:7f9517ce9e71 | 67 | if (tm.read()>.5) { |
lotfi_baghli | 0:7f9517ce9e71 | 68 | led1=!led1; //Show that we are alive |
lotfi_baghli | 0:7f9517ce9e71 | 69 | tm.start(); |
lotfi_baghli | 0:7f9517ce9e71 | 70 | } |
lotfi_baghli | 0:7f9517ce9e71 | 71 | } |
lotfi_baghli | 0:7f9517ce9e71 | 72 | } |