3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Automated Lighting Using DMX and Perl

Step 5Software

Software
All of my other home automation (security, heating, power, cctv etc..) is written (badly in parts) using perl.
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 StepDownload PDFView All StepsNext Step »
1 comment
Oct 10, 2009. 2:26 AMadrumsolo4u says:
this instrucable is great!

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.

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
17
Followers
4
Author:toastyboy
I'm fairly mint most of the time I'm a firm advocate of treating people how you would like to be treated yourself. People are always nice to me, so it must work! Try it!