Please login or register.

Login with username, password and session length

Author Topic: Perl AHCMD Server not working  (Read 7818 times)

gg4000

  • Sr. Member
  • ****
  • Helpful Post Rating: 2
  • Posts: 116
  • Been playing x-10 since Windows 3.0
    • GG4000.com
Perl AHCMD Server not working
« 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;       

Tuicemen

  • Administrator
  • Hero Member
  • ****
  • Helpful Post Rating: 283
  • Posts: 10509
  • I don't work for X10, I use it successfuly!
Re: Perl AHCMD Server not working
« Reply #1 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.
Logged
Please Read Topic:
General Forum Etiquette
Before you post!

gg4000

  • Sr. Member
  • ****
  • Helpful Post Rating: 2
  • Posts: 116
  • Been playing x-10 since Windows 3.0
    • GG4000.com
Re: Perl AHCMD Server not working
« Reply #2 on: May 18, 2012, 11:43:27 AM »

Error is....

ActiveScript Error: Expecting SendPLC  [address] [command]

gg4000

  • Sr. Member
  • ****
  • Helpful Post Rating: 2
  • Posts: 116
  • Been playing x-10 since Windows 3.0
    • GG4000.com
Re: Perl AHCMD Server not working
« Reply #3 on: May 18, 2012, 04:54:06 PM »

I have it working.  :)%

Tuicemen

  • Administrator
  • Hero Member
  • ****
  • Helpful Post Rating: 283
  • Posts: 10509
  • I don't work for X10, I use it successfuly!
Re: Perl AHCMD Server not working
« Reply #4 on: May 19, 2012, 10:47:56 AM »

Good to Know.
 >!
Logged
Please Read Topic:
General Forum Etiquette
Before you post!

gg4000

  • Sr. Member
  • ****
  • Helpful Post Rating: 2
  • Posts: 116
  • Been playing x-10 since Windows 3.0
    • GG4000.com
Re: Perl AHCMD Server not working
« Reply #5 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
To download the test client (Not needed for X10 V.C.)  Click Here
 

X10.com | About X10 | X10 Security Systems | Cameras| Package Deals
© Copyright 2014-2016 X10.com All rights reserved.