Conquer Bluetooth in Linux

Source: Internet
Author: User
Conquer Bluetooth in Linux-general Linux technology-Linux technology and application information. The following is a detailed description. This article is my notes on installing and using Bluetooth headsets in ubuntu.

The kernel support for Bluetooth is not covered in this article. The default configuration of the system has met the requirements. If you are interested, refer to the relevant articles in the references.

Let's take a look at the various software packages involved.

Bluez-hcidump-Analyses Bluetooth HCI packets // recommended for debugging
Bluez-pcmcia-support-PCMCIA support files for BlueZ 2.0 Bluetooth tools // when your Bluetooth adapter is a PC Card Interface
Bluez-pin-Bluetooth PIN helper with D-BUS support // tool for entering verification code when connecting a Bluetooth device, such as a headset
Bluez-utils-Bluetooth tools and daemons // core support, must be installed
Bluez-btsco-Bluez Bluetooth SCO tool // required to connect to a Bluetooth headset
Gnome-bluetooth-GNOME Bluetooth tools. // a bluetooth device scan tool that uses Bluetooth to send and receive files
Alsaplayer-alsa-PCM player designed for ALSA (ALSA output module) // alsa related tools, recommended

We recommend that you first plug the Bluetooth adapter into your computer and then install the above software.

Hcitool dev

The following information is displayed:

Devices:
Hci0 00: 08: 1B: 83: C7: 91

If not, the driver is faulty.
If you have a Bluetooth phone, you can use it to transfer files with your computer.
To send a file to a computer, run it on the computer first.

Gnome-obex-server

Please send a file to your mobile phone

Gnome-obex-send filename

(We recommend that you create an alias instance for the preceding two commands)

Install necessary software. There are two configuration files that need attention.

I./etc/bluetooth/hcid. conf
Most of the online materials are about to modify this file. However, according to my practice, this file can be used normally without any modifications.
However, if your Bluetooth device is fixed (for example, I only have one Bluetooth headset), we recommend that you make the following changes:
Create a file/home/ahlong/bt-pin.sh
Content is

#! /Bin/sh
Echo "PIN: 0000 ″

"0000" is the headset verification code, which can be found in the random document.

Chmod a + x/home/ahlong/bt-pin.sh

Change the file to executable. Do not forget (852 words are omitted here ).
Find the section below the configuration file

# PIN helper
Pin_helper/usr/bin/pinwrapper;

And change "/usr/bin/pinwrapper" to "/home/ahlong/bt-pin.sh ".
In this way, the steps in the pop-up dialog box in btsco can be omitted directly.

Ii./etc/bluetooth/rfcomm. conf
Before proceeding to this step, you must first obtain the identification code of the headset.

Hcitool scan

Scan the device. If there is no output, try the following command and then scan again (the following two commands may not be used at this time ):

Sudo hciconfig hci0 down
Sudo hciconfig hci0 up

If no output is available, make sure that your headset is in the "discoverable" status. For more information, see the device random document.
Here we get 00: 03: 89: 4A: 96: 6D.
Now you can change the configuration file to something similar to the following.

Rfcomm0 {
Bind yes;
# Bluetooth address of the device
Device 00: 03: 89: 4A: 96: 6D;
# RFCOMM channel for the connection
Channel 2;
# Description of the connection
Comment ahlong-M3000 ″;
}

How is the above channel value determined?

Sdptool records 00: 03: 89: 4A: 96: 6D

This command is used to scan the number of Bluetooth applications supported by 00: 03: 89: 4A: 96: 6D.
Below is my output:

Service Name: M3000 by plantrow.
Service RecHandle: 0 × 10000
Service Class ID List:
"Headset" (0 × 1108)
"Generic Audio" (0 × 1203)
Protocol Descriptor List:
"L2CAP" (0 × 0100)
"RFCOMM" (0 × 0003)
Channel: 1
Language Base Attr List:
Code_ISO639: 0 × 656e
Encoding: 0 x 6a
Base_offset: 0x100
Profile Descriptor List:
"Headset" (0 × 1108)
Version: 0 × 0100

Service Name: M3000 by plantrow.
Service RecHandle: 0 × 10001
Service Class ID List:
"Handsfree" (0 × 111e)
"Generic Audio" (0 × 1203)
Protocol Descriptor List:
"L2CAP" (0 × 0100)
"RFCOMM" (0 × 0003)
Channel: 2
Language Base Attr List:
Code_ISO639: 0 × 656e
Encoding: 0 x 6a
Base_offset: 0x100
Profile Descriptor List:
"Handsfree" (0 × 111e)
Version: 0 × 0100

We can see from the above that this Bluetooth Headset supports "Headset" and "Handsfree", and of course "Generic Audio ".
You can set the Channel to 1 or 2. However, I found that when set to 1, it seems that when XMMS finishes playing a song, it will stop at the beginning of the next song, so I chose 2.

Add multiple rfcommX {……} when multiple Bluetooth devices exist {......} You can.

To listen to music with a Bluetooth headset, You need to load the snd_bt_sco Module

Sudo modprobe snd_bt_sco

After execution, a sound card device (/dev/dsp2 here) will be added to the system ). You can see it in the menu of gnome-volume-control.
For ease of use, we recommend that you add snd_bt_sco to/etc/modules.

When you want to use Bluetooth to listen to music, open a console and enter

Btsco 00: 03: 89: 4A: 96: 6D 2

2 is the channel. It seems that it can be omitted.
Normally, there will be no output. Make sure that the window is not closed.
In particular, because the address is explicitly specified, the headset is not required to be "discoverable.

In this way, Bluetooth headsets are available, but Bluetooth headsets are not the default sound card device. Therefore, you must manually specify it in the software.
In XMMS, select the output driver as alsa, click Configure, and select "BT" in the audio device.
Mplayer does not recognize sound cards as good as XMMS. Similarly, select alsa and manually enter device into hw =. The value of hw = is related to your computer hardware configuration. It can be read in XMMS or inferred based on the sequence of gnome-volume-control.
A sound card can only be used by one program at a time.
How can I enable skype to use Bluetooth headsets?

Click Tools> Options> Sound Devices in sequence;

Select ALSA at audio system to use;

Select all of the following values as Bt Headset.

If alsaplayer is installed, you can use

Aplay-D plughw: 1, 0 xx2.wav

Play music to a Bluetooth headset;

Arecord-d 10-f cd-t wav-D plughw: 1, 0 bt0.wav

Record a 10 s recording.
If no sound is recorded, check the mic volume settings (via gnome-volume-control ).

You can use

Sudo hcidump

Assist in diagnosis.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.