Back

How do I send an event from Perl

VSCP TCP Connection

The following code use the TCP interface of the daemon

use IO::Socket;
 
 printf("========================================================\n");
 printf("             Very Simple Perl Test\n");
 printf("========================================================\n");
 
 my $sock = new IO::Socket::INET (
                                  PeerAddr => 'localhost',
                                  PeerPort => '9598',
                                  Proto => 'tcp',
                                 );
 die "Could not create socket: $!\n" unless $sock;
 
 recv( $sock, $buffer, 200, 0);
 print $buffer;
 
 print $sock "user admin\n";
 recv( $sock, $buffer, 200, 0);
 print $buffer;
 
 print $sock "pass secret\n";
 recv( $sock, $buffer, 200, 0);
 print $buffer;
 
 #
 # Send a full GUID event
 # ======================
 # Format is
 #      "send head,class,type,obid,timestamp,GUID,data1,data2,data3...."
 #
 # Class=20  CLASS1.INFORMATION
 # TYPE = 3  ON
 # obid = 0
 # timestamp = 0
 # GUID = 0:1:2:3:4:5:6:7:8:9:10:11:12:13:14:15   on the form MSB->LSB
 # Zone=1
 # SubZone=80
 #
 print $sock "SEND 0,20,3,0,0,0:1:2:3:4:5:6:7:8:9:10:11:12:13:14:15,0,1,80\n";
 recv( $sock, $buffer, 200, 0);
 print $buffer;
 
 #
 # The same thing can be sent using
 #
 # SEND 0,20,3,0,0,-,0,1,80
 #
 # where the  interface GUID is used.
 print $sock "SEND 0,20,3,0,0,-,0,1,80\n";
 recv( $sock, $buffer, 200, 0);
 print $buffer;
 
 close($sock);

No command verification is done in this sample. Obviously this should be added. Just look for a '+' in the respons for an OK return value.

 
howto/how_do_i_send_an_event_from_perl.txt · Last modified: 2014/03/27 06:22 (external edit)
[unknown button type]
 
Except where otherwise noted, content on this wiki is licensed under the following license: Public Domain
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki