Actions

Difference between revisions of "Raspberry Pi RTL-SDR Broadcastify"

From The RadioReference Wiki

Line 1: Line 1:
 
[[File:rtl_rsp_bcfy.jpg|200px|thumb|right|Raspberry Pi Broadcastify RTL-SDR Feed Appliance]]
 
[[File:rtl_rsp_bcfy.jpg|200px|thumb|right|Raspberry Pi Broadcastify RTL-SDR Feed Appliance]]
These instructions show you how to purchase and setup a completely self contained Raspberry Pi with an RTL-SDR stick(s) to broadcast a live audio feed to Broadcastify.com
+
These instructions show you how to purchase and setup a completely self contained Raspberry Pi with an RTL-SDR stick to broadcast a live audio feed to Broadcastify.com. This tutorial assumes you have a basic understanding of Linux and Raspberry Pi computers.
  
These instructions have been verified and tested as working on a Raspberry Pi 2 Model B Project Board - 1GB RAM - 900 MHz Quad-Core CPU.  Two '''separate''' feeds running rtl_fm broadcasting both AM aviation and FM business frequencies simultaneously have been verified as working just fine.
 
  
 
== Purchase Equipment ==
 
== Purchase Equipment ==
  
Raspberry Pi 2 Model B Project Board - 1GB RAM - 900 MHz Quad-Core CPU
 
* http://amzn.to/1Ku3T9Y
 
  
RTL-SDR - RTL2832U & R820T2 USB Stick
+
RTL-SDR RTL2832U USB Stick
 +
* Nooelec NESDR Smart v4 Bundle - Premium RTL-SDR w/Aluminum Enclosure https://amzn.to/3kaHMJL
  
* R820T Stick - http://amzn.to/1KFmhd6 (Most common)
 
* R820T2 Stick - http://amzn.to/1DJA79d (slightly better performance and stability)
 
  
Male MCX Connector to...
+
Raspberry Pi
 +
* CanaKit Raspberry Pi 3 B+ (B Plus) with Premium Clear Case and 2.5A Power Supply https://amzn.to/3bMP2bR
  
* F Female - http://amzn.to/1KtVwIt
 
* PL259 - http://amzn.to/1JLgjV7
 
* BNC - http://amzn.to/1DJqZ4A
 
* SMA - http://amzn.to/1JLgAav
 
* Lots of connectors - http://amzn.to/1Ku4c4s
 
 
Power Supply for Raspberry Pi
 
 
* http://amzn.to/1U2r8cD
 
 
Memory Card for Raspberry Pi
 
 
* http://amzn.to/1U2r8JG
 
 
Case for Raspberry Pi
 
 
* http://amzn.to/1JLgNe3
 
  
 
== Install Raspbian OS ==
 
== Install Raspbian OS ==
 
All testing and configuration was done using Raspbian
 
  
 
* Follow the instructions here:
 
* Follow the instructions here:
 
** https://www.raspberrypi.org/documentation/installation/installing-images/README.md
 
** https://www.raspberrypi.org/documentation/installation/installing-images/README.md
  
You can also download and install a completely preconfigured image that includes all the software and configuration files necessary
+
Once you have your Raspberry Pi booted and online you may continue.
* [[Raspberry Pi Broadcastify Image]]
 
  
 
== Install pre-reqs and update raspberry pi to latest version ==
 
== Install pre-reqs and update raspberry pi to latest version ==
Line 48: Line 25:
 
  sudo apt-get update
 
  sudo apt-get update
 
  sudo apt-get upgrade
 
  sudo apt-get upgrade
  sudo apt-get install git cmake libusb-1.0-0.dev build-essential lame
+
  sudo apt-get install build-essential libmp3lame-dev libshout3-dev libconfig++-dev
  sudo apt-get install libmp3lame-dev libvorbis-dev libshout-dev
+
  sudo apt-get install libraspberrypi-dev
 +
sudo apt-get install libfftw3-dev
 +
apt-get install librtlsdr-dev
 +
install rtl-sdr
 
  sudo reboot
 
  sudo reboot
  
