Controlling X10 (CTX35) from PHP

Pop your questions regarding Home automation software here.....
Post Reply
User avatar
ludom
Member
Member
Posts: 90
Joined: Fri Jun 11, 2010 12:30 am
Location: Netherlands

Controlling X10 (CTX35) from PHP

Post 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 :D
Home-brewed HA system based on Linux, PHP5, MySQL and Beanstalkd
User avatar
Snelvuur
Forum Moderator
Forum Moderator
Posts: 3156
Joined: Fri Apr 06, 2007 11:01 pm
Location: Netherlands
Contact:

Re: Controlling X10 (CTX35) from PHP

Post 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.
// Erik (binkey.nl)
User avatar
ludom
Member
Member
Posts: 90
Joined: Fri Jun 11, 2010 12:30 am
Location: Netherlands

Re: Controlling X10 (CTX35) from PHP

Post 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?
Home-brewed HA system based on Linux, PHP5, MySQL and Beanstalkd
airox
Member
Member
Posts: 214
Joined: Sat May 15, 2010 10:42 pm

Re: Controlling X10 (CTX35) from PHP

Post 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
poegje
Starting Member
Starting Member
Posts: 25
Joined: Mon Oct 29, 2007 10:19 pm
Location: Netherlands
Contact:

Re: Controlling X10 (CTX35) from PHP

Post 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.
poegje
Starting Member
Starting Member
Posts: 25
Joined: Mon Oct 29, 2007 10:19 pm
Location: Netherlands
Contact:

Re: Controlling X10 (CTX35) from PHP

Post 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?
Alexander
Global Moderator
Global Moderator
Posts: 1532
Joined: Sat Mar 10, 2007 11:19 pm
Location: Netherlands

Re: Controlling X10 (CTX35) from PHP

Post 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.
Alexander
poegje
Starting Member
Starting Member
Posts: 25
Joined: Mon Oct 29, 2007 10:19 pm
Location: Netherlands
Contact:

Re: Controlling X10 (CTX35) from PHP

Post 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 :)
User avatar
ludom
Member
Member
Posts: 90
Joined: Fri Jun 11, 2010 12:30 am
Location: Netherlands

Re: Controlling X10 (CTX35) from PHP

Post 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?
Home-brewed HA system based on Linux, PHP5, MySQL and Beanstalkd
Digit
Global Moderator
Global Moderator
Posts: 3388
Joined: Sat Mar 25, 2006 10:23 am
Location: Netherlands
Contact:

Re: Controlling X10 (CTX35) from PHP

Post by Digit »

Lempens
Member
Member
Posts: 265
Joined: Wed Dec 12, 2007 1:24 am
Location: Netherlands

Re: Controlling X10 (CTX35) from PHP

Post 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.
User avatar
ludom
Member
Member
Posts: 90
Joined: Fri Jun 11, 2010 12:30 am
Location: Netherlands

Re: Controlling X10 (CTX35) from PHP

Post 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?
Home-brewed HA system based on Linux, PHP5, MySQL and Beanstalkd
Bwired
Administrator
Administrator
Posts: 4704
Joined: Sat Mar 25, 2006 1:07 am
Location: Netherlands
Contact:

Re: Controlling X10 (CTX35) from PHP

Post 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
http://www.bwired.nl Online Home, Domotica, Home Automation. Weblog. http://blog.bwired.nl
User avatar
ludom
Member
Member
Posts: 90
Joined: Fri Jun 11, 2010 12:30 am
Location: Netherlands

Re: Controlling X10 (CTX35) from PHP

Post 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?
Home-brewed HA system based on Linux, PHP5, MySQL and Beanstalkd
User avatar
ludom
Member
Member
Posts: 90
Joined: Fri Jun 11, 2010 12:30 am
Location: Netherlands

Re: Controlling X10 (CTX35) from PHP

Post 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!
Home-brewed HA system based on Linux, PHP5, MySQL and Beanstalkd
Post Reply

Return to “Questions & Discussions Forum”