Difference between revisions of "Transclusion: Debian: CL-SOM-iMX7: Bluetooth"
 (New page: CL-SOM-iMX7 features Bluetooth 4.1 BLE interface, implemented with a TI WiLink8 Combo module.  ==== Host Controller Interface (HCI) Initialization ====  * HCI requires no user interaction ...)  | 
				 (→Bluez5 & PulseAudio)  | 
				||
| Line 5: | Line 5: | ||
Make sure that the Bluetooth driver is loaded:  | Make sure that the Bluetooth driver is loaded:  | ||
<pre>  | <pre>  | ||
| − | root@cl-  | + | root@cl-rootfs:~# lsmod | grep btwilink  | 
btwilink                3822  0  | btwilink                3822  0  | ||
</pre>  | </pre>  | ||
The Bluetooth driver can be loaded manually:  | The Bluetooth driver can be loaded manually:  | ||
<pre>  | <pre>  | ||
| − | root@cl-  | + | root@cl-rootfs:~# modprobe btwilink  | 
</pre>  | </pre>  | ||
* HCI device configuration utility can be run to retrieve detailed information about the Bluetooth interfaces:  | * HCI device configuration utility can be run to retrieve detailed information about the Bluetooth interfaces:  | ||
<pre>  | <pre>  | ||
| − | root@cl-  | + | root@cl-rootfs:~# hciconfig hci0 -a  | 
hci0:   Type: BR/EDR  Bus: UART  | hci0:   Type: BR/EDR  Bus: UART  | ||
         BD Address: 74:DA:EA:F9:CE:E3  ACL MTU: 1021:6  SCO MTU: 180:4  |          BD Address: 74:DA:EA:F9:CE:E3  ACL MTU: 1021:6  SCO MTU: 180:4  | ||