== Install the latest rtl-sdr code ==
+
== Install RTLSDR-Airband ==
 +
cd ~/
 +
mkdir RTLSDR-Airband
 +
cd RTLSDR-Airband
 +
wget -O v3.1.0.tar.gz https://github.com/szpajder/RTLSDR-Airband/archive/v3.1.0.tar.gz
 +
tar xvfz v3.1.0.tar.gz
 +
cd RTLSDR-Airband-3.1.0
 +
make PLATFORM=armv8-generic NFM=1
  
This latest git release is needed for padding zeros when squelch is enabled (-E pad option)
+
Let it compile until it finishes then install it ...
  
git clone https://github.com/keenerd/rtl-sdr
 
cd rtl-sdr/
 
mkdir build
 
cd build
 
cmake ../
 
make
 
 
  sudo make install
 
  sudo make install
sudo ldconfig
 
sudo mv $HOME/rtl-sdr/rtl-sdr.rules /etc/udev/rules.d/rtl-sdr.rules
 
  
== Blacklist the kernel's bundled RTL drivers ==
+
The program should now be installed to /usr/local/bin/rtl_airband. The default configuration file will be installed to /usr/local/etc/rtl_airband.conf which we will edit next.
  
We do this before connecting the USB dongle so we don't conflict with the RTL drivers we're about to install. 
+
== RTLSDR-Airband Config ==
 +
To edit the config file for RTLSDR-Airband enter this command:
 +
sudo nano /usr/local/etc/rtl_airband.conf
 +
and paste the following into the editor
  
  sudo su -
+
  # This is a minimalistic configuration file for RTLSDR-Airband.
  echo "blacklist r820t" >> /etc/modprobe.d/dvb-blacklist.conf
+
  # More complex configurations are possible.
  echo "blacklist rtl2832" >> /etc/modprobe.d/dvb-blacklist.conf
+
  # Refer to https://github.com/szpajder/RTLSDR-Airband/wiki
  echo "blacklist rtl2830" >> /etc/modprobe.d/dvb-blacklist.conf
+
# for description of keywords and config syntax.
  echo "blacklist dvb_usb_rtl28xxu" >> /etc/modprobe.d/dvb-blacklist.conf
+
  # Just a single RTL dongle with one FM channel
exit
+
# sent to a single Broadcastify stream.  
 +
  # Note that the center freq is 100 KHz offset from the receive freq
 +
# Also, you must enter your server number, mountpoint and
 +
# password from your Broadcastify stream "Technicals"
  
== Install rtl_airband customized for Broadcastify ==
+
devices:
 +
({
 +
  type = "rtlsdr";
 +
  index = 0;
 +
  gain = 25;
 +
  centerfreq = 153.87;
 +
  correction = 0;
 +
  channels:
 +
  (
 +
    {
 +
      freq = 153.77;
 +
        modulation = "nfm";
 +
        highpass = 320;
 +
      outputs:
 +
        (
 +
        {
 +
          type = "icecast";
 +
          server = "audio#.broadcastify.com";
 +
          port = 80;
 +
          mountpoint = "MOUNTPOINT";
 +
          name = "Santa Barbara County Fire Dispatch";
 +
          genre = "Fire";
 +
          username = "source";
 +
          password = "PASSWORD";
 +
        }
 +
      );
 +
    }
 +
  );
 +
});
  
This tutorial's rtl_airband implements a pre-compiled binary that is customized to read a specific configuration file named /etc/rtlairband2_config.txt and use an AM filter bandwidth of 16khz. It was compiled for the Raspberry Pi2.
 
  
sudo su -
+
== Run ==
  cd /usr/local/bin
+
It’s time to test. RTLSDR-Airband must run as root in order to have access to the GPU hardware.
wget http://s.broadcastify.com/rtl_airband/rtl_airband_bcfy_v02 -O rtl_airband_bcfy
+
  sudo /usr/local/bin/rtl_airband -f
chmod +x rtl_airband_bcfy
+
You should see a readout of numbers. The numbers should be larger when a signal is detected. Check your Broadcastify stream to see if the feed is streaming live. Once you confirmed everything is working, kill the program with CTRL+C.
  
