WXforum.net

Weather Software => RaspberryPI Weather Software => Topic started by: tim273 on March 02, 2017, 08:41:34 PM

Title: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: tim273 on March 02, 2017, 08:41:34 PM
This guide is outdated.

Please go to https://github.com/tim273/weather_radio_scripts instead as this guide will no longer be updated.




Introduction

This 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'.

Equipment

Purchase 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_Kit
Power Supply: http://www.microcenter.com/product/461596/25Amp_51v_Switching_Power_Supply_for_Raspberry_Pi_B_with_Built-in_4ft_Micro-USB_Cable

Since 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 Install

Once 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:

Code: [Select]
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:

Code: [Select]
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:

Code: [Select]
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.

Code: [Select]
sudo reboot

Install Packages

Wait a couple minutes and then ssh in again.  Install necessary packages:

Code: [Select]
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 Darkice

Clone Darkice from GitHub:

Code: [Select]
git clone https://github.com/rafael2k/darkice

Compile and install Darkice (one command at a time):

Code: [Select]
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 Darkice

I like using vim for text editing, that's just me I'm old school, :grin: 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-vim

Code: [Select]
sudo vim /etc/darkice.cfg

add the following:

Code: [Select]
[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:

Code: [Select]
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:

Code: [Select]
sudo vim /etc/init.d/darkice

add the following:

Code: [Select]
#! /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:

Code: [Select]
sudo chmod +x /etc/init.d/darkice
sudo update-rc.d darkice defaults

Setup for RTL SDR

Add the ALSA loopback plugin to the kernel modules:

Code: [Select]
sudo vim /etc/modules

add the following two lines:

Code: [Select]
snd_bcm2835
snd-aloop

Create the ALSA config file:
Code: [Select]
sudo vim /etc/asound.conf

Add the following:

Code: [Select]
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:

Code: [Select]
sudo vim /etc/udev/rules.d/20.rtlsdr.rules

add the following:

Code: [Select]
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:

Code: [Select]
vim /home/pi/weather_radio.sh

and then add the following:

Code: [Select]
#!/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:

Code: [Select]
chmod +x /home/pi/weather_radio.sh

Next add the following to /etc/rc.local to make it run at boot:

Code: [Select]
sudo vim /etc/rc.local

add the following before exit 0:

Code: [Select]
screen -d -m /home/pi/weather_radio.sh

Finally reboot:

Code: [Select]
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 Services

There will be two things started at boot, one is Darkice which can be started, stopped and restarted with the following commands:

Code: [Select]
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:

Code: [Select]
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:

Code: [Select]
sudo screen -r

This will bring you into the screen and you should see something like this:

Code: [Select]
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:

Code: [Select]
[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:

Code: [Select]
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:

Code: [Select]
./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:

Code: [Select]
[detached from 3318.pts-0.weather-radio-server]

Then you can reattach the same way as mentioned above:

Code: [Select]
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.
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: 92merc on March 11, 2017, 06:53:41 PM
I'm a bit stuck at the moment.  I got to the part where you can get the -p number, but I keep getting an error:

Sat 11 Mar 17:46:24 CST 2017
Found 1 device(s):
  0:  Generic RTL2832U OEM

Using device 0: Generic RTL2832U OEM
usb_claim_interface error -6
Failed to open rtlsdr device #0.


Also, your last step doesn't mention how to "tune" your radio to the proper frequency.  I'm assuming the 162.55m is the freq I'd need to enter.
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: tim273 on March 11, 2017, 08:50:45 PM
I'm a bit stuck at the moment.  I got to the part where you can get the -p number, but I keep getting an error:

Sat 11 Mar 17:46:24 CST 2017
Found 1 device(s):
  0:  Generic RTL2832U OEM

Using device 0: Generic RTL2832U OEM
usb_claim_interface error -6
Failed to open rtlsdr device #0.


Also, your last step doesn't mention how to "tune" your radio to the proper frequency.  I'm assuming the 162.55m is the freq I'd need to enter.

It looks like that error happens when another process is using the rtl sdr, so my guess is that you have the script running in screen and you need to stop it first before trying to run it again.  So type in:

Code: [Select]
sudo screen -r

If nothing comes back, try the above without 'sudo' and then to stop it type Ctrl+c and that will stop the RTL SDR script and screen at the same time.  Then start screen again by typing:

Code: [Select]
sudo screen

It will give you some text and just hit enter and you'll be in a new screen instance.  Then run your script and type Ctrl+a, d to detach from the screen, then to reattach type:

Code: [Select]
sudo screen -r

again. 

Hope that helps.  I updated the post above with that information.
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: tim273 on March 11, 2017, 09:18:34 PM
Optional (but recommended): PPM Error Correction

Since the RTL SDR sticks are made with super cheap crystals sometimes the frequency needs to be corrected. Before doing this, stop the RTL SDR script as mentioned above.  Here's a guide to show you how to do that: http://314256.blogspot.com/2015/03/how-to-use-kal-software-to-workout-ppm.html  In addition to the packages it has you install, add these:

Code: [Select]
sudo apt-get install librtlsdr-dev usb-1.0

Then modify weather_radio.sh to look like this:

Code: [Select]
#!/bin/sh

# Using Sox/Play with ALSA Loopback
rtl_fm -f 162.55M -s 48000 -p 14 | play -q -r 48000 -t raw -e s -b 16 -c 1 -V1 -v 6 -

Note the addition of "-p 14" use whatever number is calculated from the instructions.  Then restart the RTL SDR script as mentioned above.

Optional: Purchase a UPS (Uninterruptible Power Supply)

Since power outages often occur with sever weather, a UPS would be a good purchase to keep the weather radio setup running during a power outage.  At minimum, plug in the Raspberry Pi, modem (from whatever type of ISP you have),  and router (if you have one).  It could be that the router and modem are one unit, in which case only the router/modem and Raspberry Pi need to be plugged in.  The power consumption of these two or three units will be fairly low, around 10-20 watts which will allow the UPS to work for 1-3 hours depending on the size.  Search Amazon for Uninterruptible Power Supply to find options, APC is generally a good brand.

Notes on Reception

If you are finding that you cannot get a good signal, here's some tips to improve that. 

Optional: Create a script to monitor the uptime

Sometimes the weather radio will go down for various reasons, network issues, the Icecast server goes down, etc.  One way to monitor this is to create a script to check that the stream is mounted on the Icecast server, and to send an email when it's down.  It would be best to run this script from an outside source.  For exmaple, I have my Icecast server on a Linode instance and I have it checked from a separate Linode instance.  If this is not possible, just run it on your Raspberry Pi, which is better than nothing.

First follow this tutorial:  https://www.howtoforge.com/tutorial/configure-postfix-to-use-gmail-as-a-mail-relay to get Gmail set up as a relay.

Then create a script to check your mount point:

Code: [Select]
#!/bin/bash

#url="http://audioplayer.wunderground.com"
url="http://your_icecast_url:8000"
#status_code=$(curl -o /dev/null --silent --write-out '%{http_code}\n' $url)
status_code=$(curl -v --silent $url 2>&1 | grep your/moutpoint)
date=`date`

if [ "$status_code" == "" ]
then
        #echo "The weather radio is down at $date" >> /var/log/status_check.log
        mail -s "Weather Radio is Down" your@email.com <<< "The weather radio is down at $date."
fi

and save it as check_weather_radio.sh or something similar.  Then add a cron to run every 15 or 30 minutes (mine is every 15):

Code: [Select]
crontab -e

Add the following:

Code: [Select]
*/15 * * * * /path/to/check-weather-radio

This is opened in nano so type Ctrl+o to save (hit enter when it asks what file to save as) and Ctrl+x to exit.  If all went well you should see:

Code: [Select]
crontab: installing new crontab

Then you can type crontab -e again and you should still see the line you added.  You can test this by stopping Darkice and waiting 15-30 minutes to see if there's an email.

Recommended: Software Updates

Occasionally there are software updates which the repository will handle for you.  To update log in and type:

Code: [Select]
sudo apt-get update

and

Code: [Select]
sudo apt-get dist-upgrade

It's usually good to do this about once a week, sometimes the Pi will need to be rebooted, but usually only if there is a kernel update.

Recommended: Checking Logs

The darkice output will be sent to /var/log/darkice.log and it's good to check this from time to time.  Occasonally you'll see something like this in the log:

Code: [Select]

16-Mar-2017 11:45:21 BufferedSink, healed: 0  /  480000
16-Mar-2017 11:45:23 BufferedSink, healed: 0  /  480000
16-Mar-2017 11:56:03 BufferedSink, new peak: 169  /  480000
16-Mar-2017 11:56:03 BufferedSink, new peak: 506  /  480000
16-Mar-2017 11:56:03 BufferedSink, new peak: 1215  /  480000
16-Mar-2017 11:56:03 BufferedSink, new peak: 2762  /  480000
16-Mar-2017 11:56:03 BufferedSink, new peak: 5530  /  480000
16-Mar-2017 11:56:04 BufferedSink, new peak: 11062  /  480000
16-Mar-2017 11:56:06 BufferedSink, new peak: 22231  /  480000
16-Mar-2017 11:56:06 BufferedSink, new peak: 55  /  480000
16-Mar-2017 11:56:07 BufferedSink, new peak: 198  /  480000
16-Mar-2017 11:56:07 BufferedSink, new peak: 410  /  480000
16-Mar-2017 11:56:07 BufferedSink, new peak: 938  /  480000
16-Mar-2017 11:56:07 BufferedSink, new peak: 1919  /  480000
16-Mar-2017 11:56:08 BufferedSink, new peak: 3858  /  480000
16-Mar-2017 11:56:09 BufferedSink, new peak: 44525  /  480000
16-Mar-2017 11:56:09 BufferedSink, new peak: 7754  /  480000
16-Mar-2017 11:56:12 BufferedSink, new peak: 15531  /  480000
16-Mar-2017 11:56:15 BufferedSink, new peak: 89148  /  480000
16-Mar-2017 11:56:17 BufferedSink, new peak: 31153  /  480000
16-Mar-2017 11:56:18 TcpSocket :: write, send error 32
16-Mar-2017 11:56:18 Exception caught in BufferedSink :: write1
16-Mar-2017 11:56:18 HTTP/1.0 200
16-Mar-2017 11:56:28 BufferedSink, healed: 0  /  480000
16-Mar-2017 11:56:32 BufferedSink, healed: 0  /  480000
16-Mar-2017 12:13:35 BufferedSink, new peak: 347  /  480000
16-Mar-2017 12:13:35 BufferedSink, healed: 0  /  480000

This is darkice dealing with network issues, but if you see multiple messages that say "buffer overrun" then first restart darikce (see post 1) and if that doesn't fix it, there could be issues with your internet connection.  You may need to restart your router and/or modem to fix these, otherwise contact your ISP.

Optional: Run Your Icecast Server Externally

If you're worried about your bandwidth or your ISP has limitations Linode (http://www.linode.com/) has a number of inexpensive options that can be used to set up an Icecast server, starting at $5 a month for 1TB of data transfer (both in and out).  When setting up the Linode, choose the latest Ubuntu LTS release.  Setup will be similar to the Raspberry Pi, except there is no raspi-config utility, but it uses the same apt-get utility and has all the same tools.  Icecast can be installed by running this:

Code: [Select]
sudo apt-get install icecast2

You'll also need to register a domain and tie it to the IP address. That's not absolutely necessary, but otherwise you would just use your IP address to access the Icecast server, not pretty, but it works.  Then you would just send your stream to your Linode Icecast server.
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: 92merc on March 13, 2017, 05:25:24 PM
If I wanted to turn down the volume just a bit on the stream, is it one of these options I need to change?  I'm guessing one of the last numbers.

rtl_fm -f 162.55M -s 48000 | play -q -r 48000 -t raw -e s -b 16 -c 1 -V1 -v 6 -
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: tim273 on March 13, 2017, 05:58:48 PM
If I wanted to turn down the volume just a bit on the stream, is it one of these options I need to change?  I'm guessing one of the last numbers.

rtl_fm -f 162.55M -s 48000 | play -q -r 48000 -t raw -e s -b 16 -c 1 -V1 -v 6 -

Yep it's -v 6, so change it to -v 5 or -v 4.
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: gwwilk on April 02, 2017, 03:15:29 PM
Trying this rather complex Raspberry Pi trick, but I'm not getting a stream for some reason.

This is my 'screen':
Code: [Select]
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 -6 ppm.
Tuned to 162727000 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.

As you can see the tuner is tuned to 162.727 MHz, but I've set it to 162.475 MHz in 'weather_radio.sh':
Code: [Select]
#!/bin/sh

# Using Sox/Play with ALSA Loopback
rtl_fm -f 162.475M -s 48000 -p -6 | play -q -r 48000 -t raw -e s -b 16 -c 1 -V1 -v 6 -
When I log onto my icecast server as 'admin' with the password I set as 'hackme', this is what shows:

 [ You are not allowed to view attachments ]

There is no mountpoint:

 [ You are not allowed to view attachments ]

I'm not sure what the mountpoint, etc. should be.  Here are my entries in 'darkice.cfg':
Code: [Select]
[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        = 192.168.2.124
port          = 8000
password      = hackme
mountPoint    = raspi
name          = Raspi
description   = NOAA Weather Radio
url           = http://localhost

I've never been very fluent in 'Linux Speak', but I've gotten this far by following your instructions.  I also tried to set icecast's output port to '8002' with no success.  Lotsa gotcha's here for me apparently.
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: tim273 on April 02, 2017, 04:37:14 PM
Looks like an issue with Darkice, check your log file:

Code: [Select]
less -n +F /var/log/darkice.log

It could be that it can't find the sound card input, or it can't find the Icecast server.
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: gwwilk on April 02, 2017, 04:38:43 PM
Looks like an issue with Darkice, check your log file:

Code: [Select]
less -n +F /var/log/darkice.log

It could be that it can't find the sound card input, or it can't find the Icecast server.
Thanks, you may be right.  I get this:
Code: [Select]
pi@GWWilkinsNOAARadioServer:~ $ less -n +F /var/log/darkice.log
/var/log/darkice.log: No such file or directory
pi@GWWilkinsNOAARadioServer:~ $

How to fix?

(I finally found how to enable my Pi 3's wifi, so I've removed the ethernet tether.)
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: tim273 on April 02, 2017, 04:41:21 PM
Looks like an issue with Darkice, check your log file:

Code: [Select]
less -n +F /var/log/darkice.log

It could be that it can't find the sound card input, or it can't find the Icecast server.
Thanks, you may be right.  I get this:
Code: [Select]
pi@GWWilkinsNOAARadioServer:~ $ less -n +F /var/log/darkice.log
/var/log/darkice.log: No such file or directory
pi@GWWilkinsNOAARadioServer:~ $

How to fix?

A couple things, first if your Icecast server is on your local Raspberry Pi, you can just use localhost for the server, you don't need your IP.

I'm wondering if Darkice didn't start, so try

Code: [Select]
sudo service darkice start

and then try looking at the log again.
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: gwwilk on April 02, 2017, 04:43:18 PM
I get this:
Code: [Select]
pi@GWWilkinsNOAARadioServer:~ $ sudo service darkice start
Job for darkice.service failed. See 'systemctl status darkice.service' and 'journalctl -xn' for details.
I've also tried those commands before, to no avail.
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: tim273 on April 02, 2017, 04:46:13 PM
Ok, try this:

Code: [Select]
sudo /etc/init.d/darkice start

If that doesn't work, just try typing this just to see if it works at all:

Code: [Select]
darkice -v10

If the second one works, then it's just an issue of the service not being set up.
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: gwwilk on April 02, 2017, 04:47:52 PM
Ok, try this:

Code: [Select]
sudo /etc/init.d/darkice start

If that doesn't work, just try typing this just to see if it works at all:

Code: [Select]
darkice -v10

If the second one works, then it's just an issue of the service not being set up.
Here's the result:
Code: [Select]
pi@GWWilkinsNOAARadioServer:~ $ darkice -v10
DarkIce 1.3 live audio streamer, http://code.google.com/p/darkice/
Copyright (c) 2000-2007, Tyrell Hungary, http://tyrell.hu/
Copyright (c) 2008-2013, Akos Maroy and Rafael Diniz
This is free software, and you are welcome to redistribute it
under the terms of The GNU General Public License version 3 or
any later version.

Using config file: /etc/darkice.cfg
02-Apr-2017 15:47:09 Using ALSA DSP input device: plughw:1,1
02-Apr-2017 15:47:09 buffer size:  480000
02-Apr-2017 15:47:09 encoding
02-Apr-2017 15:47:09 scheduler high priority 99
02-Apr-2017 15:47:09 Could not set POSIX real-time scheduling, this may cause recording skips.
Try to run darkice as the super-user.
DarkIce: TcpSocket.cpp:251: connect error [113]
02-Apr-2017 15:47:15 BufferedSink :: write, couldn't reopen underlying sink, attempt 1 / 10
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: gwwilk on April 02, 2017, 04:50:32 PM
Here it is again with 'sudo':
Code: [Select]
pi@GWWilkinsNOAARadioServer:~ $ sudo darkice -v10
DarkIce 1.3 live audio streamer, http://code.google.com/p/darkice/
Copyright (c) 2000-2007, Tyrell Hungary, http://tyrell.hu/
Copyright (c) 2008-2013, Akos Maroy and Rafael Diniz
This is free software, and you are welcome to redistribute it
under the terms of The GNU General Public License version 3 or
any later version.

Using config file: /etc/darkice.cfg
02-Apr-2017 15:49:06 Using ALSA DSP input device: plughw:1,1
02-Apr-2017 15:49:06 buffer size:  480000
02-Apr-2017 15:49:06 encoding
02-Apr-2017 15:49:06 scheduler high priority 99
02-Apr-2017 15:49:06 Using POSIX real-time scheduling, priority 4
DarkIce: TcpSocket.cpp:251: connect error [113]
02-Apr-2017 15:49:12 BufferedSink :: write, couldn't reopen underlying sink, attempt 1 / 10
p
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: tim273 on April 02, 2017, 04:53:04 PM
That's odd, I haven't seen that one before. At this point, if it were me, I would just start over.  Don't feel bad that you didn't get it the first time, I've had to start over many times when I've done stuff with the Raspberry Pi, sometimes it just doesn't work out.  Maybe something got missed, I don't know, but that's my best advice. 

Ironically, I had to start over with mine today because something got messed up.
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: gwwilk on April 02, 2017, 04:54:44 PM
That's odd, I haven't seen that one before. At this point, if it were me, I would just start over.  Don't feel bad that you didn't get it the first time, I've had to start over many times when I've done stuff with the Raspberry Pi, sometimes it just doesn't work out.  Maybe something got missed, I don't know, but that's my best advice.
Start over where?  Format the Micro-SD?  Just try to reinstall the packages over those already present?
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: tim273 on April 02, 2017, 05:00:57 PM
Ok, a couple options, if you are planning to just stream to one destination, not multiple, you could use ezstream, more info on that here: http://icecast.org/ezstream.  Otherwise you could just recompile darkice and see if that works.

If you want to try ezstream, you could use this for your script:

Code: [Select]
rtl_fm -f 162.55M -s 48000 -p 14 | lame --bitwidth 16 --signed -s 48000 --lowpass 3500 --abr 64 --scale 9 -r -m m - - | ezstream -c ezstream.xml

and here's the ezstream.xml file

Code: [Select]
<!--
   EXAMPLE: MP3 playlist stream WITHOUT reencoding

   This example streams a playlist that contains only MP3 files. No other file
   formats may be listed. Since ezstream will not be doing any reencoding, the
   resulting stream format (bitrate, samplerate, channels) will be of the
   respective input files.
 -->
<ezstream>
    <url>http://localhost:8000/mount</url>
    <sourcepassword>password</sourcepassword>
    <format>MP3</format>
    <filename>stdin</filename>
    <stream_once>1</stream_once>
    <!--
      The following settings are used to describe your stream to the server.
      It's up to you to make sure that the bitrate/samplerate/channels
      information matches up with your input stream files. Note that
      <svrinfoquality /> only applies to Ogg Vorbis streams.
     -->
    <svrinfoname>Minneapolis, Minnesota Weather Radio</svrinfoname>
    <svrinfourl>http://www.wunderground.com</svrinfourl>
    <svrinfogenre>Weather</svrinfogenre>
    <svrinfodescription>NOAA Weather Radio KEC65 162.55Mhz</svrinfodescription>
    <svrinfobitrate>64</svrinfobitrate>
    <svrinfochannels>2</svrinfochannels>
    <svrinfosamplerate>48000</svrinfosamplerate>
    <!--
      Prohibit the server to advertise the stream on a public YP directory:
     -->
    <svrinfopublic>0</svrinfopublic>
</ezstream>


Obviously, change the info.  If that doesn't work, then I would reformat the microSD card and start over that way.
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: gwwilk on April 02, 2017, 05:06:02 PM
I don't know how to 'recompile' darkice.  Any advice?
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: tim273 on April 02, 2017, 05:08:03 PM
I don't know how to 'recompile' darkice.  Any advice?
It's in the original instructions at to top.

Sent from my SGH-M919 using Tapatalk

Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: gwwilk on April 02, 2017, 05:09:31 PM
I don't know how to 'recompile' darkice.  Any advice?
It's in the original instructions at to top.
You mean this?
Code: [Select]
pi@GWWilkinsNOAARadioServer:~ $ git clone https://github.com/rafael2k/darkice
fatal: destination path 'darkice' already exists and is not an empty directory.
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: tim273 on April 02, 2017, 05:10:49 PM
I don't know how to 'recompile' darkice.  Any advice?
It's in the original instructions at to top.
You mean this?
Code: [Select]
pi@GWWilkinsNOAARadioServer:~ $ git clone https://github.com/rafael2k/darkice
fatal: destination path 'darkice' already exists and is not an empty directory.
The part after that.

Sent from my SGH-M919 using Tapatalk

Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: gwwilk on April 02, 2017, 05:38:37 PM
I now get this:
Code: [Select]
pi@GWWilkinsNOAARadioServer:~ $ sudo darkice -v10
DarkIce 1.3 live audio streamer, http://code.google.com/p/darkice/
Copyright (c) 2000-2007, Tyrell Hungary, http://tyrell.hu/
Copyright (c) 2008-2013, Akos Maroy and Rafael Diniz
This is free software, and you are welcome to redistribute it
under the terms of The GNU General Public License version 3 or
any later version.

Using config file: /etc/darkice.cfg
02-Apr-2017 16:35:05 Using ALSA DSP input device: plughw:1,1
02-Apr-2017 16:35:05 buffer size:  480000
02-Apr-2017 16:35:05 encoding
02-Apr-2017 16:35:05 scheduler high priority 99
02-Apr-2017 16:35:05 Using POSIX real-time scheduling, priority 4
02-Apr-2017 16:35:05 HTTP/1.0 200
02-Apr-2017 16:35:05 set lame mode 3
02-Apr-2017 16:35:05 set lame channels 1
02-Apr-2017 16:35:05 set lame in sample rate 48000
02-Apr-2017 16:35:05 set lame out sample rate 48000
02-Apr-2017 16:35:05 set lame abr bitrate 3
02-Apr-2017 16:35:05 set lame abr mean bitrate 64
02-Apr-2017 16:35:05 set lame lowpass frequency 3500
02-Apr-2017 16:35:05 set lame highpass frequency 0
02-Apr-2017 16:35:05 set lame psycho acoustic model 1
02-Apr-2017 16:35:05 set lame error protection 1
LAME 3.99.5 32bits (http://lame.sf.net)
Using polyphase lowpass filter, transition band:  3290 Hz -  3871 Hz
02-Apr-2017 16:35:05 MultiThreadedConnector :: transfer, bytes 0
02-Apr-2017 16:35:05 MultiThreadedConnector :: ThreadData :: threadFunction, was (thread, priority, type):  0xebcad8 4 SCHED_FIFO
02-Apr-2017 16:35:05 MultiThreadedConnector :: ThreadData :: threadFunction, now is (thread, priority, type):  0xebcad8 1 SCHED_FIFO

I have a mountpoint and a very static-ridden radio!

Thanks, Tim! :-)  Gonna take a break.
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: tim273 on April 02, 2017, 06:03:51 PM
Great!  Glad you got it working.
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: saratogaWX on April 03, 2017, 01:27:49 PM
Sadness.. I rebuilt the RP3 using the full instructions in the first post.  Now I see what Jerry saw
Code: [Select]
$ sudo darkice -v10
DarkIce 1.3 live audio streamer, http://code.google.com/p/darkice/
Copyright (c) 2000-2007, Tyrell Hungary, http://tyrell.hu/
Copyright (c) 2008-2013, Akos Maroy and Rafael Diniz
This is free software, and you are welcome to redistribute it
under the terms of The GNU General Public License version 3 or
any later version.

Using config file: /etc/darkice.cfg
03-Apr-2017 10:25:22 Using ALSA DSP input device: plughw:1,1
03-Apr-2017 10:25:22 buffer size:  480000
03-Apr-2017 10:25:22 buffer size:  480000
03-Apr-2017 10:25:22 encoding
03-Apr-2017 10:25:22 scheduler high priority 99
03-Apr-2017 10:25:22 Using POSIX real-time scheduling, priority 4
DarkIce: TcpSocket.cpp:251: connect error [111]
03-Apr-2017 10:25:22 HTTP/1.0 200
03-Apr-2017 10:25:22 BufferedSink :: write, couldn't reopen underlying sink, attempt 1 / 10
I didn't see what was done to resolve that.. I'd like to continue to use icecast2 and not switch to easystream unless necessary.
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: tim273 on April 03, 2017, 01:34:10 PM
Sadness.. I rebuilt the RP3 using the full instructions in the first post.  Now I see what Jerry saw
Code: [Select]
$ sudo darkice -v10
DarkIce 1.3 live audio streamer, http://code.google.com/p/darkice/
Copyright (c) 2000-2007, Tyrell Hungary, http://tyrell.hu/
Copyright (c) 2008-2013, Akos Maroy and Rafael Diniz
This is free software, and you are welcome to redistribute it
under the terms of The GNU General Public License version 3 or
any later version.

Using config file: /etc/darkice.cfg
03-Apr-2017 10:25:22 Using ALSA DSP input device: plughw:1,1
03-Apr-2017 10:25:22 buffer size:  480000
03-Apr-2017 10:25:22 buffer size:  480000
03-Apr-2017 10:25:22 encoding
03-Apr-2017 10:25:22 scheduler high priority 99
03-Apr-2017 10:25:22 Using POSIX real-time scheduling, priority 4
DarkIce: TcpSocket.cpp:251: connect error [111]
03-Apr-2017 10:25:22 HTTP/1.0 200
03-Apr-2017 10:25:22 BufferedSink :: write, couldn't reopen underlying sink, attempt 1 / 10
I didn't see what was done to resolve that.. I'd like to continue to use icecast2 and not switch to easystream unless necessary.

Actually ezstream the equivalent of Darkice, the only difference is that Darkice can stream to multiple Icecast2 servers (as well as Shoutcast), where as ezstream only streams to one Icecast2 server.

But to answer your question, he had to recompile Darkice and that seemed to do it.
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: saratogaWX on April 03, 2017, 01:38:51 PM
Ok, thanks for the explanation.  I think I'd like to continue using Darkice as I'd like to stream to the local icecast2 and to the wxradio.dyndns.org Icecast server with a new stream.

So.. what diagnostics do I need to get darkice to not have the TcpSocket connect error (and to actually run)?
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: tim273 on April 03, 2017, 01:44:00 PM
I took my instructions from this page: https://stmllr.net/blog/live-mp3-streaming-from-audio-in-with-darkice-and-icecast2-on-raspberry-pi/, in comment 20 at the bottom of the page someone has the same error, maybe start there.

It could be that you just need to comment out the second Icecast2 server setup in darkice.cfg and see if you can get just one to work.
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: gwwilk on April 03, 2017, 05:52:11 PM
I've found a strange business with the frequency selection. This is my /home/pi/weather_radio.sh file:
Code: [Select]
#!/bin/sh

# Using Sox/Play with ALSA Loopback
rtl_fm -f 162.475M -s 48000 | play -q -r 48000 -t raw -e s -b 16 -c 1 -V1 -v 6 -
but this is my screen:
Code: [Select]
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.
Tuned to 162727000 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.

As you can see the tuner is set to 162.727MHz despite calling for 162.475M.  I'm not sure why this is, but my tuner is very scratchy and full of static like it's mistuned and needs refinement.  I've tried using kal but there aren't any consistent GSM base stations that I'm receiving because I'm in a cell relative dead zone and use calling over IP for my cell.

BTW I found this missing from the top of my /etc/init.d/darkice:
Code: [Select]
#! /bin/sh
### BEGI
Pasting it in solved my problem with the missing mountpoint.  I must have been really clumsy when I set this file up. :oops:
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: tim273 on April 03, 2017, 05:58:07 PM
I've found a strange business with the frequency selection. This is my /home/pi/weather_radio.sh file:
Code: [Select]
#!/bin/sh

# Using Sox/Play with ALSA Loopback
rtl_fm -f 162.475M -s 48000 | play -q -r 48000 -t raw -e s -b 16 -c 1 -V1 -v 6 -
but this is my screen:
Code: [Select]
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.
Tuned to 162727000 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.

As you can see the tuner is set to 162.727MHz despite calling for 162.475M.  I'm not sure why this is, but my tuner is very scratchy and full of static like it's mistuned and needs refinement.  I've tried using kal but there aren't any consistent GSM base stations that I'm receiving because I'm in a cell relative dead zone and use calling over IP for my cell.

BTW I found this missing from the top of my /etc/init.d/darkice:
Code: [Select]
#! /bin/sh
### BEGI
Pasting it in solved my problem with the missing mountpoint.  I must have been really clumsy when I set this file up. :oops:

Mine is like that too, I'm not sure why, but it's right.  For doing the PPM error correction another option you could do on a Windows machine is use SDRSharp (http://airspy.com/download/ - it's the "core SDR package") and that will give you a better idea.  Here's a guide to set that up: http://www.rtl-sdr.com/rtl-sdr-quick-start-guide/ then you can visually see the signal and adjust the PPM that way.
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: gwwilk on April 03, 2017, 06:26:42 PM
I've ordered a new tuner from NooElec (http://www.nooelec.com/store/sdr/sdr-receivers/nesdr-mini-2-plus.html) that's been tested to be within spec.  We'll see if it helps.  My NOAA Weather Radios all get a clean, clear signal here without extending the antenna or even pulling it up to vertical, so I don't think signal quality should be an issue.
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: tim273 on April 03, 2017, 06:34:15 PM
I've ordered a new tuner from NooElec (http://www.nooelec.com/store/sdr/sdr-receivers/nesdr-mini-2-plus.html) that's been tested to be within spec.  We'll see if it helps.  My NOAA Weather Radios all get a clean, clear signal here without extending the antenna or even pulling it up to vertical, so I don't think signal quality should be an issue.

That works.  Two things to keep in mind, the first is that the RTL SDR dongles use very cheap crystals and because of that these issues happen.  The other thing is that you can still use a regular weather radio with Darkice (or even ezstream) as it just listens to the sound card input, you just need an external sound card.  I was doing that (Raspberry Pi/Weather Radio/Darkice) for a few years when I was streaming to WU.  I updated my post to cover how to do that.
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: satcop on April 03, 2017, 08:01:53 PM
Hi Tim;

I was trying to get two streams to self start from boot but having no joy.  It seems that darkice dumps when the rtl sdr stream is turned on.  After boot I can get both feeds to work, providing I do a sudo screen -r , than get out of that screen with a control a d and than do a sudo darkice start.  At that point both streams work.  If I don't look at the feed with the  sudo screen -r than darkice comes up but with no audio.

Bob
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: tim273 on April 03, 2017, 10:42:41 PM
Hi Tim;

I was trying to get two streams to self start from boot but having no joy.  It seems that darkice dumps when the rtl sdr stream is turned on.  After boot I can get both feeds to work, providing I do a sudo screen -r , than get out of that screen with a control a d and than do a sudo darkice start.  At that point both streams work.  If I don't look at the feed with the  sudo screen -r than darkice comes up but with no audio.

Bob

I've been having a similar problem, but I had it working before, let me look it up and I'll get back to you.  As long as you get it working, that's good, you rarely need to reboot the Pi.  I've had Raspberry Pi's up for a month or more without rebooting.
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: tim273 on April 06, 2017, 02:33:44 PM
Hi Everyone,

I've copied over my Raspberry Pi tutorial over to Github:

https://github.com/tim273/weather_radio_scripts

I've also put all the stuff (well almost) in there so all you won't have to copy/paste as much.  Hopefully that makes it a little easier.
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: gwwilk on April 08, 2017, 05:14:53 PM
Just got my new tuner for the Raspberry Pi today.  Wow!  What a difference!  The stream is very listenable, and now I want to stream it as an alternate.  I would definitely urge anyone who is contemplating going this route to buy the 'Plus' (https://www.amazon.com/NooElec-NESDR-Mini-Receiver-RTL2832U/dp/B00VZ1AWQA/ref=sr_1_2?ie=UTF8&qid=1491685644&sr=8-2&keywords=nooelec) factory verified version.

I'm still not able to switch to a port other than 8000, which is a problem since I'm using that port through my firewall for my wxradio.dyndns.org feed from a weather radio. :-(

Why won't the port switch to something like 86 or 8500 when I set it to that in 'etc/darkice.cfg'?  Is there another setting that I need to use as well?  When I switch to another port using 'etc/darkice.cfg' I'm no longer able to use Chrome to access the Raspberry Pi through the new port.  When I switch 'etc/darkice.cfg back to port 8000, all is well.
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: tim273 on April 08, 2017, 06:36:21 PM
Just got my new tuner for the Raspberry Pi today.  Wow!  What a difference!  The stream is very listenable, and now I want to stream it as an alternate.  I would definitely urge anyone who is contemplating going this route to buy the 'Plus' (https://www.amazon.com/NooElec-NESDR-Mini-Receiver-RTL2832U/dp/B00VZ1AWQA/ref=sr_1_2?ie=UTF8&qid=1491685644&sr=8-2&keywords=nooelec) factory verified version.

I'm still not able to switch to a port other than 8000, which is a problem since I'm using that port through my firewall for my wxradio.dyndns.org feed from a weather radio. :-(

Why won't the port switch to something like 86 or 8500 when I set it to that in 'etc/darkice.cfg'?  Is there another setting that I need to use as well?  When I switch to another port using 'etc/darkice.cfg' I'm no longer able to use Chrome to access the Raspberry Pi through the new port.  When I switch 'etc/darkice.cfg back to port 8000, all is well.

I have the same RTL SDR stick and it does make a difference, I also switched to a ground plane antenna and that helped too.

If you're running an Icecast2 server locally, you can change the port there and then match it in your darkice.cfg.  The icecast config file is /etc/icecast2/icecast.xml  and in mine the port is on line 61.  Look for this:

Code: [Select]
<!-- You may have multiple <listener> elements -->
    <listen-socket>
        <port>8000</port>
        <!-- <bind-address>127.0.0.1</bind-address> -->
        <!-- <shoutcast-mount>/stream</shoutcast-mount> -->
    </listen-socket>
    <!--
    <listen-socket>
        <port>8001</port>
    </listen-socket>
    -->

Then just change port 8000 to what you want and then change darkice.cfg to match.  Hopefully that should do it.  Then just restart both

Code: [Select]
sudo service icecast2 restart
sudo service darkice restart
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: gwwilk on April 08, 2017, 07:24:14 PM
Thanks for the reply, Tim.  Changing the port to 88 in both darkice.cfg and icecast.xml leaves me unable to reconnect at 192.168.2.161:88 whereas before the change 192.168.2.161:8000 brought up the icecast2 status with links to the stream in 3 formats.  Perhaps I'm making this too difficult?
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: tim273 on April 08, 2017, 08:38:48 PM
Thanks for the reply, Tim.  Changing the port to 88 in both darkice.cfg and icecast.xml leaves me unable to reconnect at 192.168.2.161:88 whereas before the change 192.168.2.161:8000 brought up the icecast2 status with links to the stream in 3 formats.  Perhaps I'm making this too difficult?

Ok, I guess I'm not sure then, I thought that would do it, but I'm not sure, I haven't done that before, but here's more info: http://icecast.org/docs/icecast-2.4.0/config-file.html
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: tim273 on April 09, 2017, 12:35:57 PM
I'm still not able to switch to a port other than 8000, which is a problem since I'm using that port through my firewall for my wxradio.dyndns.org feed from a weather radio. :-(

I just thought of this, you probably don't need to set up port forwarding to your computer with the weather radio because you only need to do that with incoming connections, not outgoing ones.  So you should be good to go.
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: satcop on April 21, 2017, 08:01:15 PM
Hi Tim;

I was trying to get two streams to self start from boot but having no joy.  It seems that darkice dumps when the rtl sdr stream is turned on.  After boot I can get both feeds to work, providing I do a sudo screen -r , than get out of that screen with a control a d and than do a sudo darkice start.  At that point both streams work.  If I don't look at the feed with the  sudo screen -r than darkice comes up but with no audio.

Bob

I've been having a similar problem, but I had it working before, let me look it up and I'll get back to you.  As long as you get it working, that's good, you rarely need to reboot the Pi.  I've had Raspberry Pi's up for a month or more without rebooting.

Ok working with another pi user (he is feeding Washington DC and Baltimore with pis) we figured out how to get them to work from a cold boot.  We added:

sleep 20
service darkice restart

after the screen line and before exit in the rc.local file.  It seems that darkice may be coming up before the connection to the router is fully established and drops.

Bob
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: tim273 on April 21, 2017, 10:46:44 PM
Hi Tim;

I was trying to get two streams to self start from boot but having no joy.  It seems that darkice dumps when the rtl sdr stream is turned on.  After boot I can get both feeds to work, providing I do a sudo screen -r , than get out of that screen with a control a d and than do a sudo darkice start.  At that point both streams work.  If I don't look at the feed with the  sudo screen -r than darkice comes up but with no audio.

Bob

I've been having a similar problem, but I had it working before, let me look it up and I'll get back to you.  As long as you get it working, that's good, you rarely need to reboot the Pi.  I've had Raspberry Pi's up for a month or more without rebooting.

Ok working with another pi user (he is feeding Washington DC and Baltimore with pis) we figured out how to get them to work from a cold boot.  We added:

sleep 20
service darkice restart

after the screen line and before exit in the rc.local file.  It seems that darkice may be coming up before the connection to the router is fully established and drops.

Bob

Good deal, glad that worked!
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: CF20852 on April 22, 2017, 11:19:44 AM
Tim,

Thanks for loaning us your expertise and good documentation skills.  I followed your procedure to get a couple of Raspberry Pi/R820T setups working.

I riffed off the email script you posted at https://github.com/tim273/weather_radio_scripts/blob/master/OPTIONAL.md (https://github.com/tim273/weather_radio_scripts/blob/master/OPTIONAL.md) and modified it so that it attempts to restart Darkice if it doesn't see my mountpoint up on the Icecast server.  I called this script check_darkice_up.sh, and put it in /home/pi:

Code: [Select]
#!/bin/bash

url="http://wxradio.dyndns.org:8000"
status_code=$(curl -v  $url 2>&1 | grep -o /mycity/mycallsign.mp3)
#echo "$status_code"

if [ "$status_code" == "" ]
then
    sudo /usr/sbin/service darkice restart
fi

I had to put "sudo /usr/sbin/" in front of "service darkice restart" to get it to run as a cron job.  Most of the clue on why that's necessary was posted in the first answer under https://unix.stackexchange.com/questions/179042/shell-script-issue-when-added-to-cron (https://unix.stackexchange.com/questions/179042/shell-script-issue-when-added-to-cron).  Without the "sudo," cron sent me an email at /var/mail/pi telling me the script failed at /usr/sbin/service darkice restart with an "Access denied" error.

I made the script executable:
Code: [Select]
chmod +x /home/pi/check_darkice_up.sh
Then I added a line to crontab to run it once each minute:
Code: [Select]
* * * * * /home/pi/check_darkice_up.sh
I tested it by stopping darkice using
Code: [Select]
sudo service darkice stop and letting the cron job run.  I can also run the script using:
Code: [Select]
sudo /home/pi/check_darkice_up.sh
Once I found that it runs OK as a cron job, I changed the interval to 31 minutes by changing the line in crontab to
Code: [Select]
*/31 * * * * /home/pi/check_darkice_up.sh
I should have let satcop know I was working on this, because in the middle of testing it, I got an email message to the effect that "your stream is down again!"  8-)

Chip
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: tim273 on April 22, 2017, 01:46:09 PM
Tim,

Thanks for loaning us your expertise and good documentation skills.  I followed your procedure to get a couple of Raspberry Pi/R820T setups working.

I riffed off the email script you posted at https://github.com/tim273/weather_radio_scripts/blob/master/OPTIONAL.md (https://github.com/tim273/weather_radio_scripts/blob/master/OPTIONAL.md) and modified it so that it attempts to restart Darkice if it doesn't see my mountpoint up on the Icecast server.  I called this script check_darkice_up.sh, and put it in /home/pi:

Code: [Select]
#!/bin/bash

url="http://wxradio.dyndns.org:8000"
status_code=$(curl -v  $url 2>&1 | grep -o /mycity/mycallsign.mp3)
#echo "$status_code"

if [ "$status_code" == "" ]
then
    sudo /usr/sbin/service darkice restart
fi

I had to put "sudo /usr/sbin/" in front of "service darkice restart" to get it to run as a cron job.  Most of the clue on why that's necessary was posted in the first answer under https://unix.stackexchange.com/questions/179042/shell-script-issue-when-added-to-cron (https://unix.stackexchange.com/questions/179042/shell-script-issue-when-added-to-cron).  Without the "sudo," cron sent me an email at /var/mail/pi telling me the script failed at /usr/sbin/service darkice restart with an "Access denied" error.

I made the script executable:
Code: [Select]
chmod +x /home/pi/check_darkice_up.sh
Then I added a line to crontab to run it once each minute:
Code: [Select]
* * * * * /home/pi/check_darkice_up.sh
I tested it by stopping darkice using
Code: [Select]
sudo service darkice stop and letting the cron job run.  I can also run the script using:
Code: [Select]
sudo /home/pi/check_darkice_up.sh
Once I found that it runs OK as a cron job, I changed the interval to 31 minutes by changing the line in crontab to
Code: [Select]
*/31 * * * * /home/pi/check_darkice_up.sh
I should have let satcop know I was working on this, because in the middle of testing it, I got an email message to the effect that "your stream is down again!"  8-)

Chip

Great Job!  I added your script to the Github repository.  I'll update the documentation as well a little later (got some errands to run).
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: nincehelser on October 20, 2019, 02:23:17 AM
I'm trying to get darkice running, but I seem to be running into a password problem:

Code: [Select]
DarkIce: IceCast2.cpp:251: Icecast2 - wrong password [0]
I've changed the password "hackme" in both the darkice.cfg and icecast.xml file and restarted to no avail.

I've been following the tutorial on github and sticking with the defaults.

What am I missing?

I'm running buster if that makes any difference.

Thanks!
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: tim273 on October 20, 2019, 09:06:44 AM
There's three different passwords in icecast.xml:

Code: [Select]
<authentication>
        <!-- Sources log in with username 'source' -->
        <source-password>source</source-password>
        <!-- Relays log in username 'relay' -->
        <relay-password>relay</relay-password>

        <!-- Admin logs in with the username given below -->
        <admin-user>admin</admin-user>
        <admin-password>admin</admin-password>
    </authentication>

I believe it's the source password, but I made them all the same on my server.  Also, once you change the passwords, restart icecast first and the darkice second.
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: nincehelser on October 20, 2019, 10:03:42 AM
There's three different passwords in icecast.xml:

Code: [Select]
<authentication>
        <!-- Sources log in with username 'source' -->
        <source-password>source</source-password>
        <!-- Relays log in username 'relay' -->
        <relay-password>relay</relay-password>

        <!-- Admin logs in with the username given below -->
        <admin-user>admin</admin-user>
        <admin-password>admin</admin-password>
    </authentication>

I believe it's the source password, but I made them all the same on my server.  Also, once you change the passwords, restart icecast first and the darkice second.

That's what I've done, but no joy.

In the icecast error log, I get this:
Code: [Select]
[2019-10-20  08:38:40] INFO connection/_handle_source_request Source logging in at mountpoint "/weather/radio" from 127.0.0.1
[2019-10-20  08:38:40] INFO connection/_handle_source_request Source (/weather/radio) attempted to login with invalid or missing password

I'm stumped.  What version of raspian did you build on?  Maybe I should try on that and see if I have the same problem. 

Thanks!
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: dupreezd on November 24, 2019, 07:59:03 AM
nincehelser, did you get this resolved? I have been running a Raspberry NOAA weather radio since last year build on the instructions provide by Tim Urberg. This went very smoothly. After that I build three more, also with no issues. The last one was in April 2019.
Last week the SD card failed in my Raspberry. I got a new SD, followed the procedure and ended up with the same error as you.
Double check passwords, username, server name in darkice.cfg and icecast.xml. Luckily I took snapshots of my builds, so I know the data entries are correct.

As a last resort, I did a complete rebuild not changing any of the default hackme passwords, same result.

I am not a Raspberry expert, so I am clueless how to find this problem. Maybe Tim can have a look and see what is going on.

Mine is build on Raspbian Stretch release 9.11

Thanks
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: dupreezd on November 26, 2019, 05:37:15 PM
nincehelser, I managed to get hold of a SD card from one of the units I build. I cloned it, edited the required fields and are back on line.  :grin:

If you are still interested in running a Raspberry, I can send you a cloned SD card to get you going.
At 15GB the img file is way to big to email and I do not have access to a FTP server. Even then it is going to take a long time to upload and download again.

If you are interested, please send me an Email.

Dries
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: ke9lz on January 12, 2020, 12:35:12 PM
Has anyone been able to make this work from scratch using the latest Raspberry software?  I have been trying to get this running and have not been successful.  I have followed the instructions to a tee and no success.

Steve
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: 92merc on January 12, 2020, 04:42:23 PM
It's been close to a year since I did my last one.  The only issue I've run into is I can't make the service start up properly.  After a reboot, I have to give it a minute to settle down, then restart the service.

But that's the only I had run into.  I have an older PI2 that I dabble with from time to time.  Production is a PI3.
Title: Re: Streaming to Multiple Icecast Servers with RTL SDR and Darkice
Post by: 92merc on January 12, 2020, 04:44:37 PM
I just checked, mine is at release 9.8 of stretch Raspbian BTW.