If you ever have difficulty getting [back] to sleep, you may find that reading a book or listening to music for a while will make you sleepy.
But maybe you can get away with listening via a pair of headphones, if you keep the volume turned down low on your radio.
With a partner that likes to listen to the BBC World Service when sleep seems illusive, I have had to put up with all sorts of disturbances, including sudden loud noises and repeated clicks as each button on our DAB radio is pushed in turn in an attempt to find the right station.
DAB reception is very poor in our area, so we can get a satisfactory signal one minute, then lose the station altogether the next (i.e. we are on the digital cliff edge).
There have also been problems using wired headphones, where the cable gets strained, and audio starts to crackle or cut in and out.
However, I think Iâve come up with a better solution.
Using a Raspberry Pi, Wifi dongle, 5 Volt power supply, bluetooth transmitter and bluetooth headphones Iâve created The Insomniacs Bedside Radio.
I could use any of the Raspberry Pi models for this, however I selected an old model B which has two USB ports. This means I can not only connect a wifi dongle, but also power the Bluetooth transmitter, rather than having to remove it every couple of days to recharge the internal battery.
The Raspberry Pi models with better power regulators are supposed to have better audio quality. If true, it may be wise to use a B+ or B2.
This particular internet radio only receives an audio stream from the BBC World Service, so there are no buttons to push and click in the middle of the night!
Once the headset is paired with the bluetooth transmitter, only the âvolume +â and âVolume -â buttons on the headphones require any adjustment. And once the audio level is set for the one and only BBC stream that we are using, they donât really require much fiddling with.
My hardware list:-
- Raspberry Pi model B with case
- Edimax EW-7811-UN wifi dongle
- 5V 1A USB power supply (inc lead)
- BlueTooth transmitter eSynic AD2P with USB power cable
- BlueTooth Headphones CLiPtec Air-Touch
The software
The software just follows on from what I used for my Radio Caroline internet radio. Its written in Python as I donât need a user interface and I want it to start up as quick as possible.
Writing the software should have been a 5 minute task. But Python is not my language of choice, and I hadnât given too much thought to the practicalities of an internet radio with virtually no user intervention.
Initially my program just started mplayer with the BBC stream for the World Service. The idea was that the Raspberry Pi would be on all the time, and we could just pick up the headphones hanging on the bed-head and put them on.
However, on the very first night we had a short power cut at around 1am. When power returned, the Raspberry Pi must have booted OK and started mplayer. But as the wifi router was still booting up there was no internet connection, so no BBC stream, and no way to recover!
On the second night the internet connection was lost a few times because BT seem to be struggling to keep our new green street boxes going!
So this is the current Python program (BBC-player.py) which I added to the /home/pi directory.
#BBC-player.py
#Single station internet radio player
#SteveDee
#4/7/15
#==========================================================
import os
import psutil
import time
PLAYER = âmplayerâ
WORLD_SERVICE = âhttp://wsdownload.bbc.co.uk/worldservice/meta/live/shoutcast/mp3/eieuk.plsâ   #48k mp3
bPlayerRunning = False
#Set volume
os.system(âamixer sset PCM,0 85%â)
#Create a LOOP that runs & runs (âŠuntil you shutdown)
while True:
#check if player is running
for proc in psutil.process_iter():
if proc.name() == PLAYER:
bPlayerRunning = True
#print âfound mplayerâ
if bPlayerRunning == False:
#start radio
#print âstartingâŠâ
os.system(âmplayer -cache 128 -cache-min 16 -playlist â + WORLD_SERVICE + â &â)
bPlayerRunning = False   #reset flag
time.sleep(10)
#print âend of loopâ
Donât forget to install mplayer and python-psutils. The file: /etc/rc.local is then modified to run this automatically when the Pi boots up. Details are here but change the reference to point to /home/pi/BBC-player.py.
The program basically checks if the process âmplayerâ is running. If not, it runs mplayer with the required string to load the BBC stream.
For more detail: The Insomniacs Bedside Radio