Bluetooth: Transferring and receiving files under Ubuntu
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
By beginningubuntu at 2007-05-30 05:46
Here's a guide to utilizing Bluetooth on Ubuntu. The guide explains how to pair your computer with a Bluetooth device, and then transfer files between an Ubuntu computer and a Bluetooth device. Additionally, there's a quick guide to configuring Ubuntu to use common Bluetooth input devices.
The guide is extracted from Chapter 8 of Beginning Ubuntu Linux, Second Edition (published April 2007). The rest of the chapter is a comprehensive and unique examination of setting up hardware under Ubuntu.
Bluetooth is the short-range networking facility that allows various items of hardware, usually mobile devices, to work with each other wirelessly. You can use Bluetooth for everything from file transfers between a mobile phone and computer, to employing a wireless keyboard with your desktop computer.
For Bluetooth to work, both devices need to have Bluetooth support. Many mobile phones come with Bluetooth nowadays, and an increasing number of notebook computers do too. It’s also possible to buy very inexpensive Bluetooth USB adapters.
Your PC’s Bluetooth hardware is automatically recognized under Ubuntu, and the low-level driver software is installed by default. Therefore, all you normally need to do is install the software that provides the Bluetooth functionality you require.
Pairing Bluetooth Devices
When two pieces of Bluetooth-compatible hardware need to communicate on a regular basis, they can pair together. This means that they trust each other, so you don’t need to authorize every attempt at communication between the devices. Indeed, some devices won’t communicate unless they’re paired in this way.
Pairing is very simple in practice and works on the principle of a shared personal ID number (PIN). The first Bluetooth device generates the PIN, and then asks the second Bluetooth device to confirm it. Once the user has typed in the PIN, the devices are paired.
Pairing is easily accomplished under Ubuntu and doesn’t require any additional software. However, you will need to edit a configuration file. This only needs to be done once.
Start by opening the central Bluetooth configuration file, hcid.conf, in Gedit, using superuser powers:
gksu gedit /etc/bluetooth/hcid.conf
Look for the line that reads "security user", and change it so that it reads "security auto".
The default PIN needed to pair with Ubuntu is 1234. For security reasons, it’s wise to change this, and the setting is contained further down in the hcid.conf file. Look for the line that reads
and replace 1234 with the number you desire. For example, if I wanted a PIN of 9435, the line would read
When you’ve finished, save the file, and close Gedit. It’s then necessary to restart the background Bluetooth service. To do this, type the following into a Terminal window (Applications -> Accessores -> Terminal):
sudo /etc/init.d/bluetooth restart
Following this, I paired my Ubuntu test PC to a Nokia 6680 mobile phone. It’s easiest to initiate pairing on the phone, which should then autosense the PC’s Bluetooth connection.
On the Nokia 6680, I opened the menu, and selected Connections -> Bluetooth. Then I pressed the right arrow key to select Paired Devices and selected Options -> New Paired Device -> More Devices. This made the phone autosense my Ubuntu PC, which was identified by its hostname, followed by -0. In my case, the Ubuntu PC was identified as keir-desktop-0, and I was then prompted to enter the PIN I set earlier. Following this, the two devices were paired.
Transferring Files Between Bluetooth Devices
If you own a Bluetooth-equipped camera phone, you might be used to transferring pictures to your computer using Bluetooth. It’s by far the easiest way of getting pictures off the phone and avoids the need for USB cables or memory card readers.
To transfer files via Bluetooth, you’ll need to install some additional software from the Ubuntu Universe repository, and change another configuration file. If you haven’t yet configured the Synaptic Package Manager for additional repositories, see the “Setting Up Online Software Repositories” section in chapter 8 of Beginning Ubuntu Linux, Second Edition, or consult an online guide to setting up additional software repositories.
Then open Synaptic Package Manager (from the System -> Administration menu). Search for and install gnome-bluetooth.
Next, open a terminal window, and type the following, which will open the rc.local configuration file in Gedit:
gksu gedit /etc/rc.local
Scroll down to the blank line above "exit 0", and type the following:
hciconfig hci0 inqmode 0
Note that the characters in the line after hci and inqmode are zeros and not the letter “O”. Save the file, close Gedit, and then restart your computer.
Once logged in again, you should now find a new entry on the Applications -> Accessories menu: Bluetooth File Sharing. The following instructions detail how to transfer any kind of file to and from your PC using Bluetooth. Once again, I use a Nokia 6680 in the examples, but the instructions should work with any phone, or even any Bluetooth device capable of sending and receiving files, such as another Bluetooth-equipped computer.
Note Some phones refuse to transfer files unless the phone and computer are paired, so follow the instructions in the previous section first. Phones like the Nokia 6680 don’t need pairing for file transfer, although each transfer will need to be confirmed manually.
Sending Files to a Ubuntu PC
Follow these steps to send files from a Bluetooth device to your PC:
Select Applications -> Accessories -> Bluetooth File Sharing. Nothing will appear to have happened, but in fact, a new icon will have been added to the notification area. This does nothing apart from indicate your computer is ready for incoming Bluetooth connections.
On the Bluetooth device from which you wish to send the file, start the file transfer. On the Nokia 6680, I selected the file and clicked Send -> Via Bluetooth.
When the file transfer is initiated, a dialog box will appear on your computer asking if you wish to accept the file. Click OK. (If the two devices are paired, the file transfer may happen instantly without the confirmation dialog box.) The file will be saved to your /home directory.
Sending Files from an Ubuntu PC to Another Device
The easiest way to send files from your PC to a Bluetooth device is to create a desktop shortcut onto which you can drag and drop files. Follow these steps to create the shortcut:
Right-click the desktop, and click Create Launcher.
In the Name field, type something like "Send file via Bluetooth".
In the Command field, type "gnome-obex-send".
You can also choose to give the new shortcut an appropriate icon. Click the No Icon button, and then type the following into the Path field:
After you’ve created the icon, you can send files as follows:
Drag and drop a file onto the launcher (icon) you just created.
The Choose Bluetooth Device dialog box appears. Click Refresh to make the computer detect any nearby Bluetooth devices. This may take a minute or two. Remember that your device will need to be set to be “visible,” so that other Bluetooth devices can automatically detect it.
Select the device to which you want to transfer the file, and then click OK.
Check the device to see if the file transfer needs to be authorized. If the devices are paired, the transfer might take place automatically.
Using a Bluetooth Keyboard or Mouse
Your Bluetooth-equipped keyboard or mouse may work automatically under Ubuntu.
However, if not, you may find the following instructions useful:
Open a GNOME Terminal window (Applications -> Accessories -> Terminal), and type "hcitool scan".
Your Bluetooth keyboard or mouse should be identified in the results (ignore any other devices that might appear in the list). If not, make sure it isn’t in sleep mode. You might also have to press a button on the device for it to be made visible to other Bluetooth devices.
Alongside the entry for the keyboard or mouse will be a MAC address—a series of numbers like 00:12:62:A5:60:F7.
In the GNOME Terminal window, type the following:
sudo hidd --connect xx:xx:xx:xx:xx:xx
Replace xx:xx:xx:xx:xx:xx with the series of numbers you discovered in the previous step.
You should find that your keyboard or mouse works under Ubuntu. You now need to make sure your mouse or keyboard works every time you boot your computer, so you’ll need to edit the Ubuntu Bluetooth configuration file. Type the following in the GNOME Terminal window to open the configuration file in Gedit:
gksu gedit /etc/default/bluetooth
Search for the line that reads HIDD_ENABLED=0 (on its own, with no other text on the line), and change it to HIDD_ENABLED=1.
Beneath this will be a line that begins HIDD_OPTIONS=. Change this so it reads as follows, again replacing xx:xx:xx:xx:xx:xx with the MAC address you discovered earlier:
HIDD_OPTIONS="-i xx:xx:xx:xx:xx:xx --server"
Save the file and reboot.
Tip If you want to quickly connect a Bluetooth keyboard or mouse to your computer, but don’t need to make it permanent, just open a GNOME Terminal window (Applications -> Accessories -> Terminal), and type "sudo hidd --search".