X10 Community Forum

🖥️ActiveHome Pro => SDK => Topic started by: gg4000 on May 17, 2012, 06:49:22 PM

Title: Perl AHCMD Server not working
Post by: gg4000 on May 17, 2012, 06:49:22 PM
Run the Sever then the client. In the client you can type sendplc a1 on. The server get's it but shows a error. B:(
Anyone see a problem in the code?

Server:

use IO::Socket;
my($housecode,$command,$tmp);
use constant AHCMD => "C:/ahcmd.exe"; #I copied ahcmd.exe to c:/
$tmp = "";
$local = IO::Socket::INET->new(
                Proto     => 'tcp',             
                LocalAddr => '192.168.1.104:6004', 
                      ) or die "$!";
$local->listen();     
$local->autoflush(1);
my $addr;       
while ($addr = $local->accept() ) {     
        print   "Connected from: ", $addr->peerhost(); 
       print   " Port: ", $addr->peerport(), "\n";
              while (<$addr>)
      {       
      $path = "C:/";
      chdir($path) or die "Cant chdir to $path $!";
      my($housecode,$command) = @_;

   print "Sending commands $housecode $command\n";
   print "$_";
      system(AHCMD." sendplc ".$housecode. " " .$command);
      system("AHCMD. $_");
                                     
                print "Received: $_";   
                print $addr $_;         
                print $path $_;                       
                close $addr;
        }
        chomp;                 
       
      if (m/^end/gi) {       
                my $send = "result=$result";   
                print $addr "$send\n";         
                print "Result: $send\n";       
                 }
           print "Closed connection until next command\n";    # Inform that connection
            close $addr;    # close client
}




Client:

use IO::Socket;
$remote = IO::Socket::INET->new(
                Proto   => 'tcp',       
                PeerAddr=> '192.168.1.104',
                PeerPort=> "6004",     
                Reuse   => 1,
                ) or die "$!";
print "Connected to ", $remote->peerhost,
      " on port: ", $remote->peerport, "\n";
$remote->autoflush(1); 
while (<>) {   
        print $remote $_;       
        last if m/^end/gi;     
        my $line = <$remote>;   
        if ($line ne $_) {     
               exit;           
        }
}
my $res = <$remote>;           
$res =~ m/result=(\d*)/gi;     
print "Result: $1\n";           
print "End of client\n";       
close $remote;       
Title: Re: Perl AHCMD Server not working
Post by: Tuicemen on May 18, 2012, 07:37:23 AM
I'm not  a perl guy but what error is displaying?
Also using AHCMD isn't the best way to pass x10events esspecialy if your planing or releasing this with your app.
AHCMD is known to lock up with repeated events.
Title: Re: Perl AHCMD Server not working
Post by: gg4000 on May 18, 2012, 11:43:27 AM
Error is....

ActiveScript Error: Expecting SendPLC  [address] [command]
Title: Re: Perl AHCMD Server not working
Post by: gg4000 on May 18, 2012, 04:54:06 PM
I have it working.  :)%
Title: Re: Perl AHCMD Server not working
Post by: Tuicemen on May 19, 2012, 10:47:56 AM
Good to Know.
 >!
Title: Re: Perl AHCMD Server not working
Post by: gg4000 on May 19, 2012, 12:10:54 PM
The files are server.exe and client.exe.
The server is set up on 192.168.1.104:8086
The client is just a small test for the server.
Start the server first, then the client.
In the client, you only need to type the house code, the unit number, and the command. A1 ON or a1 on, a1 off.
a1 dim 50, a1 bright 50....etc
Or you can use a browser.
You only need the server to run the X-10 Voice Commander.

To download the server Click Here (http://wecometomy.com/server.exe)
To download the test client (Not needed for X10 V.C.)  Click Here (http://wecometomy.com/client.exe)