NETLANTIS NEWS/BLOG

Saturday, May 7, 2011

[Home Automation] Turning ON/OFF your Cambridge Audio Azur 840A (Version 2)

So you have a Cambridge Audio Amplifier (or any other product with a serial port) and a null-modem cable and want to be able to control your amplifier from a Linux PC (a web page or CLI). Here's a quick HOW TO...

Say you've connected it to /dev/ttyS0.

Step 1 - allowing anonymous/apache/everyone to write to /dev/ttyS0
echo "/bin/chmod 666 /dev/ttyS0" >> /etc/rc.local

Step 2 - PHP function to start/stop the amplifier
function cambridge_pstate($w) {
$line="";
$fp=fopen("/dev/ttyS0","r+");
if($w=="ON") fputs($fp,"#1,11,1\r\n");
if($w=="OFF") fputs($fp,"#1,11,0\r\n");
while($line=fgets($fp,16)) if($line!="") break;
fclose($fp);
if(substr($line,0,2)=="#4") return true;
else return false;
}

Step 3 - Use the fonction in a PHP page
if(cambridge_pstate("ON")) echo "Starting the amplifier...";
else echo "Could not start the amplifier...";

... and obviously, the opposite :
if(cambridge_pstate("OFF")) echo "Stopping the amplifier...";
else echo "Could not start the amplifier...";

Sunday, May 1, 2011

So much for "intelligent" ads :)

Nice one...

CTR must have been quite low on these ads :)