Using Python and a Raspberry Pi to Update Icecast Audio Feeds with Scanner Alpha Tags
The python scripts below will add the ability to update Icecast feed metadata via the Raspberry Pi. They are compatible with Uniden Scanners including:
Functionality could be added for other Uniden scanners such as the 780XLT, 785D, 796D, and 898T, but as of now I don’t have access to any of these models for testing.
To implement the script, download the script by right clicking on the appropriate link below and click “Save As”. You can do this from the Raspberry Pi or from another computer and use any number of tools such as ssh and scp to copy the file to your desired location on your Raspberry Pi.
Uniden MetaPy.py Script – For all models except the BCT8
Uniden MetaPy8.py Script – For the BCT8
and BCT898 models
Or you can use the
wget command from your Raspberry Pi’s console to download and save the file:
wget -O ~/metaPy.py http://www.k7bbr.net/files/metaPy.py
or for the BCT8/898:
wget -O ~/metaPy8.py http://www.k7bbr.net/files/metaPy8.py
(The -O option allows you to give the file location and filename for the downloaded file – in this case it’s saved in your home directory under the name
Once downloaded, use a text editor such as
vi to change the configuration section at the top of the script to match your settings:
port = "/dev/ttyUSB0" #enter scanner USB/serial port in quotes here
baudrate = 115200 #enter scanner baudrate here
icecastUser = "username" #enter icecast username in quotes here (for RR feed use "source")
icecastPass = "hackme" #enter icecast password in quotes here
icecastServerAddress = "192.168.1.100:8000" #enter icecast server IP Address (and port if necessary) here
icecastMountpoint = "mymountpoint" #enter icecast mountpoint in quotes here - don't add leading '/'
csvFile = "frequencies.csv" #enter the name of the csv file containing alpha tag data frequencies in 1st column, tags in 2nd column
'''-----------------END USER CONFIGURATION---------------'''
'''----------UNNECESSARY TO MODIFY SCRIPT BELOW----------'''
To connect your scanner you’ll need a USB to serial adapter. If it’s the first one connected, it should show up as
/dev/ttyUSB0. You can check and see by going to
/dev and list the files and look for ttyUSB0 or something similar. Also make sure that the baudrate in the script is the same as the baudrate set in your scanner.
The script uses two Python modules requests and serial that may or may not be installed on your Raspberry Pi. You can install these packages by using apt-get:
sudo apt-get install python-serial, python-requests
To run the script, change directories to the location the script is saved. Then type
python metaPy.py to begin the script. If it is running, you will see it print out talkgroup information, time information and an update status:
Davis County Sim 11232 Syracuse PD 2 C
Thu Jun 13 21:07:03 2013
Icecast Update OK
Davis County Sim 10688 Davis Ops 2
Thu Jun 13 21:07:21 2013
Icecast Update OK
The script can be placed in the background by typing
. It can be brought back to the foreground by typing
You can also start the script detached from the console by adding an & to the end of the command:
python metaPy.py & .
To stop the script, simply type
ctrl-c, or find the process and kill it.
The BCT8/BCT898 scanners don’t support frequency tagging. This can be
implemented however, by creating a CSV file with frequencies in the first column
and Alpha Tags in the second column. Place this file in the same directory
as the MetaPy8.py script. In the script USER CONFIGURATION section set the
variable csvFile to the name of the .csv file you created with your
frequency/tag data. When the script is run it will lookup data in the file and
if a tag is found for the frequency, it will add that to the feed metadata.
Note: Each time you make changes to the lookup table, you need to restart the
metaPy8.py script. The frequency should be in the format: XXX.XXXX. If
there are only 2 digits before the decimal point, add a space character to the
frequency area of the table:
By using Darkice to feed the audio and this metaPy.py script to feed the alpha tags, you now have a 5W streaming media box to stream both scanner audio and text alpha tags.