| Line 36: | Line 36: | ||
* If the HCI device is not running, use the below command to enable the HCI device:  | * If the HCI device is not running, use the below command to enable the HCI device:  | ||
<pre>  | <pre>  | ||
| − | root@cl-  | + | root@cl-rootfs:~# hciconfig hci0 up  | 
</pre>  | </pre>  | ||
* HCI Inquire remote devices.  | * HCI Inquire remote devices.  | ||
<pre>  | <pre>  | ||
| − | root@cl-  | + | root@cl-rootfs:~# hcitool scan  | 
Scanning ...  | Scanning ...  | ||
</pre>  | </pre>  | ||
| Line 48: | Line 48: | ||
BlueZ 5 dropped support for alsa, so the solution for now is to use PulseAudio.<br>  | BlueZ 5 dropped support for alsa, so the solution for now is to use PulseAudio.<br>  | ||
PulseAudio 5 only supports the A2DP profile and not HSP/HFP. <br>  | PulseAudio 5 only supports the A2DP profile and not HSP/HFP. <br>  | ||
| − | * Software to install {{filename|  | + | * Software to install {{filename|pulseaudio}}, {{filename|pulseaudio-module-bluetooth}}  | 
| − | {{Note|{{filename|  | + | {{Note|{{filename|debian-image.tar.bz2}} has all these packages pre-installed. Continue to the [[#Start PulseAudio | Start PulseAudio]] section if you use this root filesystem.}}  | 
===== Install and configure PulseAudio =====  | ===== Install and configure PulseAudio =====  | ||
<pre>  | <pre>  | ||
| − | root@cl-  | + | root@cl-rootfs:~# apt-get install --no-install-recommends pulseaudio pulseaudio-module-bluetooth  | 
</pre>  | </pre>  | ||
* Create a systemd service for running pulseaudio as the pulse user.  | * Create a systemd service for running pulseaudio as the pulse user.  | ||
<pre>  | <pre>  | ||
| − | root@cl-  | + | root@cl-rootfs:~# cat << eof > /etc/systemd/system/pulseaudio.service  | 
[Unit]  | [Unit]  | ||
Description=Pulse Audio  | Description=Pulse Audio  | ||
| Line 68: | Line 68: | ||
eof  | eof  | ||
| − | root@cl-  | + | root@cl-rootfs:~# chown pulse:pulse /etc/systemd/system/pulseaudio.service  | 
</pre>  | </pre>  | ||
* Create a dbus configuration file for running pulseaudio. Give the pulse user permission to use Bluetooth.  | * Create a dbus configuration file for running pulseaudio. Give the pulse user permission to use Bluetooth.  | ||
<pre>  | <pre>  | ||
| − | root@cl-  | + | root@cl-rootfs:~# cat << eof > /etc/dbus-1/system.d/pulseaudio-bluetooth.conf  | 
<busconfig>  | <busconfig>  | ||
| Line 83: | Line 83: | ||
eof  | eof  | ||
| − | root@cl-  | + | root@cl-rootfs:~# chmod 0666 /etc/dbus-1/system.d/pulseaudio-bluetooth.conf  | 
</pre>  | </pre>  | ||
* Paste the following lines to the end of /etc/pulse/system.pa:  | * Paste the following lines to the end of /etc/pulse/system.pa:  | ||
<pre>  | <pre>  | ||
| − | root@cl-  | + | root@cl-rootfs:~# cat << eof >> /etc/pulse/system.pa  | 
### Automatically load driver modules for Bluetooth hardware  | ### Automatically load driver modules for Bluetooth hardware  | ||
.ifexists module-bluetooth-policy.so  | .ifexists module-bluetooth-policy.so  | ||
| Line 100: | Line 100: | ||
* Create {{filename|/var/run/pulse/.config/pulse}} directory. Change its ownership.  | * Create {{filename|/var/run/pulse/.config/pulse}} directory. Change its ownership.  | ||
<pre>  | <pre>  | ||
| − | root@cl-  | + | root@cl-rootfs:~# mkdir -p /var/run/pulse/.config/pulse  | 
| − | root@cl-  | + | root@cl-rootfs:~# chown -R pulse:pulse /var/run/pulse  | 
</pre>  | </pre>  | ||
* Make the root belong to the pulse-access,audio groups  | * Make the root belong to the pulse-access,audio groups  | ||
<pre>  | <pre>  | ||
| − | root@cl-  | + | root@cl-rootfs:~# usermod -a -G pulse-access,audio root  | 
</pre>  | </pre>  | ||
| Line 111: | Line 111: | ||
* Start PulseAudio service  | * Start PulseAudio service  | ||
<pre>  | <pre>  | ||
| − | root@cl-  | + | root@cl-rootfs:~# systemctl daemon-reload  | 
| − | root@cl-  | + | root@cl-rootfs:~# systemctl start pulseaudio.service  | 
</pre>  | </pre>  | ||
* Make sure that the service is active, running and reports on no errors.  | * Make sure that the service is active, running and reports on no errors.  | ||
<pre>  | <pre>  | ||
| − | root@cl-  | + | root@cl-rootfs:~# systemctl status pulseaudio.service  | 
    Loaded: loaded (/etc/systemd/system/pulseaudio.service; disabled)  |     Loaded: loaded (/etc/systemd/system/pulseaudio.service; disabled)  | ||
    Active: active (running) since Mon 2015-07-20 12:00:13 UTC; 1min 34s ago  |     Active: active (running) since Mon 2015-07-20 12:00:13 UTC; 1min 34s ago  | ||
| Line 128: | Line 128: | ||
Make sure the following packages are installed:  | Make sure the following packages are installed:  | ||
pulseaudio pulseaudio-module-bluetooth pulseaudio-utils, bluez, bluez-tools.  | pulseaudio pulseaudio-module-bluetooth pulseaudio-utils, bluez, bluez-tools.  | ||
| − | {{Note|Without {{filename|  | + | {{Note|Without {{filename|pulseaudio-module-bluetooth}} you won't be able to connect after the next pairing and you won't get any usable error messages.}}  | 
* Start the Bluetooth system:  | * Start the Bluetooth system:  | ||
<pre>  | <pre>  | ||
| − | root@cl-  | + | root@cl-rootfs:~# systemctl start bluetooth  | 
</pre>  | </pre>  | ||
| − | Now we can use the {{  | + | Now we can use the {{cmd|bluetoothctl}} command line utility to pair and connect. Run  | 
<pre>  | <pre>  | ||
| − | root@cl-  | + | root@cl-rootfs:~# bluetoothctl  | 
[bluetooth]#  | [bluetooth]#  | ||
</pre>  | </pre>  | ||
| Line 170: | Line 170: | ||
* Show the PulseAudio device    | * Show the PulseAudio device    | ||
<pre>  | <pre>  | ||
| − | root@cl-  | + | root@cl-rootfs:~# pactl list cards  | awk '/00_07_A4_F2_B3_CB/' RS=""  | 
Card #1                                                                                                                                                                        | Card #1                                                                                                                                                                        | ||
         Name: bluez_card.00_07_A4_F2_B3_CB                                                                                                                                     |          Name: bluez_card.00_07_A4_F2_B3_CB                                                                                                                                     | ||
| Line 204: | Line 204: | ||
:* Show the PulseAudio sink  | :* Show the PulseAudio sink  | ||
<pre>  | <pre>  | ||
| − | root@cl-  | + | root@cl-rootfs:~# pactl list sinks | awk '/00_07_A4_F2_B3_CB/' RS=""  | 
Sink #1  | Sink #1  | ||
         State: SUSPENDED  |          State: SUSPENDED  | ||
| Line 241: | Line 241: | ||
:* Play sound using {{filename|paplay}}. Example:  | :* Play sound using {{filename|paplay}}. Example:  | ||
<pre>  | <pre>  | ||
| − | root@cl-  | + | root@cl-rootfs:~# paplay -d bluez_sink.00_07_A4_F2_B3_CB /path/to/<audio-file.wav>  | 
</pre>  | </pre>  | ||
Revision as of 14:16, 8 May 2017
CL-SOM-iMX7 features Bluetooth 4.1 BLE interface, implemented with a TI WiLink8 Combo module.
Contents
Host Controller Interface (HCI) Initialization
- HCI requires no user interaction for being configured. The driver gets loaded automatically unless this option has been disabled by putting a black list rule for this device.
 
Make sure that the Bluetooth driver is loaded:
root@cl-rootfs:~# lsmod | grep btwilink btwilink 3822 0
The Bluetooth driver can be loaded manually:
root@cl-rootfs:~# modprobe btwilink
- HCI device configuration utility can be run to retrieve detailed information about the Bluetooth interfaces:
 
root@cl-rootfs:~# hciconfig hci0 -a
hci0:   Type: BR/EDR  Bus: UART
        BD Address: 74:DA:EA:F9:CE:E3  ACL MTU: 1021:6  SCO MTU: 180:4
        UP RUNNING 
        RX bytes:636 acl:0 sco:0 events:39 errors:0
        TX bytes:1234 acl:0 sco:0 commands:39 errors:0
        Features: 0xff 0xfe 0x2d 0xfe 0xdb 0xff 0x7b 0x87
        Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 
        Link policy: RSWITCH HOLD SNIFF 
        Link mode: SLAVE ACCEPT 
        Name: 'BlueZ 5.36'
        Class: 0x000000
        Service Classes: Unspecified
        Device Class: Miscellaneous, 
        HCI Version: 4.1 (0x7)  Revision: 0x0
        LMP Version: 4.1 (0x7)  Subversion: 0xac03
        Manufacturer: Texas Instruments Inc. (13)
- If the HCI device is not running, use the below command to enable the HCI device:
 
root@cl-rootfs:~# hciconfig hci0 up
- HCI Inquire remote devices.
 
root@cl-rootfs:~# hcitool scan Scanning ...
Bluez5 & PulseAudio
Debian stretch/sid is using BlueZ 5 and PluseAudio 5, which are fairly new.
BlueZ 5 dropped support for alsa, so the solution for now is to use PulseAudio.
PulseAudio 5 only supports the A2DP profile and not HSP/HFP. 
- Software to install pulseaudio, pulseaudio-module-bluetooth
 
| debian-image.tar.bz2 has all these packages pre-installed. Continue to the Start PulseAudio section if you use this root filesystem. | 
Install and configure PulseAudio
root@cl-rootfs:~# apt-get install --no-install-recommends pulseaudio pulseaudio-module-bluetooth
- Create a systemd service for running pulseaudio as the pulse user.
 
root@cl-rootfs:~# cat << eof > /etc/systemd/system/pulseaudio.service [Unit] Description=Pulse Audio [Service] Type=simple ExecStart=/usr/bin/pulseaudio --system --disallow-exit --disable-shm [Install] WantedBy=multi-user.target eof root@cl-rootfs:~# chown pulse:pulse /etc/systemd/system/pulseaudio.service
- Create a dbus configuration file for running pulseaudio. Give the pulse user permission to use Bluetooth.
 
root@cl-rootfs:~# cat << eof > /etc/dbus-1/system.d/pulseaudio-bluetooth.conf
<busconfig>
  <policy user="pulse">
    <allow send_destination="org.bluez"/>
  </policy>
</busconfig>
eof
root@cl-rootfs:~# chmod 0666 /etc/dbus-1/system.d/pulseaudio-bluetooth.conf
- Paste the following lines to the end of /etc/pulse/system.pa:
 
root@cl-rootfs:~# cat << eof >> /etc/pulse/system.pa ### Automatically load driver modules for Bluetooth hardware .ifexists module-bluetooth-policy.so load-module module-bluetooth-policy .endif .ifexists module-bluetooth-discover.so load-module module-bluetooth-discover .endif eof
- Create /var/run/pulse/.config/pulse directory. Change its ownership.
 
root@cl-rootfs:~# mkdir -p /var/run/pulse/.config/pulse root@cl-rootfs:~# chown -R pulse:pulse /var/run/pulse
- Make the root belong to the pulse-access,audio groups
 
root@cl-rootfs:~# usermod -a -G pulse-access,audio root
Start PulseAudio
- Start PulseAudio service
 
root@cl-rootfs:~# systemctl daemon-reload root@cl-rootfs:~# systemctl start pulseaudio.service
- Make sure that the service is active, running and reports on no errors.
 
root@cl-rootfs:~# systemctl status pulseaudio.service
   Loaded: loaded (/etc/systemd/system/pulseaudio.service; disabled)
   Active: active (running) since Mon 2015-07-20 12:00:13 UTC; 1min 34s ago
 Main PID: 805 (pulseaudio)
   CGroup: /system.slice/pulseaudio.service
           └─805 /usr/bin/pulseaudio --system --disallow-exit --disable-shm
Bluez5 pairing
PulseAudio 5.x supports A2DP per default.
Make sure the following packages are installed:
pulseaudio pulseaudio-module-bluetooth pulseaudio-utils, bluez, bluez-tools.
| Without pulseaudio-module-bluetooth you won't be able to connect after the next pairing and you won't get any usable error messages. | 
- Start the Bluetooth system:
 
root@cl-rootfs:~# systemctl start bluetooth
Now we can use the bluetoothctl command line utility to pair and connect. Run
root@cl-rootfs:~# bluetoothctl [bluetooth]#
to be greeted by its internal command prompt.Then enter:
[bluetooth]# power on [bluetooth]# agent on [bluetooth]# default-agent [bluetooth]# scan
Now make sure that your headset is in pairing mode. It should be discovered shortly. For example,
[NEW] Device 00:07:A4:F2:B3:CB Motorola HT820
shows a device that calls itself "Motorola HT820" and has MAC address 00:07:A4:F2:B3:CB. We will now use that MAC address to initiate the pairing:
[bluetooth]# pair 00:07:A4:F2:B3:CB
After pairing, you also need to explicitly connect the device:
[bluetooth]# connect 00:07:A4:F2:B3:CB
If everything works correctly, you now have a separate output device in PulseAudio.
You can now disable scanning again and exit the program:
[bluetooth]# scan off [bluetooth]# exit
Playback using PulseAudio
| Next examples assume that the device mac address is 00_07_A4_F2_B3_CB | 
- Show the PulseAudio device
 
root@cl-rootfs:~# pactl list cards  | awk '/00_07_A4_F2_B3_CB/' RS=""
Card #1                                                                                                                                                                     
        Name: bluez_card.00_07_A4_F2_B3_CB                                                                                                                                  
        Driver: module-bluez5-device.c                                                                                                                                      
        Owner Module: 13                                                                                                                                                    
        Properties:                                                                                                                                                         
                device.description = "Motorola HT820"                                                                                                                       
                device.string = "00:07:A4:F2:B3:CB"                                                                                                                         
                device.api = "bluez"                                                                                                                                        
                device.class = "sound"                                                                                                                                      
                device.bus = "bluetooth"                                                                                                                                    
                device.form_factor = "headset"                                                                                                                              
                bluez.path = "/org/bluez/hci0/dev_00_07_A4_F2_B3_CB"                                                                                                        
                bluez.class = "0x240404"                                                                                                                                    
                bluez.alias = "Motorola HT820"                                                                                                                              
                device.icon_name = "audio-headset-bluetooth"                                                                                                                
                device.intended_roles = "phone"                                                                                                                             
        Profiles:                                                                                                                                                           
                headset_head_unit: Headset Head Unit (HSP/HFP) (sinks: 1, sources: 1, priority: 20, available: no)
                a2dp_sink: High Fidelity Playback (A2DP Sink) (sinks: 1, sources: 0, priority: 10, available: yes)
                off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
        Active Profile: a2dp_sink
        Ports:
                headset-output: Headset (priority: 0, latency offset: 0 usec)
                        Part of profile(s): headset_head_unit, a2dp_sink
                headset-input: Headset (priority: 0, latency offset: 0 usec, not available)
                        Part of profile(s): headset_head_unit
- Make sure the active card profile is a2dp_sink. Otherwise switch to it:
 
# pactl set-card-profile 1 a2dp_sink
- Show the PulseAudio sink
 
root@cl-rootfs:~# pactl list sinks | awk '/00_07_A4_F2_B3_CB/' RS=""
Sink #1
        State: SUSPENDED
        Name: bluez_sink.00_07_A4_F2_B3_CB
        Description: Motorola HT820
        Driver: module-bluez5-device.c
        Sample Specification: s16le 2ch 48000Hz
        Channel Map: front-left,front-right
        Owner Module: 13
        Mute: no
        Volume: front-left: 65536 / 100% / 0.00 dB,   front-right: 65536 / 100% / 0.00 dB
                balance 0.00
        Base Volume: 65536 / 100% / 0.00 dB
        Monitor Source: bluez_sink.00_07_A4_F2_B3_CB.monitor
        Latency: 0 usec, configured 0 usec
        Flags: HARDWARE DECIBEL_VOLUME LATENCY 
        Properties:
                bluetooth.protocol = "a2dp_sink"
                device.description = "Motorola HT820"
                device.string = "00:07:A4:F2:B3:CB"
                device.api = "bluez"
                device.class = "sound"
                device.bus = "bluetooth"
                device.form_factor = "headset"
                bluez.path = "/org/bluez/hci0/dev_00_07_A4_F2_B3_CB"
                bluez.class = "0x240404"
                bluez.alias = "Motorola HT820"
                device.icon_name = "audio-headset-bluetooth"
                device.intended_roles = "phone"
        Ports:
                headset-output: Headset (priority: 0)
        Active Port: headset-output
        Formats:
                pcm
- Play sound using paplay. Example:
 
root@cl-rootfs:~# paplay -d bluez_sink.00_07_A4_F2_B3_CB /path/to/<audio-file.wav>