Not as much to comment on this time. I had lost all my cgi-bin files along with my perl files. Yes I had backups and lost that drive also. Now storing offsite. In the process I had to re-write them. If it had not been for the code on wordpress I would have started from scratch; although, I did not like the original code so pretty much did that anyway. 

 This is just a re-write nothing long. It took me a few hours in the middle of the night so I would not be interrupted. I am not a perl programmer and don’t pretend to be so. This is just something after referring to my perl manual that I was able to stick with and get working.   

#!perl  
 

units that control radio’s,battery  X10 (turn on) start up# Program is used to

  

  

# charger, speakers, hub power supply, TINI unit etc.   

# Program by: Benny D. Miller Jr. ARS W4QED   

# program name: X10cmd.pl   

# Date: -5/28/2010   

# use strict;   

my %parms;   

my $e,$r,$u;   

my $Pgm_Name;   

use Getopt::Long;   

if (!&GetOptions(\%parms, “help”,   

“housecode=s”, “h=s”,   

“unitcode=i”, “u=i”,   

“command=s”, “c=s”,   

“endloop=i”, “e=i”,   

“repetitions=i”, “r=i”,   

“direction=s”, “d=s”,   

“sleeptime=i”, “sl=i”, “debug”) or @ARGV == 0 or $parms{help}) {   

# print<<eof;   

# $Pgn_Name = “X10cmd.pl”;   

# Usage:   

# $Pgm_Name [options]   

# -h or -housecode => This House Code text (A-P).   

# -u or -unitcode => This is the Unit Code, integer (1-16).   

# -c or -command => This is the command to pass (On,on,Off,off).   

# -e or -endloop => Last Unit Code, integer (1-15).   

# -r or -repetitions => How many times you want command sent, integer (1…).   

# -d or -direction => Direction up, down to do commands.   

# -sl or -sleeptime => how many seconds to pause between commands.   

# Example:   

# perl $Pgm_Name -h H -u 8 -c On -e 1 -r 2 -d down -sl 5   

#eof   

# exit 1;   

}   

x10command {   

$parms{housecode} = “A” unless $parms{housecode};   

$parms{h} = $parms{housecode} unless $parms{h};   

$parms{unitcode} = ‘1’ unless $parms{unitcode};   

$parms{u} = $parms{unitcode} unless $parms{u};   

$u = $parms{u};   

$parms{command} = “Off” unless $parms{command};   

$parms{c} = $parms{command} unless $parms{c};   

$parms{endloop} = ‘0’ unless $parms{endloop};   

$parms{e} = $parms{endloop} unless $parms{e};   

$e = $parms{e};   

$parms{repetitions} = ‘4’ unless $parms{repetitions};   

$parms{r} = $parms{repetitions} unless $parms{r};   

$r = $parms{r};   

$parms{direction} = “up” unless $parms{direction};   

$parms{d} = $parms{direction} unless $parms{d};   

$parms{sleeptime} = ‘5’ unless $parms{sleeptime};   

$parms{sl} = $parms{sleeptime} unless $parms{sl};   

print $parms{housecode};   

print $parms{unitcode};   

print $parms{command};   

print $parms{endloop};   

print $parms{repetitions};   

print $parms{direction};   

print $parms{sleeptime};   

print “\n”;   

print $parms{h};   

print $u;   

print $parms{c};   

print $e;   

print $r;   

print $parms{d};   

print $parms{sl};   

print “\n”;   

if(($parms{c} eq “On”) or ($parms{c} eq “on”)) { # turn on main control which turns on others.   

&mastercontrol();   

}   

if($parms{d} eq “down”) {   

$u = $parms{u};   

while ($u ne $e) {   

$r = $parms{r};   

while($r gt 0) {   

system “ahcmd.exe sendplc $parms{h}$u $parms{c}”;   

print “$parms{h}$u $parms{c} sleep $parms{sl}\n”;   

sleep $parms{sl};   

$r–;   

}   

$u–;   

}   

}   

if ($parms{d} eq “up”) {   

$u = $parms{u};   

while ($e lt ($u+1)) {   

$r = $parms{r};   

while($r gt 0) {   

system “ahcmd.exe sendplc $parms{h}$u $parms{c}”;   

print “$parms{h}$e $parms{c} sleep $parms{sl}\n”;   

sleep $parms{sl};   

$r–;   

}   

$e++;   

}   

}   

    

if(($parms{c} eq “Off”) or ($parms{c} eq off)) {   

&mastercontrol();   

}   

system “ahcmd.exe sendplc $parms{h}$e+1 $parms{c}”;   

sleep($sl);   

system “ahcmd.exe sendplc $parms{h}$e+1 $parms{c}”;   

sleep($sl);   

exit 0;   

sub mastercontrol {   

$u = 16;   

$r = $parms{r};   

while($r gt 0) {   

system “ahcmd.exe sendplc $parms{h}$u $parms{c}”;   

print “$parms{h}$u $parms{c} sleep $parms{sl}\n”;   

sleep $parms{sl};   

$r–;   

}   

}   

}   

 In this program I have some new options. you can enter -h D or -housecode D for a housecode function along with -u 8 -unitcode 8 and when accompanied with a -e 0 will go through the selected housecode and turn on/off units 1-8 or 8-1 depending on another option -d up or -d down. Most of the options can be entered in short or long or combination of the two opthins. An example is as follows:   

perl  X10cmd.pl  -h H -u 8 -c On -e 1 -r 2 -d down -sl 5   

by using a batch file I use during startup or shutdown which follow:   

