OP25 on Raspberry Pi Part 2 (Streaming to Broadcastify)

It’s been a while since I’ve written part one, as I have been tweaking settings and thinking about switching audio streaming clients. Anyways, It’s been since December 2018 since I’ve followed the tutorial on the Hagensieker Blog and with a few changes every other week, I have a pretty stable build. My up-time with Broadcastify is right at 100% (as long as I remember to pay my internet bill).

Broadcastify is the best service to stream with. They provide all the bandwidth for free, and will allow access to archives (up to 180 days) to premium subscribers in 30 minute blocks. My favorite part, is the amount of statistic logging that they have built in to the streaming service, you can track all time highs, trends, up-time, etc. If you choose to do something different such as Icecast or one of the other alternatives, this tutorial will work for you as long as the streaming services accepts connections from Darkice, you will need to make the appropriate changes to the Darkice config file.

If you choose to stream with Broadcastify, you’ll first need to register for a stream. Go to https://www.radioreference.com/apps/account/?tab=la%20 select the Feed Tab and click on “Apply to Broadcast Feed”. I had a few other streams in the past and on thing that I learned was to make sure you provide the information they ask for exactly. I had one feed in particular that was kicked back by admins 3 or 4 time, the last revision was short but was only the necessary information, so don’t overthink it.

Once you are an approved feed provider, you should receive and email. You’ll need to note 4 key items in the email, you can also find this under your stream’s technical tab. They are stream and user specific: Server, Port, Mount (this will start with a “/” but the “/” is not needed so forget that character), password.

Next, we’ll start configuring a loop for the audio. This is the linux version of Virtual Audio Cable with windows.

Open the bcm2835 module config:

sudo nano /etc/modprobe.d/bcm2835.conf

Add the following:

softdep snd-bcm2835 post: snd-aloop
options snd-aloop enable=1 index=1 pcm_substreams=2

Press the following keys [CTRL]+[X], then [Y], then [ENTER]

Create an asound.conf file:

sudo nano /etc/asound.conf

Paste the following information:

# output device
pcm.loopout0 {
  type plug
  slave.pcm “hw:Loopback,0,0”
}

# input device
pcm.loopin0 {
  type dsnoop
  ipc_key 686592
  slave.pcm “hw:Loopback,1,0”
}

# duplex plug device
pcm.loop0 {
  type plug
  slave {
    pcm {
      type asym
      playback.pcm “loopout0”
      capture.pcm “loopin0”
      }
  }
}

# output device
pcm.loopout1 {
  type plug
  slave.pcm “hw:Loopback,0,1”
}

# input device
pcm.loopin1 {
  type dsnoop
  ipc_key 686593
  slave.pcm “hw:Loopback,1,1”
}

# duplex plug device
pcm.loop1 {
  type plug
  lave {
    pcm {
      type asym
      playback.pcm “loopout1”
      capture.pcm “loopin1”
    }
  }
}

Press the following keys [CTRL]+[X], then [Y], then [ENTER]

The asound.conf creates a loopback device, basically a virtual cable which your streaming service (darkice) will use to send to your broadcastify device. We are using loop0 but you can use loop1 for additional devices (the amount of devices will depend on the capabilities of your system. I would stick to 1 per pi now, I am working on multi streams at the moment)

Now that the audio needs to be passed to loop0, in order to stream, we will need to alter our op25.sh script file.

cd
cd op25
sudo nano op25.sh

Paste this information into the file (changing the highlighted info to meet your needs):

