Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Wednesday, September 1, 2010

ARRL News on Allstar Node

After some review, and testing. I have updated my previous script to download the Amateur Radio Newsline when the ARRL Audio news is unavailable. I also made the script choose which announcement to play, based on which news was downloaded.

If you plan on playing MP3 files, you will need the Asterisk Addon:
Do the following:
wget -nd http://downloads.asterisk.org/pub/telephony/asterisk/old-releases/asterisk-addons-1.4.13.tar.gz
tar xvzf asterisk-addons-1.4.13.tar.gz
cd  asterisk-addons-1.4.13
./configure
make
make install
restart asterisk an you can start using mp3 format. However format_mp3 can cause Asterisk to crash on certain mp3 files (notably 8k files made with lame) due to bugs in mpglib.  If you must use this module, use it only with mp3's you know will work with it. This needs to be done every time asterisk is compiled and reinstalled.

My scripts are available to Amateur Radio Operator to use. I only ask that you make a comment here and let me know where it is deployed.

To use this script, you will need to create a "news" directory first by entering "mkdir /var/lib/asterisk/sounds/rpt/news".

You will also need to create 2 audio files for this. These are your precursor announcements, and I include the command to stop automated playback in the announcement, just in case there is emergency or priority traffic.

/var/lib/asterisk/sounds/rpt/ARRL-QST-News.ulaw
/var/lib/asterisk/sounds/rpt/ARN-QST-News.ulaw

