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 : /media/uploads/lotfi_baghli/mbed_eth1.jpg

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 :

/media/uploads/lotfi_baghli/x10webserver.png

As always with mbed systems, there are few electronic parts added : /media/uploads/lotfi_baghli/x10mbedserver.png


Report

10 comments on X10 server:

06 Sep 2011

Lotfi, What is this 318MHz transmitter you are refering to?

Regards, ...kevin

06 Sep 2011

Dear Kevin,

Sorry it is a 315 MHz transmitter from sparkfun : http://www.sparkfun.com/products/10535

Best

19 Dec 2011

Have you tried the dim function? and what range do you get?

Also which X10 wireless module are you using for a receiver? Are all of them working at 315Mhz?

19 Dec 2011

jim hamblen wrote:

Have you tried the dim function? and what range do you get?

Also which X10 wireless module are you using for a receiver? Are all of them working at 315Mhz?

receiver is TM751 module but it work with any X10 RF receiver Mine are US ones so the freq is 315 MHz European ones are 433 MHz Have a look at ido bartana website : http://www.idobartana.com/hakb/index.htm and my site : http://www.baghli.com/dspic_x10rf.php

I didn't programmed the dim function but I am quite sure it will work. The range depends on your emitter... I have about 10 m range with a wrapping wire used as antenna ;-)

29 Jan 2012

Have you tried to receive the wireless signals from the X10 motion sensors? Spakrfun has a 315Mhz receive module that looks like it might work - assuming that is also 315Mhz.

29 Jan 2012

jim hamblen wrote:

Have you tried to receive the wireless signals from the X10 motion sensors? Spakrfun has a 315Mhz receive module that looks like it might work - assuming that is also 315Mhz.

Non I don't have a motion sensor, but I have unused 315 MHz receivers, I will try to receive humidity and temperature sensor (those you found in meteo stations). I am busy at the moment and will try this in some weeks inchaAllah. Best regards

03 Feb 2012

Just got my Sparkfun 315Mhz RF chip Got it to work!!

had these issues:

Range with a 6 inch wire jumper antenna was only around 8 inches on my setup. Notice some people claim X10 carrier is 310Mhz and the Sparkfun RF module is 315Mhz, so that might be part of it. Will work perhaps once every 5 times at a distance of 3 ft. They had a trim adjust on the receiver module and someone says you can use it to adjust the carrier a bit, but I don't see one on the transmitter. The one I got today from Sparkfun looks a bit different than the one in your photo.

I got A1 to turn on and off and I hear it click OK, but when I then tried to turn an A2 lamp module on and off, it dims and brightens A2 instead with order =6010 and 6030 on the debug printf Comment at bottom of code shows a different number for A2 on and off (6080 and 60C0) - maybe a minor bug in the encode function case statements? A couple of the X10 bit protocol links in the comments seem to be dead now - so still confused about which bits might be swapped? I suppose the good news on the first try is that I can confirm DIM will work.

22 Feb 2012

I looked up the FCC ID number on the X10 module and confirmed that it is 310Mhz.

I looked around for 310Mhz modules but they are hard to find. I found one option, buy a 310Mhz SAW and replace the one on the board. But it looks kind of tough to rework the tiny 315Mhz module and replace it.

16 May 2012

Hi Lotfi Baghli. I know nothing about java language, but I can see in the program by clicking on each button it send a RPC request to mbed. It would be possible to make from the variation of some variable in the program on the mbed (for example the value of an analog input) the mbed update and display this value on the website?. regards

22 Jun 2012

Dario Delvalle wrote:

Hi Lotfi Baghli. I know nothing about java language, but I can see in the program by clicking on each button it send a RPC request to mbed. It would be possible to make from the variation of some variable in the program on the mbed (for example the value of an analog input) the mbed update and display this value on the website?. regards

It is simple, just follow the samples, but it is in C language Regards

Please login to post comments.