Digital radio with a Raspberry Pi

Digital radio is transmitted in most Australian cities using the DAB+ standard. Off the shelf DAB+ radios are a bit expensive, but it’s possible to listen to DAB+ broadcasts using a computer and an inexpensive Software Defined Radio (SDR) dongle. A desktop or a laptop computer can be used, but something as basic as a Raspberry Pi works just fine. To find a dongle, search eBay or the like for ‘r820t’ and you’ll find a range of devices costing anywhere from about AUD$10 to as much as AUD$50. A ten dollar dongle is just fine for DAB.

This setup will work on a Raspberry Pi 2, but the new Raspberry Pi 3 is faster and has built-in wifi which makes setting it up a lot easier.

Things you need

  • SDR dongle and its antenna
  • Raspberry Pi 3
  • Power supply for the Pi
  • HDMI cable
  • Keyboard and mouse
  • 8GB or bigger micro SD card
  • Laptop or desktop computer to set up the SD card
  • TV or monitor with HDMI input

If you’re using a monitor rather than a TV, you may need headphones because many monitors will have a headphone socket but no speakers. Also, a short USB extension cable can be useful if you can’t get the keyboard, mouse and dongle to play nice with the closely spaced USB sockets on the Pi.

Overview

In summary, here’s what needs to be done. On a computer with access to the Internet and a micro SD card slot, download an Operating System for the Raspberry Pi and copy it to the micro SD card. Plug the card into the Raspberry Pi, configure the Pi, update its Operating System, install a bunch of software that the DAB+ receiver software needs, then download and build the DAB+ software.

The Details

Start by downloading the latest full version of the Raspbian Desktop from the raspberrypi.org web site. It’s a zip file, so once it’s downloaded, unzip it. I’m using my laptop running Korora 24 linux for this.

unzip 2016-05-27-raspbian-jessie.zip

This results in a file of about 4 gigabytes called 2016-05-27-raspbian-jessie.img which needs to be copied to the micro SD card.

Before you plug the micro SD card into your computer, run the df command to see what block devices are mounted. Then plug the card in and run df again. The extra device that’s listed is your card, possibly something like /dev/sdb1. Unmount the card if it auto-mounted.

umount /dev/sdb1

Use the dd command to copy the image file to the card. Recent versions of dd support the handy status=progress option which lets you easily keep tabs on how it’s going. It will take a few minutes to do and don’t forget to let the sync finish before you unplug the card.

sudo dd if=2016-05-27-raspbian-jessie.img of=/dev/sdb bs=4M status=progress && sync

Now the fun stuff begins. Plug the micro SD card into its slot on the Raspberry Pi, Connect the HDMI, keyboard, mouse and finally connect the power. With any luck, you’ll see the Pi booting up and it should go straight to a desktop. Click on the network icon at the top right of the screen, select your network and give it your network password to get connected. Open a terminal and:

sudo su -
raspi-config

Out of the box the raspbian OS is set up for a UK locale and keyboard, so I use the raspi-config tool to set my AU locale and US keyboard layout. Then select the ‘resize root file system’ option to maximise the use of the SD card, exit the tool and reboot.

Once it’s rebooted, update the Operating System.

sudo su -
apt-get update && apt-get dist-upgrade -y

Now install the stack of dependencies that the DAB+ software needs in order to build:

apt-get install -y vim qt5-default qt5-qmake libusb-1.0-0 libusb-1.0-0-dev \
portaudio19-dev faad libfaad-dev libsndfile1-dev \
sndfile-tools librtlsdr0 librtlsdr-dev libfftw3-3 libfftw3-dev

The SDR-J software

The DAB+ receiver software is the Open Source SDR-J project. It’s author, Jan van Katwijk, has a range of interesting software tools that you can read about on his site. We want the Raspberry Pi version of his DAB+ software.

git clone https://github.com/JvanKatwijk/dab-rpi
cd dab-rpi

There are quite a few README files. It may be useful to read a few of them.

The last piece of config is done by editing the dab-rpi.pro file.

vim dab-rpi.pro 

Just comment out the lines for sdrplay and airspy because they’re other (more expensive) SDR devices that we’re not setting up here.

Finally, it’s time to build the software.

qmake
make

Watch a great deal of compiler output streaming past for a few minutes. Once it’s finished (hopefully without major errors)…

cd linux-bin
./dab-rpi-0.997

You should see a bunch of text stream past in the console, then a GUI should open that you can navigate with a mouse.

