X10 server
I would like to control my X10 stuff (3 devices) from a web browser.
The ethernet part
This is my first essay to use the mbed with ethernet.
It is straight forward, compared to a PIC24F + ENC2860 + magicjack...
The main idea is to get rid of hardware connexion problems (the magicjack). So, in a first try, use an RJ45 cable that you cut : http://mbed.org/forum/mbed/topic/1239/?page=1#comment-13519
I found the information of the norm T568A on : http://upload.wikimedia.org/wikipedia/commons/thumb/c/c4/Wire_white_green_stripe.svg/60px-Wire_white_green_stripe.svg.png
It looks like :
I tried with the excellent httpclient to send some data to a server of mine, it works !
Then the server is implemented using httpserver : unfortunately, the example http://mbed.org/cookbook/HTTP-Server?action=view&revision=244 has a missing .htm file, but I found one on : http://mbed.org/users/jnesystech/notebook/ch4_6/
This implement a simple web page, to be but on the root of the mbed, that has a toogles button which power the LED2 of the mbed.
Then The 3 Led, in perspective to 3 X10 devices
main.c
#include "mbed.h" #include "EthernetNetIf.h" //#include "HTTPClient.h" #include "HTTPServer.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 ); HTTPServer svr; DigitalOut myled(LED1); DigitalOut led1(LED1, "led1"); DigitalOut led2(LED2, "led2"); DigitalOut led3(LED3, "led3"); DigitalOut led4(LED4, "led4"); LocalFileSystem fs("webfs"); 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) { myled=!myled; //Show that we are alive tm.start(); } } }
index.htm
<html> <head> <title> Home Server </title> </head> <body> <center> <h1>Home Server</h1> <h4>Designed by Lotfi - v0.2</h4> </center> <script language="javascript"> var Button = 0; var X10DeviceState=new Array(3); //var X10DeviceChannel= new Array(1,2,9); // X10 Channel var X10DeviceChannel= new Array(2,3,4); // LED function X10_On(device) { var elt = document.getElementById( "FormButton"+X10DeviceChannel[device]) if (X10DeviceState[device]==0) { X10DeviceState[device] = 1; elt.value = "Off"; } else { X10DeviceState[device] = 0; elt.value = "On"; } // alert(X10DeviceState[device]); var req = new XMLHttpRequest(); //var cmd= "http://192.168.1.25/rpc/led" + X10DeviceChannel[device] +"/write+" + X10DeviceState[device]; // this is my mbed addy on my local network, so I can also play with the file from my EditPlus editor var cmd= "http://" + location.host + "/rpc/led" + X10DeviceChannel[device] +"/write+" + X10DeviceState[device]; // alert(cmd); req.open("GET", cmd, true); req.send(""); } </script> <form name="Form" action="#"> LED2: <input type="button" value="On" id="FormButton2" onclick="X10_On(0)"> LED3: <input type="button" value="On" id="FormButton3" onclick="X10_On(1)"> LED4: <input type="button" value="On" id="FormButton4" onclick="X10_On(2)"> <br> </form> </body> </html>
see also how to add RPCFunction :
The X10 part
Pay attention that this is RF X10 signals that we will send thanks to a 315 MHz transmitter :
The V0.21 is a working one
Import programWeatherRx
Web Server and send X10 RF orders to X10 RF transceivers Switch On/Off Appliance No weather Rx at the moment...
You must add the htm file
index.htm
<html> <head> <title> Home Server </title> </head> <body> <center> <h1>Home Server</h1> <h4>Designed by Lotfi - v0.21</h4> </center> <script language="javascript"> //var SRVAddy = "192.168.1.25"; var SRVAddy = location.host; var Button = 0; var X10DeviceState=new Array(3); //var X10DeviceChannel= new Array(1,2,9); // X10 Channel var X10DeviceChannel= new Array(2,3,4); // LED function X10fake_On(device) { var elt = document.getElementById( "FormButton"+X10DeviceChannel[device]) if (X10DeviceState[device]==0) { X10DeviceState[device] = 1; elt.value = "Off"; } else { X10DeviceState[device] = 0; elt.value = "On"; } // alert(X10DeviceState[device]); var req = new XMLHttpRequest(); var cmd= "http://" + SRVAddy + "/rpc/led" + X10DeviceChannel[device] +"/write+" + X10DeviceState[device]; // alert(cmd); req.open("GET", cmd, true); req.send(""); } function X10_On(device) { var elt = document.getElementById( "FormButtonX10" ) if (X10DeviceState[device]==0) { X10DeviceState[device] = 1; elt.value = "Off"; } else { X10DeviceState[device] = 0; elt.value = "On"; } // alert(X10DeviceState[device]); var req = new XMLHttpRequest(); var cmd= "http://" + SRVAddy + "/rpc/rpcX10rf/run A " + X10DeviceChannel[device] +" " + X10DeviceState[device]; // alert(cmd); req.open("GET", cmd, true); req.send(""); } function X10rf(order) { var req = new XMLHttpRequest(); var cmd= "http://" + SRVAddy + "/rpc/rpcX10rf/run " + order; // alert(cmd); req.open("GET", cmd, true); req.send(""); } </script> <form name="Form" action="#"> LED2: <input type="button" value="On" id="FormButton2" onclick="X10fake_On(0)"> LED3: <input type="button" value="On" id="FormButton3" onclick="X10fake_On(1)"> LED4: <input type="button" value="On" id="FormButton4" onclick="X10fake_On(2)"> <br> <br> old: <input type="button" value="On" id="FormButtonX10" onclick="X10_On(0)"> <br> <br> <br> X10 Lampe Chambre : <input type="button" value="On" onclick="X10rf('A,1,1')"> <input type="button" value="Off" onclick="X10rf('A,1,0')"> <br> <br> X10 Lampe Chevet Chambre : <input type="button" value="On" onclick="X10rf('A,2,1')"> <input type="button" value="Off" onclick="X10rf('A,2,0')"> <br> <br> X10 Pompe à eau: <input type="button" value="On" onclick="X10rf('A,9,1')"> <input type="button" value="Off" onclick="X10rf('A,9,0')"> <br> </form> </body> </html>
The page gives the following output :
As always with mbed systems, there are few electronic parts added :
11 comments on X10 server:
Please log in to post comments.
Lotfi, What is this 318MHz transmitter you are refering to?
Regards, ...kevin