#! /bin/shcd /op25/op25/gr-op25_repeater/apps./rx.py –args ‘rtl’ -N ‘LNA:47’ -S 2400000 -f 857.2625e6 -o 25000 -q 1 -O loop0 -T trunk.tsv -V -2 -U 2> stderr-stream0.2Now we need to install darkice. Darkice handles the streaming of your decoded audio. We will then configure it to stream to you Broadcastify feed.sudo apt-get install darkiceOnce Darkice is installed we will nee to create a darkice config. sudo nano /etc/darkice-stream0.cfgPaste the following information, change the server, port, password, mountpoint, name and description to match the stream information that you received with you feed approval. # sample DarkIce configuration file, edit for your needs before using
# see the darkice.cfg man page for details# this section describes general aspects of the live streaming session
[general]
duration = 0 # duration of encoding, in seconds. 0 means forever
bufferSecs = 1 # size of internal slip buffer, in seconds
reconnect = yes # reconnect to the server(s) if disconnected# this section describes the audio input that will be streamed
[input]
device = loop0 # OSS DSP soundcard device for the audio input
sampleRate = 22050 # sample rate in Hz. 22050 is the RR Standard
bitsPerSample = 16 # bits per sample. 16 for mono feeds, 32 for stereo feeds
channel = 1 # channels. 1 = mono, 2 = stereo# this section describes a streaming connection to an IceCast server
# there may be up to 8 of these sections, named [icecast-0] … [icecast-7]
# these can be mixed with [icecast2-x] and [shoutcast-x] sections# If you want to send to your own icecast server, you basically copy
# this whole section and put in the values to point the feed to your own
# server instead of the RR information below# Don’t forget, the name [icecast2-0] needs to change to [icecast2-1]
# and 2 and 3 as you add more feed destinations.[icecast2-0]
# The audio format to encode to, we’re using mp3 here
format = mp3# The bit rate mode to use, the commented out lines are for a fixed bit
# rate “constant bit rate” at 16 bits. I prefer the variable bit rate
# for the sound quality it has and the throughput is very similar on avg#bitrateMode = cbr
#bitrate = 16sampleRate = 22050 # sample rate in Hz. 22050 is the RR Standard
bitrateMode = cbr
bitrate = 16# Quality at .1, max is 1.0, but as you increase, so does the bandwidth
# used. For mono scanner audio .1 is totally fine.
quality = 0.1# Takes the input and mixes it down to a mono output for the feed.
channel = 1# Cuts frequency response over 5kHz. For scanner feed this mostly
# eliminates hiss and harshness on paging tones. Saves a bunch of
# bandwidth as well.
lowpass = 5000# Server shown on your RR feed owner page that hosts your feed
# You need to log in to RR, go to Account -> My Live Audio Feeds ->
# click the feed owner page icon at the far right of your feed listing.
# Then you will see all this information.# From Feed Technical Details, the “Server”
server = SERVER.broadcastify.com# From Feed Technical Details, the “Port”
port = 80 # port of the IceCast server, usually 8000# From Feed Technical Details, the Password exactly as shown
password = PASSWORD# From Feed Technical Details, the mount…remove the leading “/”, it’s
# not needed in this file. So if it is /999999 make it just 999999
mountPoint = MOUNTPOINT# name of the stream
# On My Live Audio Feeds, it’s the first part ending in a colon “:”
name = Short name# On My Live Audio Feeds, it’s the part in parentheses in the Feed name
description = DescriptionPress the following keys [CTRL]+[X], then [Y], then [ENTER]Now install screen in order to create a Crontab command to start the  op25.sh at boot up.sudo apt install screenNow edit your crontab file. This file allows certain functions/commands to be started/stopped/executed at certain times. This will start op25.sh at startup/reboot.crontab -ePaste at the bottom@reboot /usr/bin/screen -d -m /home/pi/op25/op25.shNow create a service for op25, you can start the service via terminal if op25.sh isn’t currently running (if you kill the job or it crashes etc)sudo nano /etc/systemd/system/op25-stream0.servicePaste the following:[Unit]
Description=op25
After=syslog.target network.target nss-lookup.target network-online.target
Requires=network-online.target[Service]
User=pi
Group=pi
Type=forking
ExecStart=/usr/bin/screen -d -m /home/pi/op25/op25.sh
RestartSec=5
Restart=on-failure[Install]
WantedBy=multi-user.targetPress the following keys [CTRL]+[X], then [Y], then [ENTER]Enable and start the servicesudo systemctl enable op25-stream0.service
sudo systemctl start op25-stream0.serviceYou can start darkice by typingdarkice -c /home/pi/darkice/darkice.cfgBut we want darkice to start automatically at boot, this way if your pi reboots or it crashes, it will start automatically if it is power cycled, sudo reboot command is sent, or you have crontab auto reboot your pi.Create a darkice servicesudo nano /etc/systemd/system/darkice-stream0.servicePaste the following:[Unit]
Description=darkice-stream0
After=syslog.target network.target nss-lookup.target network-online.target
Requires=network-online.target[Service]
ExecStart=/usr/bin/darkice -c /etc/darkice-stream0.cfg
RestartSec=5
Restart=on-failure[Install]
WantedBy=multi-user.targetPress the following keys [CTRL]+[X], then [Y], then [ENTER]Now enable and start the servicesudo systemctl enable darkice-stream0.servicesudo systemctl start darkice-stream0.serviceNow both darkice and op25 should start automatically at boot.In case there is a crash or for some reason the services stop, let’s create a simple start everything from one command. Create a file named broadcastify.shsudo nano /home/pi/broadcastify.shPaste the following information#! /bin/sh
sudo systemctl start op25-stream0.service
sudo systemctl start op25-stream0.service
bash /home/pi/op25/op25.shPress the following keys [CTRL]+[X], then [Y], then [ENTER]Make it executablesudo chmod -x broadcastify.shMake an alias for broadcastify.shsudo nano .bashrcThis should already be at the very bottom##OP25 aliasalias op25=’bash /home/pi/op25/op25.sh’Underneath pastealias bcst=’bash broadcastify.sh’Press the following keys [CTRL]+[X], then [Y], then [ENTER]For some reason I’ve realized my stream will stop about every 12 – 24 hours. instead of logging in SSH or VNC (which is a pain if I am asleep or away from the computer/phone (courtesy of VNC Viewer app)) You will need to edit the ROOT crontab file, reboot, shutdown commands require the command to be executed as root. (hence the sudo before crontab -e)sudo crontab -ePaste this at the bottom0 0 * * * /sbin/rebootYou shouldn’t see your other crontab @reboot in the file because this is a separate file with different permissions. Now your pi will auto reboot at midnight. If you have issues every twelve hours add another line. the format is as followsmin hour dayofthemonth month dayoftheweek {command}So, if you wanted to reboot at 12 noon0 12 * * * /sbin/rebootRemember it is in 24-hr format.

I’d like to thank John Hagensieker for doing a lot of the hard work, I originally followed his tutorial at his personal wordpress blog https://www.hagensieker.com/wordpress/. A lot of his code is implemented here.If you are following this tutorial, please stream the traffic to Broadcastify, if you have a stream up and want me to publish them in my feed section, Please send your infromation to my email KN4KNG@Outlook.com.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s