This guide is outdated.Please go to
https://github.com/tim273/weather_radio_scripts instead as this guide will no longer be updated.
IntroductionThis is a guide to set up NOAA streaming weather radio using a Raspberry Pi and an RTL SDR stick. The advantages to using a Raspberry Pi over Windows is that Raspberry Pi primary runs Linux and Linux is ideal for 24/7 type servers where as Windows is not. Linux can run days, weeks or even months without needing to be restarted as it was designed to be used this way. It doesn't have the problem of restarting on you or going to sleep and you don't need an entire computer dedicated to streaming. The Raspberry Pi is also very low power, maybe 5-15 watts at the most and much less depending the load and it is very small, about the size of a deck of cards so it can be put just about anywhere. The only disadvantage is that is not very powerful, it's about the equivalent of an average smart phone in power, but for the purposes of streaming no GUI is needed, so resources are not needed for that, so it has plenty of power to do what we need. The other big advantage is that all the software is free.
Note: You can also use a Raspberry Pi with just Darkice and a weather radio, the setup is similar, you would just use a weather radio instead of an RTL SDR stick. I used this setup for a few years to stream to Weather Underground (Raspberry Pi/Darkice/Weather Radio), the instructions are the same except you only need to follow the instructions to install the OS and compile/setup Darkice and skip the RTL SDR setup. You would also need an external sound card such as this one:
https://www.amazon.com/Behringer-UCA202-BEHRINGER-U-CONTROL/dp/B000KW2YEI and then an adapter for your weather radio like this:
https://www.amazon.com/gp/product/B0052A2LYG and then an RCA left/right cable. The trick is to find the right ALSA input to stream from, but I believe I used 'plughw:1,0'.
EquipmentPurchase a Raspberry Pi from Amazon:
https://www.amazon.com/CanaKit-Raspberry-Clear-Power-Supply/dp/B01C6EQNNK you'll also need a microSD card, preferably class 10
Micro Center also carries Raspberry Pi's and everything else you'll need:
MicroSD:
http://www.microcenter.com/product/366176/16GB_microSDHC_Class_10_Flash_Memory_Card (I've used Micro Center microSD cards in all my Raspberry Pi's without any problems, they're cheap and reliable. I also have a Micro Center near me though).
Raspberry Pi and Case:
http://www.microcenter.com/product/461230/Raspberry_Pi_3_Model_B_Board_and_Case_KitPower Supply:
http://www.microcenter.com/product/461596/25Amp_51v_Switching_Power_Supply_for_Raspberry_Pi_B_with_Built-in_4ft_Micro-USB_CableSince this Pi is going to be streaming 24/7, you'll also want an Ethernet cable to connect to your modem/router as WiFi is not reliable enough. Amazon or Micro Center has various lengths of Cat 5e cable at reasonable prices.
Nooelec has good RTL SDR kits, this one is fairly small and includes an antenna:
http://www.nooelec.com/store/sdr/sdr-receivers/nesdr/nesdr-mini2-rtl2832u-r820t2.html. If you can't get good reception with the included antenna, you could strip off the jacket of some standard TV coax and expose 17 1/4 inches of bare center wire, then mount that somewhere up high indoors (like an attic).
OS InstallOnce you have all that equipment download Raspbian Jessie Lite from
https://www.raspberrypi.org/downloads/raspbian and follow these instructions to put it on the microSD card:
https://www.raspberrypi.org/documentation/installation/installing-images/ Once the OS is installed on the SD card, insert it into the Pi, connect the network cable, HDMI to a monitor or TV, and a USB keyboard (mouse not needed). You can also plug in the RTL SDR and hook it up to the antenna. Finally, plug in the power.
Once booted, log in with username pi and password raspberry, then type:
sudo raspi-config
Select 5 Interfacing Options, hit Enter
Select 2 SSH, hit Enter
Select Yes to enable SSH
At the main menu, select 7 Advanced Options
Select A3 Memory Split
Type in 16 and select Ok
Optional: From the main menu
Select 2 Hostname and slelect Ok
change the hostname from "raspberrypi" to something more meaningful like "weather-radio-streamer" or whatever you choose.
Select 4 Localisation Options then I2 Change Timezone then choose your timezone (GMT is the default timezone).
Then exit out of raspi-config by selecting Finish and hit Enter. If it ask to reboot, select no or cancel as we will be rebooting later.
Next type:
ifconfig
Then take note of the IP address of eth0. From there, you no longer need the monitor/TV or keyboard and you can SSH using Putty (
http://www.putty.org/) and perform the rest of this guide remotely with SSH from a desktop/laptop.
Optional step: Create an SSH key pair so that you don't have to enter your username or password when you log in:
http://www.tecmint.com/ssh-passwordless-login-with-putty/Next update your pi:
sudo apt-get update
sudo apt-get dist-upgrade
This will take a few minutes depending on the number of updates. Once finished reboot just in case there are any kernel updates.
sudo reboot
Install PackagesWait a couple minutes and then ssh in again. Install necessary packages:
sudo apt-get install build-essential devscripts autotools-dev fakeroot dpkg-dev debhelper autotools-dev dh-make quilt ccache libsamplerate0-dev libpulse-dev libaudio-dev lame libjack-jackd2-dev libasound2-dev libtwolame-dev libfaad-dev libflac-dev libmp4v2-dev libshout3-dev libmp3lame-dev vim htop screen git icecast2 libtool-bin rtl-sdr sox libsox-fmt-mp3 ezstream iftop
When it asks about configuring Icecast, just choose the default values for now. Installing these packages will take several minutes, now would be a good time to get a coffee or take a walk or something.
Download and Compile DarkiceClone Darkice from GitHub:
git clone https://github.com/rafael2k/darkice
Compile and install Darkice (one command at a time):
cd darkice/darkice/trunk
./autogen.sh --prefix=/usr --sysconfdir=/usr/share/doc/darkice/examples --with-vorbis-prefix=/usr/lib/arm-linux-gnueabihf/ --with-jack-prefix=/usr/lib/arm-linux-gnueabihf/ --with-alsa-prefix=/usr/lib/arm-linux-gnueabihf/ --with-faac-prefix=/usr/lib/arm-linux-gnueabihf/ --with-aacplus-prefix=/usr/lib/arm-linux-gnueabihf/ --with-samplerate-prefix=/usr/lib/arm-linux-gnueabihf/ --with-lame-prefix=/usr/lib/arm-linux-gnueabihf/ CFLAGS='-march=armv6 -mfpu=vfp -mfloat-abi=hard'
make
sudo make install
Setup DarkiceI like using vim for text editing, that's just me I'm old school,

you can also use nano if you'd like. More on nano here:
https://www.howtogeek.com/howto/42980/the-beginners-guide-to-nano-the-linux-command-line-text-editor and you want to read about vim vs nano vs emacs, here you go:
http://downtoearthlinux.com/posts/clash-of-the-text-editors-nano-vim-and-emacs/Here's a quick vim rundown:
vim test.txt
i (i for insert or a for add)
Type: "Here's my text"
Esc (takes you out of insert/add mode)
:wq (w for write q for quit)
If you don't know what's going on hit Esc a few times and start over. If you make changes and screw up and don't want to save type
:q!
This will quit without saving changes. Typing : will allow you to search and do other things as well. Here's more info:
https://www.linux.com/learn/vim-101-beginners-guide-vimsudo vim /etc/darkice.cfg
add the following:
[general]
duration = 0
bufferSecs = 5
reconnect = yes
[input]
device = plughw:1,1
sampleRate = 48000
bitsPerSample = 16
channel = 1
# Primary Icecast
[icecast2-0]
bitrateMode = abr
format = mp3
bitrate = 64
server = icecast.yourserver.com
port = 8000
password = your_password
mountPoint = your/mountpoint
name = Your Weather Radio
description = NOAA Weather Radio
url = http://www.wunderground.com
genre = Weather
public = yes
#lowpass = 3000
lowpass = 3500
#lowpass = 4300
# Broadcastify/Radio Reference Icecast (if you have one, if not comment out or remove the following)
[icecast2-1]
bitrateMode = cbr
quality = 0.3
format = mp3
bitrate = 16
sampleRate = 22050
server = audio9.broadcastify.com
port = 80
password = your_password
mountPoint = your/moutpoint
name = Your Weather Radio
description = NOAA Weather Radio
url = http://www.wunderground.com
genre = Weather
public = yes
#lowpass = 3000
lowpass = 3500
#lowpass = 4300
Darkice allows you to stream to up to 8 Icecast/Shoutcast servers from a single source and each can have its own bitrate, sampleRate, etc and it will reencode from the source, they are labeled icecast2-0, icecast2-1, icecast2-2, etc. You shouldn't need more than 2, but you never know. For more info type:
man darkice.cfg
Next, modify the above and add your url, mount point, password and information. Next, add an init script for Darkice so it starts on boot:
sudo vim /etc/init.d/darkice
add the following:
#! /bin/sh
### BEGIN INIT INFO
# Provides: darkice
# Required-Start: $remote_fs $syslog $network $named $time alsa-utils
# Required-Stop: $remote_fs $syslog $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: darkice audio streamer
# Description: Darkice will take an ALSA audio input and send it to
# a streaming server.
### END INIT INFO
# or try
# Required-Start: $all
# in above header
# Author: <glyman3@gmail.com>
# Based on skelton script installed with "Raspbian", A community-created
# port of Debian wheezy, optimised for the Raspberry Pi
# This is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.#
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="darkice"
NAME=darkice
DAEMON=/usr/bin/$NAME
DAEMON_ARGS="-v10 -c /etc/darkice.cfg"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
# Read deafult configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
# Overide VERBOSE variable so that results are displayed
VERBOSE=yes
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
# and status_of_proc is working.
. /lib/lsb/init-functions
#
# Function that starts the daemon/service
#
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
start-stop-daemon --start --quiet --background --make-pidfile --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
|| return 1
#start-stop-daemon --start --quiet --background --make-pidfile --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_ARGS \
start-stop-daemon --start --quiet --make-pidfile --pidfile $PIDFILE --background --startas /bin/bash -- -c "exec darkice -v10 > /var/log/darkice.log 2>&1" \
|| return 2
# Add code here, if necessary, that waits for the process to be ready
# to handle requests from services started subsequently which depend
# on this one. As a last resort, sleep for some time.
# # If radioplay script exists & can be run then initalize it when darkice starts recording:
# [ -x "/usr/local/bin/radioplay" ] && /usr/local/bin/radioplay init
}
#
# Function that stops the daemon/service
#
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
# Wait for children to finish too if this is a daemon that forks
# and if the daemon is only ever run from this initscript.
# If the above conditions are not satisfied then add some other code
# that waits for the process to drop all resources that could be
# needed by services started subsequently. A last resort is to
# sleep for some time.
# WAS ACTIVE:
#start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
[ "$?" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
return "$RETVAL"
}
#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
#
# If the daemon can reload its configuration without
# restarting (for example, when it is sent a SIGHUP),
# then implement that here.
#
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
return 0
}
case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
status)
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
;;
reload|force-reload)
log_daemon_msg "Reloading $DESC" "$NAME"
do_reload
log_end_msg $?
;;
restart)
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
exit 3
;;
esac
Next add darkice to the services:
sudo chmod +x /etc/init.d/darkice
sudo update-rc.d darkice defaults
Setup for RTL SDRAdd the ALSA loopback plugin to the kernel modules:
sudo vim /etc/modules
add the following two lines:
snd_bcm2835
snd-aloop
Create the ALSA config file:
sudo vim /etc/asound.conf
Add the following:
pcm.duplex {
type asym
playback.pcm "hw:1,0"
capture.pcm "hw:0,0"
}
pcm.!default {
type plug
slave.pcm "duplex"
}
Next create the rules file for RTL SDR which allows the correct kernel driver to be used:
sudo vim /etc/udev/rules.d/20.rtlsdr.rules
add the following:
SUBSYSTEM=="usb", ATTRS{idVendor}=="0bda", ATTRS{idProduct}=="2838", GROUP="adm", MODE="0666", SYMLINK+="rtl_sdr"
Create a script to start RTL SDR and pipe it to the ALSA loopback card:
vim /home/pi/weather_radio.sh
and then add the following:
#!/bin/sh
# Using Sox/Play with ALSA Loopback
rtl_fm -f 162.55M -s 48000 | play -q -r 48000 -t raw -e s -b 16 -c 1 -V1 -v 6 -
In my area the weather radio frequency is 164.55Mhz, you'll want to edit this to use your local frequency. Then make it executable like this:
chmod +x /home/pi/weather_radio.sh
Next add the following to /etc/rc.local to make it run at boot:
sudo vim /etc/rc.local
add the following before exit 0:
screen -d -m /home/pi/weather_radio.sh
Finally reboot:
sudo reboot
Wait a few minutes and if all goes well, you should be able to go to
http://raspberry.pi.ip:8000 (or whatever Icecast server you are pointing to) and see your mount point and hear your weather radio stream!
Starting and Stopping ServicesThere will be two things started at boot, one is Darkice which can be started, stopped and restarted with the following commands:
sudo service darkice start
sudo service darkice stop
sudo service darkice restart
Log output for Darkice is sent to /var/log/darkice.log and can be monitored using less or tail:
tail -f /var/log/darkice.log
less -n +F /var/log/darkice.log
I prefer less as it has more features because it is an extension of vim, so it allows for searching and scrolling up and down, for more information on less vs tail see:
http://www.brianstorti.com/stop-using-tail/The second service is the screen instance with the RTL_SDR script. Darkice will stream silence to your mount point if it is running and the RTL SDR script is not, so keep that in mind if you stop or start that script. Screen is used as a "poor mans service" for the RTL SDR script (more on screen here
https://www.rackaid.com/blog/linux-screen-tutorial-and-how-to/). You can access the RTL SDR script in the screen instance by typing this:
sudo screen -r
This will bring you into the screen and you should see something like this:
Found 1 device(s):
0: Realtek, RTL2838UHIDIR, SN: 00000001
Using device 0: Generic RTL2832U OEM
Found Rafael Micro R820T tuner
Tuner gain set to automatic.
Tuner error set to 14 ppm.
Tuned to 162802000 Hz.
Oversampling input by: 21x.
Oversampling output by: 1x.
Buffer size: 8.13ms
Exact sample rate is: 1008000.009613 Hz
Sampling at 1008000 S/s.
Output at 48000 Hz.
To stop the script type Ctrl+C and this will stop the script and exit screen at the same time. You will know it exited screen when you see something like this:
[screen is terminating]
If you don't see the above then you are still in the screen instance, but have just stopped the script. If that is the case, skip the next command as it will just start a second screen instance. Otherwise to start the RTL SDR script again, type this to start a new screen instance:
sudo screen
There will be some text, and just hit enter. Then navigate (cd /home/pi or wherever you put it) to the folder with the script and execute it by typing:
./weather_radio.sh
This will bring you back to where you were and send the output of RTL SDR to the alsa loopback device. To detach from screen type Ctrl+a, d. So Ctrl+a and then d, and you should see something like this:
[detached from 3318.pts-0.weather-radio-server]
Then you can reattach the same way as mentioned above:
sudo screen -r
Don't type Ctrl+c unless you want to stop the RTL SDR script. If you want to exit out of screen completely, type Ctrl+c.
Continued in Reply #3 below.