Thursday, April 22, 2010
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
Posted by POTUSCamacho at 12:21 PM
Saturday, April 10, 2010
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 https://wiki.ubuntu.com/ARM/NSLU2 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: http://www.nslu2-linux.org/wiki/HowTo/OverClockTheSlug 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:
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:
Now copy the following python script into a file named pair.py:
_dbus_error_name = "org.bluez.Error.Rejected"
exit_on_release = True
def set_exit_on_release(self, exit_on_release):
self.exit_on_release = exit_on_release
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")
def RequestPinCode(self, device):
print "RequestPinCode (%s)" % (device)
return raw_input("Enter PIN Code: ")
def RequestPasskey(self, device):
print "RequestPasskey (%s)" % (device)
passkey = raw_input("Enter passkey: ")
def DisplayPasskey(self, device, passkey):
print "DisplayPasskey (%s, %d)" % (device, passkey)
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")
def ConfirmModeChange(self, mode):
print "ConfirmModeChange (%s)" % (mode)
print "New device (%s)" % (device)
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)
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)
adapter.CreatePairedDevice(sys.argv, path, "DisplayYesNo",
print "Agent registered"
#print "Agent unregistered"
Now place your headset into pairing mode again and issue the follow command:
sudo -i python pair.py 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:
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 http://www.nasa.gov/55644main_NASATV_Windows.asx
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: http://wiki.bluez.org/wiki/HOWTO/AudioDevices 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: http://git.kernel.org/?p=bluetooth/bluez.git;a=blob_plain;f=test/simple-agent;hb=HEAD ) If you would like more information on this project or others contact me via http://twitter.com/POTUSCamacho
Posted by POTUSCamacho at 2:49 PM