Thursday, April 22, 2010

Twitter Audio Update

I decided a while ago to take down the radio station. I wasn't really getting any listeners, so I decided that it would be one less thing to try to keep up. If you are interested in continuing the project, and would like detailed scripts to do it, message me on twitter @POTUSCamacho

Saturday, April 10, 2010

Linksys NSLU2 Utilizing Bluetooth Audio

I was posting on Twitter and got a request from @m1n1m3 to cover this topic. The requirements are a Linksys NSLU2, a linux compatible usb bluetooth adapter (I use IOGEAR GBU211 or GBU421), a bluetooth headset (any should do), and a usb thumb drive (4GB or higher). This is for mono audio on a bluetooth headset. This does not cover a stereo configuration, though it should be possible.

To get started, follow the directions at to get your base Ubuntu system installed on the NSLU2. I have used other alternative firmwares in the past, but not for this particular project. The Debian install should work, but I cannot verify it. Note that it will take a while to complete the install. Also, if your NSLU2 is of a certain manufacture date, I strongly suggest that you follow the overclocking hack here: I have only run the NSLU2 at 266Mhz.

Once you have installed Ubuntu, log in and update your packages:

sudo -i apt-get update

Then install the following packages:

sudo -i apt-get install linux-sound-base bluetooth bluez bluez-alsa bluez-btsco bluez-compat bluez-utils python python-bluez vlc

Note: I do alot of other development stuff on my unit. I may have left off something, and if so let me know if you try it and it doesn't work.

Now that the needed packages are installed, an .asoundrc needs to be created in your user home directory. An example:

pcm.bluetooth {
type bluetooth
device 00:00:00:00:00:00

Edit the device section with the MAC address of your bluetooth headset. To find this, issue a reset of the bluetooth adapter by issuing the command:

hciconfig hci0 reset

Then place your headset in pairing mode and issue the following command:

sdptool browse

Now copy the following python script into a file named


import gobject

import sys
import dbus
import dbus.service
import dbus.mainloop.glib

class Rejected(dbus.DBusException):
_dbus_error_name = "org.bluez.Error.Rejected"

class Agent(dbus.service.Object):
exit_on_release = True

def set_exit_on_release(self, exit_on_release):
self.exit_on_release = exit_on_release

in_signature="", out_signature="")
def Release(self):
print "Release"
if self.exit_on_release:

in_signature="os", out_signature="")
def Authorize(self, device, uuid):
print "Authorize (%s, %s)" % (device, uuid)
authorize = raw_input("Authorize connection (yes/no): ")
if (authorize == "yes"):
raise Rejected("Connection rejected by user")

in_signature="o", out_signature="s")
def RequestPinCode(self, device):
print "RequestPinCode (%s)" % (device)
return raw_input("Enter PIN Code: ")

in_signature="o", out_signature="u")
def RequestPasskey(self, device):
print "RequestPasskey (%s)" % (device)
passkey = raw_input("Enter passkey: ")
return dbus.UInt32(passkey)

in_signature="ou", out_signature="")
def DisplayPasskey(self, device, passkey):
print "DisplayPasskey (%s, %d)" % (device, passkey)

in_signature="ou", out_signature="")
def RequestConfirmation(self, device, passkey):
print "RequestConfirmation (%s, %d)" % (device, passkey)
confirm = raw_input("Confirm passkey (yes/no): ")
if (confirm == "yes"):
raise Rejected("Passkey doesn't match")

in_signature="s", out_signature="")
def ConfirmModeChange(self, mode):
print "ConfirmModeChange (%s)" % (mode)

in_signature="", out_signature="")
def Cancel(self):
print "Cancel"

def create_device_reply(device):
print "New device (%s)" % (device)

def create_device_error(error):
print "Creating device failed: %s" % (error)

if __name__ == '__main__':

bus = dbus.SystemBus()
manager = dbus.Interface(bus.get_object("org.bluez", "/"),

if len(sys.argv) > 1:
path = manager.FindAdapter(sys.argv[1])
path = manager.DefaultAdapter()

adapter = dbus.Interface(bus.get_object("org.bluez", path),

path = "/test/agent"
agent = Agent(bus, path)

mainloop = gobject.MainLoop()

if len(sys.argv) > 2:
if len(sys.argv) > 3:
device = adapter.FindDevice(sys.argv[2])

adapter.CreatePairedDevice(sys.argv[2], path, "DisplayYesNo",
adapter.RegisterAgent(path, "DisplayYesNo")
print "Agent registered"

#print "Agent unregistered"

Now place your headset into pairing mode again and issue the follow command:

sudo -i python hci0 00:00:00:00:00:00

Once again replacing the address above with your headsets MAC.

The last step involves editing the vlcrc. To do this, issue the command:

pico .vlc/vlcrc

Scroll to the end and edit the entry that says alsadev=(default soundcard) to:


If it does not exist then create it.

Now you should be ready to listen to audio. To listen to the audio from NASA TV's online video stream, issue the command:

cvlc --aout-rate 8000 --novideo

If everything is working you should hear audio. Keep in mind that the sample rate needs to be 8000Hz since that is the sample rate the headset can handle.

To pair another headset, or to re-pair the current, the /var/lib/bluetooth/(your MAC)/linkkeys file must be deleted. It will regenerate once you have paired the devices. Also remember that the .asoundrc file must be edited to match a different headset as the MAC will be different.

Other things I have done in the way of bluetooth that have worked has been using a TCP/IP piconet using pand. Since I have been unable so far to get a Belkin 802.11 usb wireless adater to work, it is useful as a wireless connection. I have connected 2 GBU211 adapters to a Targus ACH7405US travel usb hub, with one connecting to a computer via pand and the other providing bluetooth audio. I tried for 3, but the power draw was too much. I have tried to use the NSLU2 as a bluetooth to cellular bridge via pand, ip forwarding, iptables, rfcomm, and wvdial, but the version of wvdial for NSLU2 Ubuntu (and I believe Debian) crashes when connecting. Linphonc will work if you use wav files as soundcards. I have been trying to get a bluetooth headset to work (which I have no issues with on x86), but I have been unable to make calls. I have yet to try a bluttooth hands free speaker phone, but I would imagine that it would work the same.

Information on bluez-audio can be found here: I can't remember where exactly I found the pairing script. Let me know where to find it and I will post a link. ( Update: It's called simple-agent and I found it here:;a=blob_plain;f=test/simple-agent;hb=HEAD ) If you would like more information on this project or others contact me via