Friday, July 20, 2007

Linux clock radio

I've been wanting to wake to the sound of something more pleasant than my beeping cellphone. I've used the alarm clock feature of my cellphone to get me up in the morning for some time now. I'm not sure why ... think its because the clock radio in our room broke some time ago ... radio still works but the switch on the alarm position is flaky. But I digress ... anyway I thought it would be nice to get up to the sound of the BBC instead. Also unrelated, I picked up a Griffin RocketFM USB FM transmitter .... mostly because I saw it on another blog and thought it would be cool to have ... with no key purpose in mind at the time. It was designed for Windows/MAC but it will work with Linux as an ALSA USB sound device. Only issue is I haven't figured out a way to control the frequency selection under Linux. The device defaults to 88.1 Mhz which is fine for me right now.

I needed to physically modify the device a tad .... the internal 3" copper wire antenna downright sucks. I calculated what A half wave wire would be on 88 MHz ( ~ 63"), divided it in two, put one on the circuit board where the antenna connects and the other on a ground connection. Had to drill a few holes in the case for the wires to come out. Instant FM dipole. Now from the basement location of my Linux box I can receive the signal full quieting all around the house. Since I doubt I'm going beyond the bounds of my property I'm likely still within FCC PART 15 compliance.

Next I needed to tinker with ALSA a bit ... I created a new definition in my .asoundrc file for the RocketFM which showed up as card 1:


pcm.RADIO {
type hw
card 1


Then by using the -ao option I can direct mplayer to use that device rather than the default sound card.

mplayer also has a -slave option which means: listen on stdin for commands. I then create a FIFO and cat that FIFO to stdin on my invocation of mplayer. Now if I want to command that specific invocation of mplayer all I need to do is "echo" the command into the FIFO.

Now for the clock .... well that's a no brainer ..... I just use "at".

This all gets wrapped up into one neat script I call, oddly enough, "wakeup":

#!/bin/bash
at 8:59 << EOF
cat /tmp/mplayer-fifo | /usr/local/bin/mplayer -quiet -slave -ao alsa:device=RADIO \
mms://a1149.l1305038288.c13050.g.lm.akamaistream.net/D/1149/13050/v0001/reflector:38288
EOF
at 10:00 << EOF
echo "quit" > /tmp/mplayer-fifo
EOF

(times are in UTC)

I leave the radio on .. again ... now the Rocket FM puts out a full quieting carrier so no unnecessary noise. At 08:59 the process kicks off and the stream is up in running in time to here the "beep" on the hour and the following news. (No Mike ... considering the delay in the stream I doubt the beep meets your standards for accuracy ;-) )

I have a similar script that allows me to drift off to the sound of WNYC-HD for 30 minutes when I go to sleep. I just invoke mplayer immediately into the background and then set up the turn off at "now + 30 minutes"




#posted by Rob Roschewsk @ 10:54 AM

Comments:

Rob,
I bought the same FM Transmitter and I would like to duplicate what you did with the antenna. Would you mind either posting a picture of the modifications or sending it to me? Once I do that my next challenge would be to follow your steps and try to get it working on Linux. Thanks in advance,

Oscar

# posted by Blogger Payero @ 9:36 AM 

Comments:

Sure .. will do ... I fully intended to do that but life got in the way :) Stay tuned.

# posted by Blogger Rob Roschewsk @ 1:25 PM 

Post a Comment