This Perl program is called by HCA, using three parameters to format and send a packet to the appropriate Arduino. The 3 parameters are command, IP address and data. HCA sends them in that order as flags ardcmd1, ardaddr1 and arddata1 respectively. See this posting for more information.
use Getopt::Long; #pick up parms
my $cmdIn = sprintf(“%.0f”,$ARGV);
my $addrOut = $ARGV;
my $dataIn = sprintf(“%.0f”,$ARGV);
my $dataOut = $cmdIn . $dataIn;
# print “$cmdOut\n”;
# print “$addrOut\n”;
# flush after every write
# $| = 1;
# my $dot68 = “192.168.0.68”;
# we call IO::Socket::INET->new() to create the UDP Socket and bound
# to specific port number mentioned in LocalPort and there is no need to
# provide LocalAddr explicitly as in TCPServer.
my $socket = new IO::Socket::INET (
LocalPort => 6001,
Proto => ‘udp’,
PeerPort => 5001,
PeerAddr => $addrOut,
) or die “ERROR in Socket Creation : $!\n”;
# read operation on the socket
# get the peerhost and peerport at which the recent data received.
# $peer_address = $socket->peerhost();
# $peer_port = $socket->peerport();
# print “\n($peer_address , $peer_port) said : $received_data”;
#send the data to the arduino.
# $data = ‘1’;
print $socket “$dataOut”;