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
Revision 0:7f9517ce9e71, committed 2011-08-27
- Comitter:
- lotfi_baghli
- Date:
- Sat Aug 27 16:45:11 2011 +0000
- Commit message:
- V0.21
Changed in this revision
diff -r 000000000000 -r 7f9517ce9e71 EthernetNetIf.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EthernetNetIf.lib Sat Aug 27 16:45:11 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/donatien/code/EthernetNetIf/#bc7df6da7589
diff -r 000000000000 -r 7f9517ce9e71 HTTPClient.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HTTPClient.lib Sat Aug 27 16:45:11 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/donatien/code/HTTPClient/#d0be6af2d1db
diff -r 000000000000 -r 7f9517ce9e71 HTTPServer.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HTTPServer.lib Sat Aug 27 16:45:11 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/donatien/code/HTTPServer/#d753966e4d97
diff -r 000000000000 -r 7f9517ce9e71 RPCInterface.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RPCInterface.lib Sat Aug 27 16:45:11 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/MichaelW/code/RPCInterface/#a9e2c45097c8
diff -r 000000000000 -r 7f9517ce9e71 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Aug 27 16:45:11 2011 +0000 @@ -0,0 +1,72 @@ +#include "mbed.h" +#include "EthernetNetIf.h" +//#include "HTTPClient.h" +#include "HTTPServer.h" +#include "RPCFunction.h" +#include "x10rf.h" + +EthernetNetIf eth( + IpAddr(192,168,1,25), //IP Address + IpAddr(255,255,255,0), //Network Mask + IpAddr(192,168,1,1), //Gateway + IpAddr(192,168,1,1) //DNS +); +//HTTPClient http; +HTTPServer svr; + +DigitalOut led1(LED1, "led1"); +DigitalOut led2(LED2, "led2"); +DigitalOut led3(LED3, "led3"); +DigitalOut led4(LED4, "led4"); + +LocalFileSystem fs("webfs"); + +//Create a function of the required format +void rpcX10rf(char * input, char * output); +//Attach it to an RPC object +RPCFunction rpc_foo(&rpcX10rf, "rpcX10rf"); + +void rpcX10rf(char * input, char * output) { +char houseCode; +short int numberCode, action; + printf("%s\r\n", input); + sscanf(input, " %c,%d,%d", &houseCode, &numberCode, &action); + printf("%c, %d,%d\r\n", houseCode, numberCode, action); + // calls the X10RFLib + SendX10rf( houseCode, numberCode, action); + + //nothing to send back - sprintf(output, "%i, %i", x, y ); +} + +int main() { + Base::add_rpc_class<DigitalOut>(); + EthernetErr ethErr = eth.setup(); + if (ethErr) { + printf("Error %d in setup.\n", ethErr); + return -1; + } + printf("\r\nSetup OK\r\n"); + + FSHandler::mount("/webfs", "/files"); //Mount /webfs path on /files web path + FSHandler::mount("/webfs", "/"); //Mount /webfs path on web root path + + //svr.addHandler<SimpleHandler>("/hello"); + svr.addHandler<RPCHandler>("/rpc"); + svr.addHandler<FSHandler>("/files"); + svr.addHandler<FSHandler>("/"); //Default handler + //Example : Access to mbed.htm : http://a.b.c.d/mbed.htm or http://a.b.c.d/files/mbed.htm + svr.bind(80); + + printf("Listening...\n"); + + Timer tm; + tm.start(); + //Listen indefinitely + while (1) { + Net::poll(); + if (tm.read()>.5) { + led1=!led1; //Show that we are alive + tm.start(); + } + } +} \ No newline at end of file
diff -r 000000000000 -r 7f9517ce9e71 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat Aug 27 16:45:11 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912
diff -r 000000000000 -r 7f9517ce9e71 x10rf.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/x10rf.cpp Sat Aug 27 16:45:11 2011 +0000 @@ -0,0 +1,155 @@ +// Interface Lib to X10 RF transmiter + +#include "mbed.h" + +DigitalOut led_2(LED2, "led2"); +DigitalOut led_3(LED3, "led3"); + +DigitalOut RF_TX(p19); +DigitalOut RF_Alim(p18); + +void SendX10RF_bit(unsigned int databit); +void SendX10byte(unsigned int data8); +void SendX10Cmd(unsigned int data); +void SendX10RF(); + + +//----------------------------------------------------------------------------- +// http://idobartana.com/hakb/x10rf.htm +// ftp://ftp.x10.com/pub/manuals/cm17a_protocol.txt +unsigned int EncodeX10rf(char houseCode, int numberCode, int action) +{// action : 1 : On, 0 : Off, 2 : BRIGHT , 3 : DIM +unsigned int order, add; + switch (houseCode) + { + case 'A' : order= 0x6000; break; + case 'B' : order= 0xE000; break; + case 'C' : order= 0x2000; break; + case 'D' : order= 0xA000; break; + case 'E' : order= 0x1000; break; + case 'F' : order= 0x9000; break; + case 'G' : order= 0x5000; break; + case 'H' : order= 0xD000; break; + case 'I' : order= 0x7000; break; + case 'J' : order= 0xF000; break; + case 'K' : order= 0x3000; break; + case 'L' : order= 0xB000; break; + case 'M' : order= 0x0000; break; + case 'N' : order= 0x8000; break; + case 'O' : order= 0x4000; break; + case 'P' : order= 0xC000; break; + } + switch (numberCode) + { + case 1 : add= 0x0000; break; + case 2 : add= 0x0010; break; + case 3 : add= 0x0008; break; + case 4 : add= 0x0018; break; + case 5 : add= 0x0040; break; + case 6 : add= 0x0050; break; + case 7 : add= 0x0048; break; + case 8 : add= 0x0058; break; + case 9 : add= 0x0400; break; + case 10: add= 0x0410; break; + case 11: add= 0x0408; break; + case 12: add= 0x0418; break; + case 13: add= 0x0440; break; + case 14: add= 0x0450; break; + case 15: add= 0x0448; break; + case 16: add= 0x0458; break; + } + order |= add; + if (action==0) order |= 0x0020; + return order; +} +//----------------------------------------------------------------------------- +void SendX10rf(char houseCode, int numberCode, int action) +{ // action : 1 : On, 0 : Off, 2 : BRIGHT , 3 : DIM + printf( "h=%c U=%d R=%d Order=%X\r\n", houseCode, numberCode, action, EncodeX10rf(houseCode, numberCode, action)); +// SendX10Cmd(0x6010); // A2 ON +// SendX10Cmd(0x6000); // A1 ON + SendX10Cmd( EncodeX10rf(houseCode, numberCode, action)); +} +//----------------------------------------------------------------------------- +void SendX10RF_bit(unsigned int databit) +{ + // envoi un 1 + RF_TX=1; + wait_us(560); // 0.56 ms + RF_TX=0; + wait_us(560); // 0.56 ms + // si c'est un 0 + if (!databit) wait_us(1120); // 0.56*2 = 1.12 ms si un zero +} +//----------------------------------------------------------------------------- +void SendX10byte(unsigned int data8) +{ +unsigned int j, k; + for (j=0; j<8; j++) + { + k=(data8 & 0x0080 )==0x0080; + SendX10RF_bit(k); + data8=data8 << 1; + } +} +//----------------------------------------------------------------------------- +void SendX10Cmd(unsigned int data) +{ +unsigned int Cmd8; + RF_Alim=1; // Alimente le transmetteur RE8=ON +// wait_ms(20); // >20 ms + wait_ms(10); // >10 ms + wait_ms(10); // >10 ms +// en-tête + RF_TX=1; + wait_us(8960); // 8.96 ms + RF_TX=0; + wait_us(4500); // 4.5 ms + Cmd8=data>>8; // send les Hi + SendX10byte(~Cmd8); + SendX10byte(Cmd8); + Cmd8=(data) & 0xFF; // send les Low + SendX10byte(~Cmd8); + SendX10byte(Cmd8); + SendX10RF_bit(1); // 1 à la fin ?? + wait_us(1120); // 1.12 ms + RF_Alim=0; // Eteint transmetteur RE8=OFF +} +//----------------------------------------------------------------------------- +void SendX10RF() +{ +// SendX10Cmd(0x6000); // A1 ON +// SendX10Cmd(0x6020); // A1 OFF + SendX10Cmd(0x6010); // A2 ON +// SendX10Cmd(0x6030); // A2 OFF +// SendX10Cmd(0x6090); // A2 DIM+ +// SendX10Cmd(0x60B0); // A2 DIM- + +//http://idobartana.com/hakb/x10rf.htm +//10101111 11011101 01010101 11011111 10101101 01010101 <-A1 OFF cmd (as seen on RF, RIGHT bit first !) +//00000100 11111011 00000110 11111001 A1 OFF (as RIGHT bit first !) +// byte 1 byte 2 byte 3 byte 4 +//bit function +//0 always 0 +//1 always 0 +//2 always 0 +//3 bit B1 of unit number +//4 bit B0 of unit number +//5 1 for OFF command. DIM B2 ON/OFF B0 B1 <--(unit number -1= 0bB2B1B0 ) +//6 bit B2 of unit number ------------------>| +//7 1 for DIM (if bit 5=1) or BRIGHT (if bit 5=0) command + +// à l'envers aussi mais bytes inversées +//A- 00001 ON +//00032: 11111001 00000110 11111111 00000000 0x6000 +//A- 00001 OFF +//00032: 11111001 00000110 11111011 00000100 0x6020 +//A- 00002 ON +//00032: 11111001 00000110 11110111 00001000 0x6080 +//A- 00002 OFF +//00032: 11111001 00000110 11110011 00001100 0x60C0 +//A- 00002 DIM+ +//00032: 11111001 00000110 11110111 00001000 0x6090 +//http://camelspit.org/modified-x10-rf-transmitter/ +} +//---------------------------------------------------------------------
diff -r 000000000000 -r 7f9517ce9e71 x10rf.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/x10rf.h Sat Aug 27 16:45:11 2011 +0000 @@ -0,0 +1,4 @@ +// Interface Lib to X10 RF transmiter + +void SendX10rf(char houseCode, int numberCode, int action); + // action : 1 : On, 0 : Off, 2 : BRIGHT , 3 : DIM