#!/usr/bin/perl -w ########################################################## # RadioBot - an IRC bot to control radios through Hamlib # (c) 2007 www.tarapippo.net # Project page: www.tarapippo.net/sirad/radiobot.html # # IRC bot essentials taken from http://wholok.com/irc/ # # released under GNU/GPL license - # please see http://www.gnu.org for more details # version: 0.21 - published: 20apr07 ########################################################## ### Y O U M U S T E D I T T H I S P A R T ### # name of the bot $botname = "RadioBot"; # IRC server to connect to $server = 'eu.zirc.org'; # IRC channel the bot will sit on $mychannel = "\#radiobot_test"; # path to RIGCTL exec file # under windows double back-slashes are necessary $rctl = "c:\\hamlib\\bin\\rigctl"; #serial port $serial = "COM1" ; #serial speed - must match radio settings $speed = 19200 ; $serial = $serial . " -s $speed"; #radio model: find the code for your rx at http://hamlib.sourceforge.net under "supported radios" # 342 is Icom R8500 $rtype = "342" ; #CI-V address for Icom radios * ONLY WHEN CONNECTED USING THE CI-V PORT # es. Icom R8500 connected via the rs232 doesn't need CI-V # CI-V address must be in decimal format es. Icom R72 hex 32 > dec 50 # you can use Windows calculator to convert $civ = "-"; if ($civ ne "-"){$serial = $serial . " -c $civ";} ### EDITING THESE AS WELL MAKES IT BETTER ### #write explainations how to receive the audiofeed: streaming address, Skype nick ...whatever $audiofeedinfo = "Audio stream: "; #station details $stationdetails = "RX Icom R8500"; ####################################### use Net::IRC; use Data::Dumper; # radio declarations my $rig; my $vfo; my $m; my $nmode; # create the IRC object my $irc = new Net::IRC; # Create a connection object. You can have more than one "connection" per # IRC object, but we'll just be working with one. my $conn = $irc->newconn( Server => shift || $server, Port => shift || '6667', Nick => $botname, Ircname => $botname, Username => $botname ); # We're going to add this to the conn hash so we know what channel we # want to operate in. $conn->{channel} = shift || $mychannel; # here we start a scheduled task sending some rubbish to the IRC server to keep the connection alive &keepalive ; ###################### subs sub on_connect { # shift in our connection object that is passed automatically my $conn = shift; # when we connect, join our channel and greet it $conn->join($conn->{channel}); $conn->privmsg($conn->{channel}, 'Hello everyone!'); $conn->{connected} = 1; } sub on_join { my ($conn, $event) = @_; # this is the nick that just joined my $nick = $event->{nick}; # say hello to the nick in public $conn->privmsg($conn->{channel}, "Hello, $nick! Use <$botname help> to know more about me."); } sub on_part { # pretty much the same as above my ($conn, $event) = @_; my $nick = $event->{nick}; $conn->privmsg($conn->{channel}, "Goodbye, $nick!"); } sub keepalive { $conn->privmsg($conn->{Server}, "PING $server\n"); print "¬"; $conn->schedule(180, \&keepalive); } # Reconnect to the server when we die. sub on_disconnect { my ($self, $event) = @_; print "Disconnected from ", $event->from(), " (", ($event->args())[0], "). Attempting to reconnect...\n"; $self->connect(); } sub help { $conn->privmsg($conn->{channel}, "=== $botname IRC controlled receiver"); $conn->privmsg($conn->{channel}, "=== $audiofeedinfo"); $conn->privmsg($conn->{channel}, "=== active commands:"); $conn->privmsg($conn->{channel}, "=== <$botname freq> - display current frequency and mode"); $conn->privmsg($conn->{channel}, "=== <$botname tune XXXXXXXX> - tunes rx to XXXXXXXX in Hertz"); $conn->privmsg($conn->{channel}, "=== <$botname mode YYY> - set mode to one between: AM FM WFM USB LSB CW "); $conn->privmsg($conn->{channel}, "=== $stationdetails"); } sub tune { $_[0] =~ /$RadioBot tune /i; my $frq = $' ; $frq =~ s/\D*//g; $cmdstring = "$rctl -m $rtype -r $serial F $frq"; $answer = system($cmdstring); if ($answer == 0){ &frequency; #$conn->privmsg($conn->{channel}, "Tuned to $frq"); } else {$conn->privmsg($conn->{channel}, "There was a problem in tuning to $frq");} } sub mode { $_[0] =~ /$RadioBot mode /i; $nmode = 0 ; my $rawmode = $' ; if ($rawmode eq "AM" ){$nmode = "AM";} if ($rawmode eq "USB" ){$nmode = "USB";} if ($rawmode eq "LSB" ){$nmode = "LSB";} if ($rawmode eq "CW" ){$nmode = "CW";} if ($rawmode eq "FM" ){$nmode = "FM";} if ($rawmode eq "WFM" ){$nmode = "WFM";} if ($nmode eq 0){ $conn->privmsg($conn->{channel}, "Invalid mode: $rawmode"); } else { $cmdstring = "$rctl -m $rtype -r $serial M $nmode 0"; $answer = system($cmdstring); if ($answer == 0){ $conn->privmsg($conn->{channel}, "Switched to $nmode");} else {$conn->privmsg($conn->{channel}, "There was a problem in switching to $nmode");} } } sub frequency { my $width; $cmdstring = "$rctl -m $rtype -r $serial f"; $frq = `$cmdstring`; $frq =~ s/\n/ /g; $cmdstring = "$rctl -m $rtype -r $serial m"; $nmode = `$cmdstring`; $nmode =~ s/\n/ /g; $answer = "Listening on: $frq Hz - in $nmode Hz bandwidth" ; $conn->privmsg($conn->{channel}, "$answer"); } sub on_public { my ($conn, $event) = @_; # print Dumper($event); my $text = $event->{args}[0]; if ($text =~ /^$botname freq/) {frequency();} elsif ($text =~ /^$botname tune/) {tune($text);} elsif ($text =~ /^$botname mode/) {mode($text);} elsif ($text =~ /^$botname help/) {help();} } sub on_private { print @_ ; } ############# event handlers # add event handlers for join and part events $conn->add_handler('join', \&on_join); $conn->add_handler('part', \&on_part); $conn->add_handler('public', \&on_public); $conn->add_handler('private', \&on_private); $conn->add_global_handler('disconnect', \&on_disconnect); # The end of MOTD (message of the day), numbered 376 signifies we've connect $conn->add_handler('376', \&on_connect); # start IRC $irc->start();