We were working towards a neater version, here:
http://forum.linuxmce.org/index.php?topic=3573.0I didn't really have time though.
Here is what I use right now (it's VERY ugly - I don't know perl!):
# Category=Pluto
#
#@ Connection with Pluto DCE Router via TCP port localhost:3450 (mh.ini -> pluto_DCE_router).
#
use strict;
$restartTimer = new Timer;
##############################################################################
sub connect_lmce {
print_log "Configuring sockets";
$pluto_device_event_receiver = new Socket_Item(undef, undef, '192.168.1.1:3450','device_event_receiver','tcp','record');
$pluto_device_command_sender = new Socket_Item(undef, undef, '192.168.1.1:3450','device_command_sender','tcp','record');
print_log "Closing sockets if any left open";
if (active_now $pluto_device_event_receiver) {stop $pluto_device_event_receiver;}
if (active_now $pluto_device_command_sender) {stop $pluto_device_command_sender;}
print_log "Open and setup new sockets";
start $pluto_device_event_receiver;
set $pluto_device_event_receiver "COMMAND 78";
start $pluto_device_command_sender;
set $pluto_device_command_sender "EVENT 78";
set $pluto_device_command_sender "PLAIN_TEXT";
#MESSAGET 21
#77 -1000 8 0 5 2 4 84
}
if ($Startup) {
print_log "Starting connection to LMCE";
set $restartTimer 10, sub {connect_lmce;};
}
if (inactive_now $pluto_device_event_receiver or inactive_now $pluto_device_command_sender) {
print_log "Connection to LMCE terminated, restarting";
set $restartTimer 10, sub {connect_lmce;};
}
if (new_minute 1 and !active $pluto_device_event_receiver or new_minute 1 and !active $pluto_device_command_sender) {
print_log "Connection to LMCE still terminated, restarting";
connect_lmce;
}
#my $motion=0;
if (my $msg = said $pluto_device_event_receiver) {
print_log "Pluto Device Message received: $msg\n";
$msg =~ s/[\"\']//g; # remove quotes before splitting on whitespace
if ($msg =~/(\w*)\s(\w*)\s(\w*)\s(\w*)\s(\w*)\s(\w*)\s(\w*)\s(\w*)/ or $msg =~/(\w*)\s(\w*)\s(\w*)\s(\w*)\s(\w*)\s(\w*)/
or $msg =~/(\w*)\s(\w*)\s(\w*)\s(\w*)/ ) {
print_log "DeviceFrom: $1";
print_log "DeviceTo: $2";
print_log "MsgType: $3 (1=Command, 2=Event)";
print_log "MsgId: $4";
if (defined $5) { print_log "param1id: $5";}
if (defined $6) { print_log "param2value: $6";}
if (defined $7) { print_log "param2id: $7";}
if (defined $8) { print_log "param2value: $8";}
#############################################################
# $1 $2 $3 $4 $5 $6 $7 $8
# from to msgtype msgid p1id p1val p2id p2val
# Example command from orbiter
# 69 206 1 192 97 "" 98 ""
# 69 206 1 193 97 ""
# 69 205 1 184 76 "100"
# 69 218 1 193
# Example command from admin site
# 0 204 1 760 10 "C2" 154 "192"
# 0 204 1 760 10 "C2" 154 "193"
#############################################################
my $target;
my $x10_id;
if ($2 == '71') { $x10_id = 'A5'; } # BR Table *
if ($2 == '79') { $x10_id = 'A3'; } # Hall
if ($2 == '80') { $x10_id = 'B1'; } # Triple Spot
if ($2 == '81') { $x10_id = 'A8'; } # LR Reading *
if ($2 == '82') { $x10_id = 'B3'; } # LR Red
if ($2 == '84') { $x10_id = 'C1'; } # LR AV
if ($2 == '83') { $x10_id = 'A10'; } # Landing
if ($2 == '85') { $x10_id = 'A9'; } # Kitchen
if ($2 == '72') { $x10_id = 'A6'; } # BR Mirror
if ($2 == '73') { $x10_id = 'A4'; } # BR AV
if (defined $x10_id) { $target = new X10_Item("$x10_id");}
if ($4 == '760' ) { $target = new X10_Item("$6");}
if ($8 == '192' or $4 == '192') {
print_log "Turn device $x10_id ON";
set $target ON;
}
if ($8 == '193' or $4 == '193') {
print_log "Turn device $x10_id OFF";
set $target OFF;
}
if ($4 == '184') {
print_log "Setting device $x10_id to $6%";
set $target "$6%";
}
}
}
sub send_pluto_message {
my($message) = @_;
set $pluto_device_command_sender "MESSAGET " . length ($message);
set $pluto_device_command_sender $message;
}
sub update_temp {
# Example message@
# 167=temp sensor ID, 2=event, 25=event ID (temp changed), 30=value, temperature (string)
# my $message = sprintf("167 -1000 2 25 30 %d.2",$random_number);
my($sensor, $temp) = @_;
my $lmce_device;
### map iButtons to lmce device numbers - there are better ways of doing this! ###
if ($sensor == 0) { $lmce_device = 166; }
if ($sensor == 1) { $lmce_device = 167; }
my $message = sprintf("$lmce_device -1000 2 25 30 %d.2",$temp);
send_pluto_message($message);
print_log "Updating sensor $lmce_device $temp";
}
sub lmce_motion {
my($device_id) = @_;
# 6780=Detector ID, 2=event, 9=event ID (tripped), 25=tripped value, 0=value (tripped OFF)
my $message = "$device_id -1000 2 9 25 0";
send_pluto_message($message);
}
sub lmce_still {
my($device_id) = @_;
# 6780=Detector ID, 2=event, 9=event ID (tripped), 25=tripped value, 1=value (tripped ON)
my $message = "$device_id -1000 2 9 25 1";
send_pluto_message($message);
}
if ($state = state_now $Kitchen_Motion) {
if ($state eq MOTION) {
lmce_motion(76);
}
if ($state eq STILL) {
lmce_still(76);
}
}
if ($state = state_now $Landing_Motion) {
if ($state eq MOTION) {
lmce_motion(75);
}
if ($state eq STILL) {
lmce_still(75);
}
}
if ($state = state_now $Hall_Motion) {
if ($state eq MOTION) {
lmce_motion(74);
}
if ($state eq STILL) {
lmce_still(74);
}
}
Edit: Just noticed that message values for still and motion seem to be the wrong way round? Btw I haven't been able to clear a tripped security sensor from a DCE message, it seems from looking at the admin site that there is no command to do this.