If you want to use the original working source for rtl_airband for any other distribution, please follow the instructions on the rtl_airband git source page:
+
== Create a service ==
 +
Now you will want RTLSDR-Airband to run on startup of the Pi as well as restart if there are any errors or crashes over time (bound to happen eventually). Navigate to your RTLSDR-Airband folder. It should be somewhere like this:
 +
cd /home/pi/RTLSDR-Airband/RTLSDR-Airband-3.1.0
 +
sudo nano /init.d/rtl_airband.service
 +
Now in this rtl_airband.service file, change Restart=No to
 +
Restart=on-failure
 +
and add this line directly below it
 +
RestartSec=5s
 +
Save (ctrl+x and y) and then run these commands to copy the config over and create the service:
  
https://github.com/blantonl/RTLSDR-Airband
+
sudo cp init.d/rtl_airband.service /etc/systemd/system
 +
sudo chown root.root /etc/systemd/system/rtl_airband.service
 +
sudo systemctl daemon-reload
 +
sudo systemctl enable rtl_airband
  
== Install and configure ezstream ==
+
Now to run it, you simply need to type sudo systemctl start rtl_airband or just reboot the Pi!
  
sudo apt-get install ezstream
+
== More info, expansion and troubleshooting ==
 +
Much of this information I gleaned from this very helpful tutorial:
 +
https://viatorci.com/posts/rtlsdr-police-scanner/#install-rtlsdr-airband
 +
There are so many more possibilities with this setup and you can scan, receive multiple channels within the rtl-sdr's bandpass and a multitude of other things. This page is intended to get you streaming quickly and is not intended to address all of those scenarios.
  
