Page 1 of 1
Controlling X10 (CTX35) from PHP
Posted: Tue Jun 15, 2010 1:19 pm
by ludom
Hi There,
I am very new in the domotica world, and also new with the X10 protocol.
I have plans to write my own HA interface with PHP, before i will start to code my system I have some questions about the X10 integration:
- How can i integrate X10 into my webserver so that i can send X10 signals to a X10 device (via my Xanura CTX35) from a PHP webpage?
- How can i watch my CTX35 for incomming X10 signals from my devices and send these signals into my PHP system so that i can link an event with it?
As webserver i like to use Windows (with IIS or apache) or Linux, PHP5 and MySQL.
I hope somebody can advise me with this

Re: Controlling X10 (CTX35) from PHP
Posted: Wed Jun 16, 2010 9:50 am
by Snelvuur
well there is tons of information out there on the web on how to do just that. The ctx has a protocol which is found on the web too, same for x10 devices.
All depends how you want to build it, if you need a daemon you might end up with a command line php script with a loop of some kind.
Re: Controlling X10 (CTX35) from PHP
Posted: Wed Jun 16, 2010 11:48 am
by ludom
I know that there are tons of information on the net, but i have to know how i can build a good working deamon, that can send and receive all X10 data to and from the CTX35.
It can be done with a loop that runs over and over, but it would be nicer if it was possible via the "PUSH" meganism.
Is there anybody that has also written their HA system in PHP / ASP?
Re: Controlling X10 (CTX35) from PHP
Posted: Wed Jun 16, 2010 11:15 pm
by airox
My ha systemen is completely build in php with one daemon for zwave and one for rfxcom receiver. So fire away those questions.
Grt, airox
Sent from my iPad
Re: Controlling X10 (CTX35) from PHP
Posted: Thu Jun 17, 2010 4:41 pm
by poegje
ludom wrote:I know that there are tons of information on the net, but i have to know how i can build a good working deamon, that can send and receive all X10 data to and from the CTX35.
It can be done with a loop that runs over and over, but it would be nicer if it was possible via the "PUSH" meganism.
Is there anybody that has also written their HA system in PHP / ASP?
I'm also working on a HA system in PHP with a CTX35 amongst others.
A push mechanism with a CTX35 is difficult i think because you have to keep polling it. You would have to have a daemon looping and polling every second.
I have something working but must now program some mechanism to process to signals and also to send signals back. I'm thinking about a few scripts that interact with each other in some way (maybe mysql or network ports).
A looping PHP-script can be done, just make sure it doesn't time-out or eat your cpu-time
I'm interested in your ideas.
Re: Controlling X10 (CTX35) from PHP
Posted: Thu Jun 17, 2010 4:44 pm
by poegje
airox wrote:My ha systemen is completely build in php with one daemon for zwave and one for rfxcom receiver. So fire away those questions.
How do you process the incoming signals?
Are you using a database?
Re: Controlling X10 (CTX35) from PHP
Posted: Thu Jun 17, 2010 4:48 pm
by Alexander
poegje wrote:A looping PHP-script can be done, just make sure it doesn't time-out or eat your cpu-time

I don't understand this. You need to have a daemon that has a constant connection open with the CTX to not miss any packets. So eventhough you would use scripts that loop, you still could loose a packet. And ofcourse webserver pages aren't the realtime way of retreiving data.
Re: Controlling X10 (CTX35) from PHP
Posted: Thu Jun 17, 2010 5:07 pm
by poegje
Alexander wrote:poegje wrote:A looping PHP-script can be done, just make sure it doesn't time-out or eat your cpu-time

I don't understand this. You need to have a daemon that has a constant connection open with the CTX to not miss any packets. So eventhough you would use scripts that loop, you still could loose a packet. And ofcourse webserver pages aren't the realtime way of retreiving data.
The PHP-script is run from the console in this form: php -f scriptname.php
If you make sure the script keeps checking/polling the serial port it never misses anything. Also the CTX35 has an internal buffer storing events until you read them.
So the script isn't started from a webbrowser. The webserver doesn't do anything for the daemon. It's pure PHP doing the work stand-alone without output to a browser.
Hope i made it clear to you

Re: Controlling X10 (CTX35) from PHP
Posted: Fri Jun 18, 2010 11:13 am
by ludom
Thanks for all replies.
I have found a website where sombody (from the netherlands) has made kind of daemon class for PHP
http://kevin.vanzonneveld.net/techblog/ ... ns_in_php/
It looks good, i will try this week to buid a simple daemon that will run over and over the whole day long.
Is this something that i can use to write my daemon?
Then i have also found a PHP class for sending serial commands via a serial port
http://www.phpclasses.org/package/3679- ... -port.html
Can anybody tell my what raw commands i have to send over the X10 lines?
Re: Controlling X10 (CTX35) from PHP
Posted: Fri Jun 18, 2010 6:04 pm
by Digit
Re: Controlling X10 (CTX35) from PHP
Posted: Wed Jun 23, 2010 5:09 pm
by Lempens
I'm have a PMIX35 Webservice (VB.NET) , you can post data to the webservice and the PMIX35 sends it.
It also receives the data, which you can call back in your program.
The Windows Webservice works with almost every language.
I received my CTX35 today, and I will try to rewrite it.
Re: Controlling X10 (CTX35) from PHP
Posted: Wed Jul 14, 2010 1:15 pm
by ludom
I'm writing my own driver for the CTX35 now, and i stumbling against the checksum that i have to generate for the CTX35.
I tried to wrote a simple function for this but on this moment i can't get this work;
Code: Select all
function checksum($command)
{
$input = '$>28001'.$command;
$count = strlen($input);
$asc = '';
$i = 0;
while($i < $count)
{
$asc .= ord(substr($input, $i, 1));
$i++;
}
$output = substr($asc, -2, 2);
return dechex($output);
}
Is there somebody that can help me with this?
Re: Controlling X10 (CTX35) from PHP
Posted: Wed Jul 14, 2010 4:21 pm
by Bwired
Sample VB function Marmitek CTX35
Code: Select all
Private Function CheckSum(x)
Dim q, l, i
x = "$>28001" + x
l = Len(x)
For i = 1 To l
q = q + Asc(Mid$(x, i, 1))
Next i
ChSm = Right$(Hex$(q), 2)
End Function
Re: Controlling X10 (CTX35) from PHP
Posted: Wed Jul 14, 2010 5:12 pm
by ludom
Pieter, i reviewed your function earlier today and i used it to wrote my PHP version of it, but my function won't work right on this moment.
Does anybody know how i can verify if a generated checksum if it's right?
Re: Controlling X10 (CTX35) from PHP
Posted: Thu Jul 15, 2010 10:16 am
by ludom
I have a working function now!
Code: Select all
function checksum($command)
{
$input = '$>28001'.$command;
$i = 0;
while($i < strlen($input))
{
$asc = $asc + ord(substr($input, $i, 1));
$i++;
}
$output = dechex($asc);
$output = substr($output, -2, 2);
return $output.'#';
}
I was stupid! i had to sum the ORD output all togheter in the WHILE loop, now it's working fine!