Here is an example script that I read, and recorded into a ulaw format for the node per support instructions, (http://ohnosec.org/drupal/node/142):
------------------
QST QST QST

Please stand by for a re-transmission of last weeks ARRL Audio News.

When available, the ARRL Audio News is re-transmitted on this WA6YBN Repeater every Monday night at 7 PM Local Time. If the ARRL Audio News is unavailable, the Amateur Radio Newsline will be aired in its place.

If you have Emergency or Priority traffic during an automated playback, use *999 to cancel it.

For more information, e-mail WA6YBN@GMAIL.COM or visit us at qsl.net/wa6ybn

The Re-Transmission of the ARRL Audio News will begin momentarily.
------------------

Next, create the script file, watch out for word wrap if you copy and paste from this site. I will post the script file somewhere and post a link here for download.

Enter "vi /etc/asterisk/news", then type "i" to begin editing. Copy and paste the script below.
-------------------------------------------------------------------------------------


#!/bin/bash
#Please comment on my blog as to where this script is running. Thanks
#Script by KI6PSP, Ref KI6PSP.BLOGSPOT.COM, 73s
cd /var/lib/asterisk/sounds/rpt/news/
#Cleanup last weeks news file
rm -f /var/lib/asterisk/sounds/rpt/news/QST-News.ulaw
rm -f /var/lib/asterisk/sounds/rpt/news/news.wav
rm -f /var/lib/asterisk/sounds/rpt/news/news.mp3
rm -f /var/lib/asterisk/sounds/rpt/news/news.gsm
echo "Starting Dowload of ARRL Audio News @ $(date +%H:%M:%S)"
wget http://www.arrl.org/files/file/News/Audio%20News/AudioNews$(date --date="last thursday" +%m%d%y).mp3
if [ -f /var/lib/asterisk/sounds/rpt/news/AudioNews$(date --date="last thursday" +%m%d%y).mp3 ];
 then
 echo "Download complete @ $(date +%H:%M:%S)"
 #Extract the MP3 to RAW
 #Long Command here, may wordwrap......
 /usr/local/bin/mpg123 -s --rate 44100 --mono /var/lib/asterisk/sounds/rpt/news/AudioNews$(date --date="last thursday" +%m%d%y).mp3 > /var/lib/asterisk/sounds/rpt/news/news1.raw
 #Verify Extraction Completed
  if [ -f /var/lib/asterisk/sounds/rpt/news/news1.raw ]
  then
  echo "MP3 Expansion Complete, Starting Conversion @ $(date +%H:%M:%S)"
  #Convert RAW to WAV and reduce volume
   #Change the "-v .8" to a value acceptable for your system, .8 means 80% of original volume.
  /usr/bin/sox -r 44100 -w -s -c 1 /var/lib/asterisk/sounds/rpt/news/news1.raw -r 8000 -v .8 -c 1 /var/lib/asterisk/sounds/rpt/news/news.wav
  #Verify Conversion Completed
     if [ -f /var/lib/asterisk/sounds/rpt/news/news.wav ];
     then
     echo "Download and Conversion Completed @ $(date +%H:%M:%S)"
     else
     echo "Conversion Failed @ $(date +%H:%M:%S)"
     exit
     fi
  else
  echo "MP3 Expansion Failed @ $(date +%H%M%S)"
  exit
  fi
 #Cleanup MP3 Download and RAW File
 rm -f /var/lib/asterisk/sounds/rpt/news/AudioNews$(date --date="last thursday" +%m%d%y).mp3
 rm -f /var/lib/asterisk/sounds/rpt/news/news1.raw
 #List directory for log file
 cp /var/lib/asterisk/sounds/rpt/ARRL-QST-News.ulaw /var/lib/asterisk/sounds/rpt/news/QST-News.ulaw
 ls -l
 else
 echo "ARRL Audio News Unavailable, Downloading Amateur Radio Newsline @ $(date +%H:%M:%S)"
 rm -f /var/lib/asterisk/sounds/rpt/news/missing.png
 wget http://arnewsline.squarespace.com/storage/audio/news.mp3
   if [ -f /var/lib/asterisk/sounds/rpt/news/news.mp3 ];
   then
   echo "Download complete @ $(date +%H:%M:%S)"
   /usr/local/bin/mpg123 -s --rate 44100 --mono /var/lib/asterisk/sounds/rpt/news/news.mp3 > /var/lib/asterisk/sounds/rpt/news/news1.raw
     if [ -f /var/lib/asterisk/sounds/rpt/news/news1.raw ]
     then
     echo "MP3 Expansion Complete, Starting Conversion @ $(date +%H:%M:%S)"
     #Convert RAW to WAV and reduce volume
      #Change the "-v .8" to a value acceptable for your system, .8 means 80% of original volume.
     /usr/bin/sox -r 44100 -w -s -c 1 /var/lib/asterisk/sounds/rpt/news/news1.raw -r 8000 -v .8 -c 1 /var/lib/asterisk/sounds/rpt/news/news.wav
     #Verify Conversion Completed
       if [ -f /var/lib/asterisk/sounds/rpt/news/news.wav ];
       then
       echo "Download and Conversion Completed @ $(date +%H:%M:%S)"
       #Cleanup MP3 Download and RAW File
       rm -f /var/lib/asterisk/sounds/rpt/news/news.mp3
       rm -f /var/lib/asterisk/sounds/rpt/news/news1.raw
       #List directory for log file
       cp /var/lib/asterisk/sounds/rpt/ARN-QST-News.ulaw /var/lib/asterisk/sounds/rpt/news/QST-News.ulaw
       ls -l
       else
       echo "Conversion Failed @ $(date +%H:%M:%S)"
       exit
       fi
     else
     echo "MP3 Expansion Failed @ $(date +%H%M%S)"
     #If download failed, delete the retrieved PNG File and copy alternate file to news.wav
     cp /var/lib/asterisk/sounds/rpt/NONE-QST-News.ulaw /var/lib/asterisk/sounds/rpt/news/news.ulaw
     exit
     fi
   else
   #If download failed, delete the retrieved PNG File and copy alternate file to news.wav
   cp /var/lib/asterisk/sounds/rpt/news/memory_notfound.gsm /var/lib/asterisk/sounds/rpt/news/news.gsm
   cp /var/lib/asterisk/sounds/rpt/NONE-QST-News.ulaw /var/lib/asterisk/sounds/rpt/news/QST-News.ulaw
   fi
 exit
 fi
exit

-------------------------------------------------------------------------------------

After pasting this, you need to save it by hitting the "Esc" key, then typing ":wq". Next we need to make sure the script has permission to run, by entering "sudo chmod o+x /etc/asterisk/news"

I created this script because I needed to download the MP3, but I convert the file because I couldn't get the MP3Player to work in Asterisk. I had everything installed, but couldn't get the syntax to actually play the file. But I was already playing wav files.

*****You will need to install the Add-on for Asterisk using these commands:*****

cd /tmp/
wget http://downloads.asterisk.org/pub/telephony/asterisk/old-releases/asterisk-addons-1.4.13.tar.gz
tar -xf asterisk-addons-1.4.13.tar.gz
cd asterisk-addons-1.4.13
make clean
./configure
make install
service asterisk restart

Now your reasy to test, to run the script manually for testing purposes, enter "/etc/asterisk/news"

To automate this script, I used crontab. I typed "crontab -e" and pasted in the following:
0 7 * * 5 /etc/asterisk/news > /etc/asterisk/news.log
This will run my script on Friday Mornings, so the news will be ready to go for Monday nights.

To make this fully automated, we modify the rpt.conf to add something like this:

[schedule27178]
25= 0 19 * * 1     ;Announce the News Re-Transmission at 7:00 PM on Monday
26= 1 19 * * 1     ;Begin playback of the ARRL Audio news that is already downloaded

[functions27178]
925=playback,rpt/QST-News     ;Command to make Announcement
926=playback,rpt/news/news     ;Command to start playback
999=cop,24 ; Flush All Telemetry (AKA:Be Quiet)

[macro27178]
25=*925#     ;Macro for scheduler to make Announcement
26=*926#     ;Macro for scheduler to start playback

This repeater is setup to Morse its ID over the audio, so I don't have to key in the Club Call during the news.

Ed
KI6PSP
http://ki6psp.blogspot.com/

Saturday, June 12, 2010

Club Repeater Buildout

I began building and testing an Allstar Repeater for my local club (WA6YBN), using a computer from a previous blog post. The Allstar install disk is not like a Windows install, it installs basic functionality, then gets the rest from the Internet. The install disk will show a text mode menu system with colors, but this is as fancy as an Allstar build gets. You will need at least a 4GB HDD. It will setup, partition, and perform the install. After the install, it will start getting material from the Internet and updating itself, that took about 45 minutes for me. I just left it to do its thing for a few hours, and then it will be almost ready for configuring. The first thing it asks for is a password for the root account. Pay attention here, because if you just hit the enter key a few times here, you won't be able to login.
     A script will start asking Allstar related questions, and it will program your node number, and then ask you to plug in your USB Radio Interface, then it will reboot. After that completes, you can login with "root" and the password you set.
     I grew up installing Windows 95 over DOS, so command line is not new to me, but Linux is a little intimidating because of the different structure. There is no GUI (Graphical User Interface), so you will need to understand how to navigate using the keyboard. I wanted to setup several capabilities for this Allstar Node, Echolink being one of them. I will demonstrate basic commands using the procedures I used to configure Echolink on Allstar. My reference for setup is located here. There is a wealth of information on app-rpt.qrvc.com related to setting up an Allstar Node, but come linux experience is needed, that you can learn here.

The starting point here is how to change folders. The "cd" command is for Changing Directories and it is used like so:

[root@test ~]# cd /etc/asterisk
[root@test asterisk]#

Notice the "/etc/", the Asterisk config folder is in the /etc/ folder. The folder name you are in shows in the brackets of the command line header. If you enter "dir", it will show you a listing of what is in the directory. To go back to the root folder, simply enter "cd", with no folder destination. When you are back at the root level of the folder structure, it will show "~", as you are not in a folder.

If you need to make a folder, use "mkdir foldername", where foldername would be what you want it to be called. Remember, whatever folder you are in, is where you will be creating this folder. So use the cd command to navigate to where you want this folder first.

To copy files, I find it easiest to go to the folder where the file resides, and then use the "cp" (copy) command like this:

[root@test ~]# cd /usr/src/configs/examples/echolink/
[root@test echolink]# cp echolink.conf /etc/asterisk/

Editing configuration files is a little different. first navigate to the folder where the configuration file you want to modify resides.

[root@test echolink]# cd
[root@test ~]# cd /etc/asterisk

Next we need to edit the file with a program called VI Editor. To edit the echolink.conf file, type the following:

[root@test asterisk]# vi echolink.conf

This will open a full screen editor, and display the configuration file. To move up and down the file, use the arrows on the keyboard. To make changed, first hit "i", and INSERT will appear on the bottom left of the screen. you can now make changed to the file. Some lines start with a ";". Those lines will be ignored, and it is an easy way to turn a command on or off by adding or removing the ";". Sometimes comments for commands will be on the same line as the command, the system will simply ignore anything on that line after the ";" character.

When you are done with your exiting, hit the "ESC" key to exit the edit mode. To quit the editor, first type ":", then the program will accept commands like "q" for quit, "wq" write and quit, "q!" for quit without save

The program that does the work of the repeater is called Asterisk. It was initially intended for phone communications. Tuning of the repeater can be done now, I followed instructions located here. I did need to borrow a service monitor from a friend to complete the tuning, and I also had to adjust the gain level in the rpt.conf to make it sound a little better. When making various changed to the config files, I would usually restart Asterisk so it would take the new settings by executing "service asterisk restart", this way I wouldn't have to do a full reboot.

A quick Duplexing Vs Simplex note, Allstar defaults to full duplex, so it will be impossible to control or use if you are setup for simplex without adding "duplex=1" to the rpt.conf file, in the section for your node number. 2 is the default to run as Full Duplex, 1 is Semi-Half Duplex and will give all the tones and identifiers, while 0 is full Half Duplex with no tones or identifiers.
If you are planning on setting up your Allstar Node with Echolink capability, you will need to go through the validation process, login and setup as a repeater to get a node number. Once you have that all complete, its just a matter of using the correct DTMF commands.

*1node Disconnect Link
*2node Connect link in monitor mode
*3node Connect link in transceive mode
     For Allstar, use *3nnnn, all Allstar nodes start with a 2
     For Echolink, use *33nnnnnn, ex, *33009999
     For IRLP, use *34nnnn
*4node Enter command mode on a remote node
*7 Local connection status

*80 Force System ID
*81 Say System Time
*82 Say app_rpt software version
*85 Last active node (system-wide)
*87 System-wide connection status

Have Fun with Allstar


Ed
KI6PSP
http://KI6PSP.blogspot.com