Create the following configuration file at '''/etc/ezstream_bcfy.xml''' and replace with your mount, password, and stream name.  If you plan on having multiple streams make sure and create a separate named configuration file (i.e.'/etc/ezstream_bcfy2.xml) for each stream and reference accordingly in your command script below.
 
  
<ezstream>
+
== Stream directly from a USB sound card ==
    <url>http://audio#.broadcastify.com:80/your_mount</url>
 
    <sourcepassword>your_source_password</sourcepassword>
 
    <format>MP3</format>
 
    <filename>stdin</filename>
 
    <svrinfoname>Stream Name</svrinfoname>
 
    <svrinfourl>http://www.broadcastify.com</svrinfourl>
 
    <svrinfogenre>Scanner</svrinfogenre>
 
    <svrinfodescription></svrinfodescription>
 
    <svrinfobitrate>16</svrinfobitrate>
 
    <svrinfochannels>1</svrinfochannels>
 
    <svrinfosamplerate>22050</svrinfosamplerate>
 
    <svrinfopublic>0</svrinfopublic>
 
</ezstream>
 
 
 
== Use rtl_airband to Stream AM Aviation ==
 
 
 
'''''rtl_airband is the recommend method for feeding an AM Aviation feed to Broadcastify using the Raspberry Pi and an RTL stick.'''''
 
 
 
Create this configuration file below and save to '''/etc/rtlairband2_config.txt''' - configure it appropriate to your setup.
 
 
 
The example config below monitors 119.8 MHz AM, with a gain of -35.0db and broadcasts to mount point /999888777 on Broadcastify using the feed's assigned master server audio3.broadcastify.com and a source password of "coolpassword" - -15000 is the frequency correction which works well with most rtl devices.  Adjust between -5000 and -20000 to fix any frequency offset issues (a whine on the feed etc).  You can also adjust the gain between 200 and 496 (-20.0db and -49.6db) based on your local setup. 
 
 
 
1
 
0      1      350    119800000      -15000
 
audio3.broadcastify.com 80      999888777      119800000      source  coolpassword
 
 
 
For a more advanced configuration, including multiple feeds and frequencies using the same dongle and multiple dongles, please see the documentation for rtl_airband at https://github.com/szpajder/RTLSDR-Airband
 
 
 
After creating the configuration file, start rtl_airband_bcfy
 
 
 
sudo su -
 
mknod char_dev c 249 0
 
/usr/local/bin/rtl_airband_bcfy &
 
 
 
You should now be streaming the configured AM aviation frequency to broadcastify
 
 
 
== Use rtl_fm for AM Aviation Scanning and Streaming ==
 
  
/usr/local/bin/rtl_fm -M am -f 124.55M -f 133.4M -f 121.6M -l 65 -p 69 -g 40 -t 0 -E pad -s 8k -|
+
'''THIS INFORMATION MAY BE OUTDATED'''
lame -r -s 8 -m m -b 16 --cbr --lowpass 4 --scale 16 - - |
 
ezstream -c /etc/ezstream_bcfy.xml > /var/log/bcfy.log 2>&1 &
 
 
 
rtl_fm - command line tuner for rt stick
 
 
 
rtl_fm
 
-d 0          device 0 (first rtl stick, second rtl stick would be -d 1)
 
-M am          tune to AM Mode
 
-f 124.55M      tune to 124.55 MHz (use multiple -f entries to scan through frequencies)
 
-l 65          set scanning squelch to 65 (adjust as needed)
 
-p 69          ppm offset (adjust as needed for your dongle)
 
-g 40.2        gain (0-49.6) - adjust as needed
 
-t 0            scanning delay (I set to 0, default is 10)
 
-E pad          when squelch is enabled pad output with zeros (required when broadcasting)
 
-s 8k          sample at 8k
 
 
 
which is then piped to the mp3 lame encoder...
 
 
 
lame - MP3 encoder
 
-r          accept raw data input
 
-s 8          sample in at 8k
 
-m m          encode mono
 
-b 16          encode at 16kbs bitrate
 
--cbr        use Broadcastify’s mp3 cbr standard
 
--lowpass 4  use a low pass filter of 4
 
--scale 16  turn up the volume for AM Mode
 
 
 
which is then piped to ezstream
 
 
 
ezstream -c /etc/ezstream_bcfy.xml
 
 
 
== Use rtl_fm for FM Scanning and Streaming ==
 
The following commands can be entered on one line:
 
 
 
/usr/local/bin/rtl_fm -d 0 -M fm -f 461.4M -p 69 -l 65 -g 40.2 -t 2 -E pad -s 12k -|
 
/usr/bin/lame -r -s 12 --resample 22.05 -m m -b 16 --cbr --lowpass 4 - - |
 
/usr/bin/ezstream -c /etc/ezstream_bcfy.xml > ~/bcfy2.log 2>&1 &
 
 
 
rtl_fm - command line tuner for rt stick
 
 
 
rtl_fm
 
-d 0          device 0 (first rtl stick, second rtl stick would be -d 1)
 
-M fm          tune to FM Mode
 
-f 461.4M      tune to 461.4 MHz (use multiple -f entries to scan through frequencies)
 
-l 65          set scanning squelch to 65 (adjust as needed)
 
-p 69          ppm offset (adjust as needed for your dongle)
 
-g 40.2        gain (0-49.6) - adjust as needed
 
-t 2            scanning delay (I set to 2, default is 10)
 
-E pad          when squelch is enabled pad output with zeros (required when broadcasting)
 
-s 12k          sample NFM at 12k
 
-F 0          fir_size (try adding this if you have difficulty eliminating static with squelch and gain)
 
 
 
which is then piped to the mp3 lame encoder...
 
 
 
lame - MP3 encoder
 
-r          accept raw data input
 
-s 12          input at 12k
 
--resample 22.05  resample at 22.05Khz
 
-m m          encode mono
 
-b 16          encode at 16kbs bitrate
 
--cbr        use Broadcastify’s mp3 cbr standard
 
--lowpass 4  use a low pass filter of 4
 
 
 
which is then piped to ezstream
 
 
 
ezstream -c /etc/ezstream_bcfy.xml
 
 
 
== Stream directly from a USB sound card ==
 
  
 
If you already have a scanner ready to go and just want to use the Raspberry Pi to broadcast your radio to broadcastify, simply purchase an inexpensive USB sound card dongle, plug it in to the Raspberry Pi, and follow these steps:
 
If you already have a scanner ready to go and just want to use the Raspberry Pi to broadcast your radio to broadcastify, simply purchase an inexpensive USB sound card dongle, plug it in to the Raspberry Pi, and follow these steps:

Revision as of 21:08, 10 September 2020

File:Rtl rsp bcfy.jpg
Raspberry Pi Broadcastify RTL-SDR Feed Appliance

These instructions show you how to purchase and setup a completely self contained Raspberry Pi with an RTL-SDR stick to broadcast a live audio feed to Broadcastify.com. This tutorial assumes you have a basic understanding of Linux and Raspberry Pi computers.


Purchase Equipment

RTL-SDR RTL2832U USB Stick


Raspberry Pi


Install Raspbian OS

Once you have your Raspberry Pi booted and online you may continue.

Install pre-reqs and update raspberry pi to latest version

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential libmp3lame-dev libshout3-dev libconfig++-dev
sudo apt-get install libraspberrypi-dev
sudo apt-get install libfftw3-dev
apt-get install librtlsdr-dev
install rtl-sdr
sudo reboot

Install RTLSDR-Airband

cd ~/
mkdir RTLSDR-Airband
cd RTLSDR-Airband
wget -O v3.1.0.tar.gz https://github.com/szpajder/RTLSDR-Airband/archive/v3.1.0.tar.gz
tar xvfz v3.1.0.tar.gz
cd RTLSDR-Airband-3.1.0
make PLATFORM=armv8-generic NFM=1

Let it compile until it finishes then install it ...

sudo make install

The program should now be installed to /usr/local/bin/rtl_airband. The default configuration file will be installed to /usr/local/etc/rtl_airband.conf which we will edit next.

RTLSDR-Airband Config

To edit the config file for RTLSDR-Airband enter this command:

sudo nano /usr/local/etc/rtl_airband.conf 

and paste the following into the editor

# This is a minimalistic configuration file for RTLSDR-Airband. 
# More complex configurations are possible.
# Refer to https://github.com/szpajder/RTLSDR-Airband/wiki
# for description of keywords and config syntax.
# Just a single RTL dongle with one FM channel
# sent to a single Broadcastify stream. 
# Note that the center freq is 100 KHz offset from the receive freq
# Also, you must enter your server number, mountpoint and 
# password from your Broadcastify stream "Technicals"
devices:
({
  type = "rtlsdr";
  index = 0;
  gain = 25;
  centerfreq = 153.87;
  correction = 0;
  channels:
  (
    {
      freq = 153.77;
        modulation = "nfm";
        highpass = 320;
     outputs:
        (
       {
          type = "icecast";
          server = "audio#.broadcastify.com";
          port = 80;
          mountpoint = "MOUNTPOINT";
          name = "Santa Barbara County Fire Dispatch";
          genre = "Fire";
          username = "source";
          password = "PASSWORD";
        }
      );
    }
  );
});


Run

It’s time to test. RTLSDR-Airband must run as root in order to have access to the GPU hardware.

sudo /usr/local/bin/rtl_airband -f 

You should see a readout of numbers. The numbers should be larger when a signal is detected. Check your Broadcastify stream to see if the feed is streaming live. Once you confirmed everything is working, kill the program with CTRL+C.

Create a service

Now you will want RTLSDR-Airband to run on startup of the Pi as well as restart if there are any errors or crashes over time (bound to happen eventually). Navigate to your RTLSDR-Airband folder. It should be somewhere like this:

cd /home/pi/RTLSDR-Airband/RTLSDR-Airband-3.1.0
sudo nano /init.d/rtl_airband.service

Now in this rtl_airband.service file, change Restart=No to

Restart=on-failure

and add this line directly below it

RestartSec=5s

Save (ctrl+x and y) and then run these commands to copy the config over and create the service:

sudo cp init.d/rtl_airband.service /etc/systemd/system sudo chown root.root /etc/systemd/system/rtl_airband.service sudo systemctl daemon-reload sudo systemctl enable rtl_airband

Now to run it, you simply need to type sudo systemctl start rtl_airband or just reboot the Pi!

More info, expansion and troubleshooting

Much of this information I gleaned from this very helpful tutorial: https://viatorci.com/posts/rtlsdr-police-scanner/#install-rtlsdr-airband There are so many more possibilities with this setup and you can scan, receive multiple channels within the rtl-sdr's bandpass and a multitude of other things. This page is intended to get you streaming quickly and is not intended to address all of those scenarios.


Stream directly from a USB sound card

THIS INFORMATION MAY BE OUTDATED

If you already have a scanner ready to go and just want to use the Raspberry Pi to broadcast your radio to broadcastify, simply purchase an inexpensive USB sound card dongle, plug it in to the Raspberry Pi, and follow these steps:

  • Purchase USB Soundcard Dongle: http://amzn.to/1hekylB ($1.70)
  • Install and configure ezstream with your feed's details
  • Start alsamixer
pi@raspberrypi:~# alsamixer
  • press F6, choose the "USB Headphone Set" entry
  • press your tab key to select the "Capture" device volume control
  • use your "up arrow" key to adjust the level to it's lowest level possible above 0 - (6)
  • press escape to exist alsamixer
  • run the following command to save the volume settings
sudo alsactl store
  • Run this command to start the sound card broadcast
arecord -f dat -c 1 -D hw:1,0 | \
/usr/bin/lame -r -s 48 --resample 22.05 -m m -b 16 --cbr --lowpass 4 - - | \
/usr/bin/ezstream -c /etc/ezstream_bcfy1.xml > /var/log/bcfy1.log 2>&1 &

Note: very little volume will be needed from your scanner - adjust the levels as appropriate for a good sounding feed.

Start stream on boot

Easiest way is to add your full command(s) to /etc/rc.local just before the exit 0 entry

TODO: formal startup scripts.

Verify System is running and connected

I've found that occasionally lame will crash/stop and take the feed offline (at least with my setup).

I've made a script to reboot the Pi if it happens. The script will check if the user pi is logged in - if so it won't reboot because maybe you are working on it.

Copy the script below, and create a file in /etc called checkstuff.sh

sudo nano /etc/checkstuff.sh
#!/bin/sh

PROCESS="$1"
PROCANDARGS=$*

RESULT=`who | grep pi`

if [ "${RESULT:-null}" = null ]; then
echo "Nobody logged in.  We'll check for  other stuff"
logger "checkstuff: Nobody logged in.  Continueing checks."
else
logger "checkstuff: Pi is logged in.  Bypass all other checks."
exit 0
fi

RESULT=`netstat -an | grep :80`

if [ "${RESULT:-null}" = null ]; then
logger "checkstuff: No connection to RadioReference.  Rebooting."
sudo reboot
else
logger "checkstuff: Connection established to RadioReference."
fi

RESULT=`pgrep rtl_fm`

if [ "${RESULT:-null}" = null ]; then
logger "checkstuff: rtl_fm not running.  Rebooting."
sudo reboot
else
logger "checkstuff: rtl_fm running."
fi

RESULT=`pgrep lame`

if [ "${RESULT:-null}" = null ]; then
logger "checkstuff: Lame not running.  Rebooting."
sudo reboot
else
echo "lame running"
logger "checkstuff: Lame running."
fi

RESULT=`pgrep ezstream`

if [ "${RESULT:-null}" = null ]; then
logger "checkstuff: EZStream not running.  Rebooting."
sudo reboot
else
logger "checkstuff: EZStream running."
fi

logger "checkstuff: Feed should be online."

Save the file and exit nano.

Now the file needs to be made executable:

sudo chmod 755 /etc/checkstuff.sh

You now need to set up a schedule to run the script. I've set mine to run automatically every 10 minutes. This can be done by updating the cron jobs:

sudo crontab -e

Paste the following lines at the bottom.

*/10 * * * * /etc/checkstuff.sh

Save & exit the file. The script will now run every 10 minutes (at x:00, x:10, x:20, x:30, x:40 and x:50). It will log to the /var/log/messages logfile every time it runs.


Also refer to another thread postings ... https://wiki.radioreference.com/index.php/Broadcastify/RTLSDR-Airband