##################################################################   

DoStartUp.bat:   

#REM shut down X10 units.   

sleep 30   

perl “D:\Program Files\Apache Software Foundation\Apache2.2\cgi-bin\X10cmd.pl” -h H -u 8 -c On -e 0 -r 2 -d down -sl 3   

ahcmd.exe sendrf C1 CamGoPosition4   

sleep 2   

ahcmd.exe sendrf C1 CamGoPosition4   

sleep 2   

ahcmd.exe sendrf C1 CamGoPosition4   

#REM done   

##################################################################   

DoShutdown.bat: 

#REM shut down X10 units. 

perl “D:\Program Files\Apache Software Foundation\Apache2.2\cgi-bin\X10cmd.pl” -h H -u 8 -c Off -e 1 -r 2 -d up -sl 3 

shutdown.exe -s -t 10 

#REM done 

##################################################################   

control2.pl 

#!perl 

############################################################################### 

####### Code modified from ahp-cgi.pl by: Benny D. Miller Jr ARS W4QED ######## 

####### Date: February 8th, 2009 ############################################### 

####### Modified: March 26th, 2010 ############################################ 

####### Note: 20100526 expanded selection options ############################# 

############################################################################### 

use strict; 

use CGI; 

my($q,$msg); 

$q = new CGI->new(); 

print “Content-type: text/html\n\n”; 

if($q->param(‘cmd’) ne ” ” && $q->param(‘uc’) ne “” && $q->param(‘hc’) ne “”) { 

sendCommand($q->param(‘hc’),$q->param(‘uc’),$q->param(‘cmd’)); 

$msg = $q->param(‘hc’).$q->param(‘uc’).” “.$q->param(‘cmd’); 

getForm($msg); 

############################################################################### 

sub sendCommand 

print “$msg.”; 

my($hc,$uc,$cmd) = @_; 

system(“ahcmd.exe sendrf “.$hc.$uc.” “.$cmd); 

system(“ahcmd.exe sendrf “.$hc.$uc.” “.$cmd); 

# system(“ahcmd.exe sendplc “.$hc.$uc.” “.$cmd); 

# system(“ahcmd.exe sendplc “.$hc.$uc.” “.$cmd); 

############################################################################### 

sub getForm 

my($msg) = @_; 

print(<<END); 

<html> 

<head> 

</head> 

<body> 

<style type=”text/css”> 

A {text-decoration: none; font-weight: bold;} 

A:hover {text-decoration: underline; color: //FF0000;} 

</style> 

<center> 

<form method=”get”> 

<table cellpadding=”1″ cellspacing=”0″ border=”1″ width=”175″> 

<tr> 

 

 VK74A Control Panel 

</tr> 

<tr> 

<td bgcolor=”#ffffff”> 

<table cellpadding=”2″ cellspacing=”0″ border=”0″ width=”100%”> 

<tr> 

<td align=”left”> 

<b>Camera is C1</b> 

</td> 

<td align=”right”> 

<select name=”hc”> 

<option value=”A”>A</option> 

<option value=”B”>B</option> 

<option value=”C”>C</option> 

<option value=”D”>D</option> 

<option value=”E”>E</option> 

<option value=”F”>F</option> 

<option value=”G”>G</option> 

<option value=”H”>H</option> 

<option value=”I”>I</option> 

<option value=”J”>J</option> 

<option value=”K”>K</option> 

<option value=”L”>L</option> 

<option value=”M”>M</option> 

<option value=”N”>N</option> 

<option value=”O”>O</option> 

<option value=”P”>P</option> 

</select> 

<select name=”uc”> 

<option value=”1″>1</option> 

<option value=”2″>2</option> 

<option value=”3″>3</option> 

<option value=”4″>4</option> 

<option value=”5″>5</option> 

<option value=”6″>6</option> 

<option value=”7″>7</option> 

<option value=”8″>8</option> 

<option value=”9″>9</option> 

<option value=”10″>10</option> 

<option value=”11″>11</option> 

<option value=”12″>12</option> 

<option value=”13″>13</option> 

<option value=”14″>14</option> 

<option value=”15″>15</option> 

<option value=”16″>16</option> 

</select> 

</td> 

</tr> 

<tr> 

<td align=”left”> 

<B>Command</b> 

</td> 

<td align=”right”> 

<select name=”cmd”> 

<option value=”PanUp”>up</option> 

<option value=”PanDown”>down</option> 

<option value=”PanLeft”>left</option> 

<option value=”PanRight”>right</option> 

<option value=”CamCenter”>center</option> 

<option value=”CamSweep”>sweep</option><br> 

<option value=”CamGoPosition1″>Position 1</option> 

<option value=”CamGoPosition2″>Position 2</option> 

<option value=”CamGoPosition3″>Position 3</option> 

<option value=”CamGoPosition4″>Position 4</option> 

<option value=”On”>On</option> 

<option value=”Off”>Off</option> 

</select> 

</td> 

</tr> 

</table> 

</td> 

</tr> 

<tr> 

<td align=”right” bgcolor=”#ffffff”> 

<input type=”text” size=”17″ value=”$msg”> 

<input type=”submit” value=”Run”> 

</td> 

</tr> 

</table> 

</center> 

</form> 

</center> 

<center>Your IP is: <B>$ENV{‘REMOTE_ADDR’}</B></center> 

</body> 

</html> 

END 

1; 

__END__ 

 As stated it was a complete rewrite of the code. It seems to be a bit smoother and more into accordance to what I’ve done in the past. 

Advertisements