Step 5Software
This lighting project is no different, although it does represent my first attempts at using web services.
For the web services I've used Apache 2.x and the Soap::Lite module for perl, to actually talk serial to the DMX controller, I have used the perl module Device::SerialPort.
The whole lot runs under Redhat Linux I call the web services from my actual home automation application like this: (note this is a part of a much larger program)
# Lights off if no movement for ten minutes and movement more recently in the hallway
#
if ( $epoch - $in11_lastmove > 600 && $in11_lastmove < $in23_lastmove && $kitchenlights == 1 ) {
&send_lights_soap(1,0) ;
$kitchenlights = 0 ;
}
The actual subroutine being called is here:
sub send_lights_soap {
$soap_response = SOAP::Lite
-> uri('http://192.168.101.172/Lights')
-> proxy('http://192.168.101.172/cgi-bin/lights')
-> send( "$_[0]" , "$_[1]" ) ;
$res = $soap_response->result ;
}
And as this is a web service, the actual serial interface and web service code resides on another machine on my network, the web service code looks like this:
#!/usr/bin/perl -w
use SOAP::Transport::HTTP;
SOAP::Transport::HTTP::CGI
-> dispatch_to('Lights')
-> handle;
# Call as -> uri('http://192.168.101.172/Lights')
# -> proxy('http://192.168.101.172/cgi-bin/lights')
# -> send("" , "")
package Lights;
sub send {
use Device::SerialPort ;
my $port = Device::SerialPort->new("/dev/ttyS0") ;
$port->baudrate(9600) ; $port->parity("none") ;
$port->handshake("none") ; $port->databits(8) ;
$port->stopbits(1) ; $port->read_char_time(0) ;
$port->read_const_time(1) ;
my ($class , $channel , $intensity ) = @_;
# send data out
$port->write( pack "C", $channel ) ;
$port->write( pack "C", $intensity ) ;
sleep(1) ;
$port->close() ;
return "Done! I used $class with chn $channel and inten $intensity";
}
Fairly simple code, I'm sure you'll agree, and best of all, because it runs webservices, I can spread these nodes out across my network and call them easily.
Additionally you may have noticed that like most people I've RFC1918 addressed my network, but with a suitable NAT rule, these services can easily be called from anywhere with an internet connection, meaning that I can control my lighting, heating etc.. from anywhere (even a GPRS or 3G phone!)
| « Previous Step | Download PDFView All Steps | Next Step » |












































one suggestion i have is for your manual system. you could go with a "manual override" routine, where you would have two buttons on each wall plate. one for shutting off the lights and one for turning them on at a pre-determined intensity.
you would have to run each control to your computer, which would be quite an ordeal given your setup, but with a good end result. you could simply push a button to turn off the lights when going to sleep, and if the system ever had a malfuntion in movement detection, an "on" button would be the perfect backup.