Select dabstick as your input source, select your audio device, select your channel group and click Start. I used the Wikipedia DAB+ page to work out that the channel group I need for Canberra is 10B. If you exit the app via the Quit button, it will write a config file to ~/.dab-rpi.ini with your settings so that the next time you run it you won’t need to set it up again.

Tip: To route the audio to the Raspberry Pi’s 3.5mm headphone socket instead of HDMI, do this before you start dab-rpi.

amixer cset numid=3 1

More on setting up Openstack Ansible

Since I wrote this blog post in December 2015, things have been changing in the openstack-ansible world. Here I will describe an ‘all command line’ method for setting up a cloud server in the Rackspace Public Cloud and go through the steps necessary to get an All In One Openstack installation running.

This will include installing and setting up a command line tool for bringing up server instances, getting logged in to a new server instance, obtaining openstack-ansible, making some small configuration adjustments and using openstack-ansible to set up an ‘All in One’ Openstack setup.

The rack tool

Command line provisioning of cloud servers in the Rackspace public cloud may be accomplished using the rack tool available for MacOSX, Linux and Windows from the Rackspace Developer site.

To use the tool, you’ll need to have an account on mycloud.rackspace.com and to set up the tool you’ll need your username and API key from that account.

Follow the installation instructions on the developer site to get the rack tool set up for your operating system.

Before you create a server

Once you have created a server, you will want to ssh in to it to set up Openstack. You could just use ssh with a password, but it’s entirely possible that the Openstack installation process will disable password logins (hint: It will) so you’d be well advised to set things up so that you can log in with an ssh key instead.

If you already have an ssh keypair available, you’re ready to use the racker tool to add the public key to your mycloud account so that it can be automatically installed in your cloud servers. If you don’t, or if you’re not quite sure how to go about making a keypair, the nice folks at github have some great instructions for doing that.

With your public key living at ~/.ssh/id_rsa.pub, you can:

rack servers keypair upload --file ~/.ssh/id_rsa.pub --name mi_key
Name		mi_key
Fingerprint	e6:bb:27:21:b8:6a:d8:17:04:c6:26:56:a8:bc:ef:b6
PublicKey	ssh-rsa <snipped the actual key>

This will give your public key the name mi_key and upload it to your mycloud account, ready to use when you create servers. Choose your own name for the key when you upload it.

Creating a server

A couple of things that you’ll need to know before you create a server are an image name which will determine your server’s base operating system and a flavor which will determine its memory, disk and CPU characteristics. The racker tool includes some useful commands to help you decide which image and flavor you want to use.
To work out what system images are available, use:

rack servers image list

And to work out what flavors are available:

rack servers flavor list

Having run these commands to determine what options are available, I can now create a server with:

rack servers instance create --name myserver --image-name "Ubuntu 14.04 LTS (Trusty Tahr) (PVHVM)" --flavor-id io1-15 --keypair mi_key

Once the command has run, you’ll see an ID for the server and a root admin password (which you may want to copy) and you should be able to see details of the new server via your list of servers with:

rack servers instance list | grep myserver

Your ssh key should already be installed on the new server so using the IP address revealed by the list:

ssh root@<server.ip.address>

Preparing the system

The Ubuntu 14.04 image will benefit from some package upgrades, so start out by doing that:

apt-get update && apt-get upgrade -y

And you’ll need a couple of extra tools set up:

apt-get install git tmux

The tmux tool lets you set up a session that will keep going if you lose your network connection. This command will create a session called ‘admin’ that you can later re-connect to with the tmux attach -t admin command.

tmux new -s admin

Next get a copy of the openstack-ansible code using git:

git clone https://git.openstack.org/openstack/openstack-ansible /opt/openstack-ansible

The procedure for kicking off ansible has changed slightly since the last time I wrote about it. Start with:

cd /opt/openstack-ansible

If you have a need to run a version of Openstack earlier than the very latest, select the version you want now.

git tag

From the list of git tags, choose the one you want to use. Substitute it for TAG in the following command:

git checkout TAG

Then get things going with:

scripts/bootstrap-ansible.sh

It’s important to have quite a lot of disk available to set this up. This requires a config change:

sed -i '/#bootstrap_host_data_disk_device:/c\bootstrap_host_data_disk_device: xvde' tests/roles/bootstrap-host/defaults/main.yml

Now the openstack setup can run:

scripts/bootstrap-aio.sh
scripts/run-playbooks.sh

This will need an hour or more to run. Once it completes, you should be able to see all of the lxc containers running Openstack services on your server with:

