Facebook Group: Military Air & Space Communications.
2700+ members, logs, how too's & more. Please click the link and join.
Cheap SDR Dongle Connected to a Raspberry Pi Computer for a Self-Contained Audio Streaming Device
This is project using the Raspberry Pi and the Dongle. I've been thinking of how I could stream audio
online without tieing up a "real" computer. I've been streaming Military Aviation Communications audio
for years. But sometimes I don't like streaming from the computer that I do "real" work on, this got me
thinking of a new project for the Raspberry Pi computer. At this time the project isn't complete but
it is just to prove the concept that it will work. This project is no more than me experimenting with
the Raspberry Pi and Linux style of operating system, both new to me.
Some applications for this type of setup would be to mount this very small dongle/Raspberry system
at the antenna to avoid coax losses. It would be great if powered from a battery/solar panel. You
could set one at your Ham Radio repeater site and stream the repeaters audio online. Put one at
your friends house if he lives close to something you would like to monitor but you're too far
away for a good signal....The possibilities are endless. Please if you think of some good
uses share them with me....
If you don't have any experience using the Raspberry Pi computer you first need to see my
article Raspberry Pi - Getting It Ready for Neat Scanner Projects. That
article will guide you through installing an operating system, setting up the networking, and getting
the Raspberry Pi computer and Dongle to talk to each other.
Picture of the Self-Contained Dongle Radio Streaming via the Raspberry Pi's Wifi dongle.
Click on Picture for larger image
As a first test I installed and confirgured the required software on the Raspberry Pi computer. I then tuned
the SDR Dongle to a NOAA weather radio frequency (162.400 MHz), and using ezstream and lame software
I had the Raspberry Pi stream the audio to an Icecast 2 server via a wifi link. Since I now can get audio
from the Raspberry Pi to Icecast, this means I could stream scanner audio to any web service that accepts
Icecast such as LiveATC.net
Steps on How to Stream Dongle Audio Through Raspberry Pi to an Icecast Server
- 1) Install ezstream, this will stream mp3 audio to an IceCast server, type the following command:
sudo apt-get install ezstream
- 2) Install lame, this will handle the MP3 audio encoding. It takes the output from the Dongle and converts it to MP3 format.
Type the following command:
sudo apt-get install lame
Setting Up an IceCast Server on Your PC
If you don't have access to an IceCast server to stream to (like LiveATC.com) you'll want to setup
your own. You really should do this to test out your system. You will want to go to IceCast.org
and download IceCast for your Windows PC. At the time of this article (Feb. 27, 2014) the link on the IceCast
website didn't work for downloading the Windows version. But never fear I have a way around this that worked.
scroll to the bottom of the download page. You will see a section called Icecast Old Releases Click
on the linked titled Icecast. Scroll down until you see icecast2_win32_2.3.2_setup.exe, click
on that file and save it to your PC. This is the version I used and it worked.
Install IceCast as you would install any piece of software on your Windows PC. Once installed start IceCast by
clicking on the IceCast icon. When IceCast starts, choose Configuration icecast.xml will open
in Notepad, scroll down until you see source-password, relay-password, admin-password change these
passwords to something you'll remember.
Next you will need to figure out what the IP address of the computer you're running IceCast on is.
It probably will start with 192.168.1.xxx (in my case 192.168.1.105). If you wish to allow other people
listen to streams on your IceCast computer you'll probably have to log into your router (the little box your cable
modem is connected to). Usually you can do this by opening up your web browser and enter the web address exactly like
this http://192.168.1.1 This is the default IP address of most routers. The default username usually
is admin, default password usually is admin. Next you're going to want to look for an option
called port forwarding, some routers call this Applications & Gaming as is the case of my Linksys
router. You will want to tell the server to forward any requests for port 8000 to the IP address
of the computer you are running IceCast on. If you do not wish to stream your IceCast audio over the
internet for others to listen to, you don't need to worry about these router settings.
Now you'll want to start the IceCast server. To do this make sure you've got IceCast running, then click the
Start Server button. Its as simple as that!
Setting Up Ezstream and its XML File to Stream MP3 Audio to IceStream
You will need to create a .XML which Ezstream uses to know where to send the audio to, format, password,
and comments. To correctly setup the .XML file do the following:
- 1) Type cd this will put you in your home dirctory (the directory you are put into when you login).
- 2) Type pwd, you should see "/home/pi". We're just making sure you are really in your home directory.
- 3) We now will use nano to create a file called ezstream.xml, type sudo nano ezstream.xml
- 4) In the window below you'll see a template you can use for the ezstream.xml file. Click somewhere
on the text below, then hit CTRL A to select the entire window. Next hit CTRL C
to copy the text to your clipboard. Now return to your PuTTY window, select the window with your
mouse, then hit the RIGHT mouse button. This will copy the contents of your clipboard to
the ezstream.xml file you have open in nano.
- 5) Next you'll make some changes to the ezstream.xml file. Do Not Use Your Mouse
while in nano, it just screws things up!. User your up arrow key to move to
the top of the file.
- 6) The 2nd line of text says your_icecast_stream_server replace the text between
the "url" tags with the following: http://192.168.1.105:8080/stream_raspberry, but
use the IP address of your IceCast machine.
- 7) The next line says sourcepassword, change that to what you set the
source password in IceCast.
- 8) While using your down arrow key, move down the file until you find
svrinfobitrate, change the 128 to 16
- 9) Move down until you see svrinfosamplerate, change the 44100 to 22000
- 10) You will see other informational items in the ezstream.xml file such as description of
stream, URL, and so on. These don't need to be change.
- 11) You're done editing the file, to save the file hit CTRL O, then hit Enter
to write the file. Then to exit nano hit CTRL X
- 12) Are you getting excited yet? We're almost ready to test it out!
Ok, we are ready to see if we made any mistakes. The following command is a bit long to type
and its very important you get every letter correct, every space correct, and
every punctuation mark correct so use care or you'll get an error.
The following command is going to tell the Dongle to tune to the frequncy 162.4 MHz in FM mode. I
picked a NOAA weather frequency since its always broadcasting and makes testing easy. If you
don't have a receivable weather frequency in your area, you can use any FM broadcast station. If
you use a broadcast station, change fm to wbfm and change 162.4
to the frequency you want to receive. Type the following command:
sudo rtl_fm -M fm -f162.4M -r 22000 -p 48 | lame -r -s 22.0 -m m - - | ezstream -c ezstream.xml
Experimental Command for scanning frequencies:
sudo rtl_fm -M fm -f147.15M -f147.24M -f147.375M -f443.925M -f442.075M -l 400 -r 22000 -p 48 | lame -r -s 22.0 -m m - - | ezstream -c ezstream.xml
If everything is working your PuTTY screen should have the following:
Now your Dongle is streaming to your IceCast server. If you want to stop the process you simply
can hit CTRL C from your PuTTY window.
If things didn't work you'll be sitting at your Linux prompt. If you scroll up the screen
you'll probably see an error message telling you want you may have done wrong. Simply fix
the issue and try again.
Here is a handy command to save some 'retyping' Linux commands. If you hit your Up
arrow you'll see the last few commands you typed, this is a handy timesaving thing to know.
To listen to your streaming audio from any computer attached to your router (either wired Ethernet,
or Wifi) go to your web browser and type the following: http://192.168.1.105:8000, but
use the actual IP address of the computer running IceCast. If things are working you should then
see the Icecast2 Status display. To listen to the audio stream click on the icon
that says M3U. If you want someone to go directly to the audio without seeing the
Icecast2 Status display you can type the following into your web browser:
To find the IP address your ISP assigned you go to the website
I have tested this with an Apple iPhone and it sounds good. I have not tested with other
If your audio sounds like its off frequency you will have to play with the Dongle frequency
correction. Its easy to use SDRSharp to determine just what the correction should be. In my case
I had to add a correction factor or 48, that is the -p 48 part of the rtl_fm
Below I'm including some of the parameters that can be used with the rtl_fm program.
- -M fm | wbfm | am | usb | lsb | raw
- Selects a demodulator.
- -M fm narrow band FM
- -M wbfm wide band FM
- -M am amplitude modulation
- -M lsb lower sideband
- -M usb upper sideband
- -M raw raw output, 2x16 bit IQ pairs. Purely debugging and no sane person has any use for this.
- -f "freq" | "start:stop:step"
- Tune to a frequency. Value can be specified as an integer (89100000), a float (89.1e6) or as a metric suffix (89.1M). Multiple values or ranges will be scanned.
- -s "sample_rate"
- -d "index"
- When using multiple dongles, this indicated which. You can also identify dongles by the text in the serial number field of the EEPROM.
- -g "gain"
- A floating point gain value. The dongle will use the closest gain setting available.
- -p "error"
- Correct for the parts-per-million error in the crystal.
- -F 0 | 9
- Enable a higher quality downsampling FIR than the default boxcar filter. -F 0 is okay to use while -F 9 is still a work in progress.
- -A std | fast | lut
- Choose how arctan is computed. Options select between the standard (floating) lib, a fast polynomial integer approximation and a precomputed look-up-table.
- -E dc | deemp | direct | offset
- -E dc dc blocking filter
- -E deemp de-emphasis filter for WBFM
- -E direct direct sampling mode
- -E offset offset tuning mode (E4000 only)
- -l "squelch level"
- Squelch is required for scanning multiple frequencies, to indicated when a frequency should be skipped. When used with a single frequency the output will be muted instead. Default value is 0/off.
Squelch values are extremely sensitive to external conditions (noise and antenna) as well as the other options used. For example, squelch should be halved when the sample rate is doubled. When in doubt, start at zero and work upwards.
- -t "squelch delay"
- The number of squelch hits to count up to. Default value is 20. So the squelch must be trigger 20 times consecutively before rtl_fm moves on to the next channel.
Negative delay values cause rtl_fm to exit instead of hopping to another channel or muting the output. This is useful for scripts or trunked systems.
- -r "output rate"
- In some odd circumstances you might want to apply an extra low pass downsampling/resampling stage. This is for that, but most of the time it is rarely needed. It will also change the output rate. It is also a very poor quality resampler. Use sox for resampling.
I hope you've enjoyed this article.