lxc-ls -f

Setting up Openstack Ansible AIO

These notes are an attempt to bring together a few sources of information that collectively explain how to set up an ‘All In One’ (AIO) Openstack installation on a single host.

The official Openstack Docs Quickstart guide is very good and is a great place to start.
In addition, Richard Jones has blogged about setting up an AIO installation for Horizon development work. His notes point out some of the customisation that can be done if you have a need to not deploy all of the components of the stack. Also, Miguel Grinberg has written a blog post about his use of AIO for development work.

Setting up an AIO instance may be done on a standalone computer or on a virtual machine. Here I am working with a virtual machine in the Rackspace Public Cloud. One of the first things that the Quick Start guide makes clear is the minimum system requirements for RAM and disk being 16 gig of RAM and 80 gig of disk. I initially attempted an AIO setup on a virtual machine with only 8 gig of RAM, and though the process seems to mostly proceed as it should, it eventually fails and cannot be used. Others have reported AIO installation failures when attempting to use virtual servers from the ‘standard’ set of Rackspace server ‘flavors’ due to scripted assumptions about disk partitioning. I have had success in setting up AIO on a virtual server from the ‘I/O’ group with 15 gig of RAM, 40 gig of disk and Ubuntu 14.04 as the operating system. This combination is called 15 GB I/O v1.

Note: When creating the server, you must scroll to the Recommended Installs section at the bottom of the Create screen and select the checkbox for ‘Operating system security patches applied on selected images’.

Tip: Doing protracted operations on a server via ssh runs the risk that a flaky network connection may drop out and lose all of your hard work. To mitigate that risk, I like to use tmux (terminal multiplexer). Using tmux, you can create a shell session that will persist even if you lose the link. When you ssh in again, your session is still there and you can attach to it. So once you have ssh’d into your new server:

tmux new -s admin  #creates a session called admin

Now just do everything you normally would, but safely ensconced in a tmux session. Later on, if you lose the link and ssh back in again, you just:

tmux attach -t admin  #reattaches to your admin session. 

Okay. On with what we came here to do:

apt-get install git
git clone https://github.com/openstack/openstack-ansible /opt/openstack-ansible
cd /opt/openstack-ansible
scripts/bootstrap-ansible.sh
scripts/bootstrap-aio.sh

Once the AIO is up and running, you’ll likely want to log into the Horizon web interface to interact with the system. The scripts will have helpfully created some memorable passwords like “8237b1b4e89221693c81c50156bc7b69d2cd91f6a9a37b9c36db2” which you can use to log in to the web UI. If you find that a bit tedious, now is the time to go and edit /etc/openstack_deploy/user_secrets.yml and seek the line that begins with keystone_auth_admin_password. Change the long string there to something you can remember like ‘TrickyPa55’.

Now you can finish the setup process:

scripts/run-playbooks.sh

Watch a great deal of logging go past for perhaps an hour or so. Once the setup is complete, that log may be found at /var/log/cloud-init.log

If all has gone well, it should now be possible to point a web browser at the public IP of your virtual server and log in to the Openstack dashboard.

User: admin
Password: TrickyPa55

…or whatever password you set in /etc/openstack_deploy/user_secrets.yml

From the shell prompt where you ran the setup scripts, you can take a look at the containers that have been set up using:

lxc-ls -f

This will list all of the containers (32 at the time of writing) and some metadata; most usefully their IP addresses. To ‘log in’ to a container, you might (as Miguel suggests in his blog post) use:

lxc-attach -n the_full_container_name_and_identifier

Since the installation scripts have helpfully copied your virtual server’s root ssh public key into each container, it is perhaps easier to look inside a container using ssh. This is a matter of getting the container’s IP address from the lxc-ls -f command and just ssh-ing to that address. For example:

root@cadence:~# ssh 172.29.238.249
Welcome to Ubuntu 14.04.3 LTS (GNU/Linux 3.13.0-58-generic x86_64)

Executing openstack CLI commands can be done by accessing the ‘utility_container’. ssh to its IP address then:


source openrc

(or even)

. openrc

Then it’s possible to run queries like:

root@aio1_utility_container-60daf7b8:~# cinder type-list
+--------------------------------------+------+-------------+-----------+
| ID                                   | Name | Description | Is_Public |
+--------------------------------------+------+-------------+-----------+
| 341ae6ec-5298-4cd0-b433-2fa5ffe5990d | lvm  | -           | True      |
+--------------------------------------+------+-------------+-----------+