This article describes how to use Bluetooth in Embedded Linux. For modules that don't come with Bluetooth hardware on-module, support can easily be added by using a USB Bluetooth module. The table below presents the modules with integrated Bluetooth:
|Colibri||iMX6ULL V1.0A||512MB Wi-Fi / Bluetooth||Wi2Wi WM828CC6||Bluetooth 4.2/BLE (Dual-Mode)|
|Colibri||iMX6ULL V1.1A+||512MB Wi-Fi / Bluetooth||Azureware AW-CM276NF||Bluetooth 4.2/BLE (Dual-Mode)|
Since the BSP 2.7b4, Bluetooth support is added to the Toradex pre-built image through the kernel driver backports with BlueZ 5 bluetooth software stack. Please see the article below for instructions about how to cross-compile the driver backports:
Bluetooth support was either compiled into the kernel, or not shipped at all. Please see the details below:
BlueZ 5 is already shipped in the Toradex pre-built image and is the software stack used for Bluetooth interaction.
Additional user space utilities can be added to a custom Linux image. For this an OpenEmbedded build is required. Please refer the following article for setup of the same:
An example is provided with some useful packages. Add the following to "~/oe-core/build/conf/local.conf":
IMAGE_INSTALL_append = " obexftp obex-data-server obex-client python-dbus python-pygobject python-pybluez"
Build the image for the module to be used and flash the image on the module.
A USB Bluetooth module should be detected after connecting it to the USB port (if using a Bluetooth USB dongle):
root@colibri-vf:~# lsusbBus 001 Device 005: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)
There is a systemd Bluetooth service already enabled. Start it:
root@colibri-vf:~# systemctl start bluetooth.service
Enable the Bluetooth device using ConnMan.
root@colibri-imx6ull:~# connmanctl enable bluetoothEnabled bluetooth
hciconfig should show the connected bluetooth devices up and running. Other information such as the MAC address and device bus are also provided.
For a USB dongle:
root@colibri-vf:~# hciconfighci0: Type: BR/EDR Bus: USBBD Address: 00:1A:7D:DA:71:13 ACL MTU: 310:10 SCO MTU: 64:8UP RUNNINGRX bytes:574 acl:0 sco:0 events:30 errors:0TX bytes:368 acl:0 sco:0 commands:30 errors:0
For an SDIO module:
root@colibri-imx6ull:~# hciconfighci0: Type: Primary Bus: SDIOBD Address: 00:19:88:5E:10:B1 ACL MTU: 1021:7 SCO MTU: 120:6UP RUNNINGRX bytes:1882 acl:0 sco:0 events:83 errors:0TX bytes:2075 acl:0 sco:0 commands:83 errors:0
See below instructions for BSP release 2.7b3 and older:
Starting with BSP version 2.7, bluetoothctl was added to the Linux image. It enables scanning, pairing and connecting to devices, among other features.
root@colibri-imx6ull:~# bluetoothctl[NEW] Controller 00:19:88:5E:10:B1 colibri-imx6ull [default]Agent registered
List all available options:
[bluetooth]# helpAvailable commands:list List available controllersshow [ctrl] Controller information...
Scan for Bluetooth devices:
[bluetooth]# scan on
After you enable scanning, it will begin to list available devices:
Discovery started[CHG] Controller 00:19:88:5E:10:B1 Discovering: yes[NEW] Device 98:39:8E:1B:D8:88 Galaxy A5 (2016)[CHG] Device 98:39:8E:1B:D8:88 RSSI: -86
The device number listed is the device MAC address. In the example above its value is 98:39:8E:1B:D8:88. You can stop scanning once you find the device you are looking for:
[bluetooth]# scan off
Pair to the device using its MAC address:
[bluetooth]# pair 98:39:8E:1B:D8:88Attempting to pair with 98:39:8E:1B:D8:88[CHG] Device 98:39:8E:1B:D8:88 Connected: yesRequest confirmation[agent] Confirm passkey 117022 (yes/no):
Confirm that the passkey is the same as displayed on your device:
[agent] Confirm passkey 117022 (yes/no): yes[CHG] Device 98:39:8E:1B:D8:88 Modalias: bluetooth:v0075p0100d0200[CHG] Device 98:39:8E:1B:D8:88 UUIDs: 00001105-0000-1000-8000-00805f9b34fb...[CHG] Device 98:39:8E:1B:D8:88 ServicesResolved: yes[CHG] Device 98:39:8E:1B:D8:88 Paired: yesPairing successful...[CHG] Device 98:39:8E:1B:D8:88 Connected: no
Trust paired device:
[bluetooth]# trust 98:39:8E:1B:D8:88[CHG] Device 98:39:8E:1B:D8:88 Trusted: yesChanging 98:39:8E:1B:D8:88 trust succeeded
Connect to the Bluetooth device:
[bluetooth]# connect 98:39:8E:1B:D8:88Attempting to connect to 98:39:8E:1B:D8:88[CHG] Device 98:39:8E:1B:D8:88 Connected: yesConnection successful[CHG] Device 98:39:8E:1B:D8:88 ServicesResolved: yes[Galaxy A5 (2016)]#
List the connected device information, including supported services:
[Galaxy A5 (2016)]# info 98:39:8E:1B:D8:88Device 98:39:8E:1B:D8:88Name: Galaxy A5 (2016)Alias: Galaxy A5 (2016)Class: 0x5a020cIcon: phonePaired: yesTrusted: yesBlocked: noConnected: yesLegacyPairing: noUUID: OBEX Object Push (00001105-0000-1000-8000-00805f9b34fb)UUID: Audio Source (0000110a-0000-1000-8000-00805f9b34fb)UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)UUID: Headset AG (00001112-0000-1000-8000-00805f9b34fb)UUID: PANU (00001115-0000-1000-8000-00805f9b34fb)UUID: NAP (00001116-0000-1000-8000-00805f9b34fb)UUID: Handsfree Audio Gateway (0000111f-0000-1000-8000-00805f9b34fb)UUID: Phonebook Access Server (0000112f-0000-1000-8000-00805f9b34fb)UUID: Message Access Server (00001132-0000-1000-8000-00805f9b34fb)UUID: PnP Information (00001200-0000-1000-8000-00805f9b34fb)UUID: Generic Access Profile (00001800-0000-1000-8000-00805f9b34fb)UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)UUID: Vendor specific (936da01f-9abd-4d9d-80c7-02af85c822a8)Modalias: bluetooth:v0075p0100d0200ManufacturerData Key: 0x0075ManufacturerData Value: 0x77ManufacturerData Value: 0x98ManufacturerData Value: 0x39ManufacturerData Value: 0x8eManufacturerData Value: 0x1bManufacturerData Value: 0xd8ManufacturerData Value: 0x88
Warning: At this point, obexftp and other old utilities like rfcomm or sdptool don't seem to work correctly with BlueZ 5.46+.
In order to use other some of the availables profiles offered by BlueZ 5, it is necessary to launch your own program that would be make discoverable the desired profile rather than be available by default. You may find more information about this under BlueZ 5 D-Bus API Documentation.
Here there is an example of an SPP echo server and client that will make the serial port service available for other devices: SPP BlueZ5 example
PyBluez is a Python module that allows access to system Bluetooth resources. See how to add it to a custom Linux image in the section Custom Image above. Check the project GitHub page for documentation.
If you would like to test the samples provided by PyBluez, clone the git repository to the board:
opkg updateopkg install gitgit clone https://github.com/karulis/pybluez.git
Then you can run the samples using the Python interpreter:
You must pair to another device before transferring files. Please see the Bluetoothctl section above for an example on how to pair.
Alternatively, a Python sample for pairing is provided below. Currently it only works with BSP version 2.5 and bluez4.
On an Android Lollipop device install an application like Bluetooth File Transfer which provides the obexftp service. Enable Bluetooth and open the Bluetooth File Transfer application for enabling obexftp service on the Android device.
For some Android devices running Icecream Sandwich, the obexftp service might be available by default which could be enabled from the Bluetooth settings or elsewhere depending on the device.
From the module a file can be transferred as follows.
root@colibri-vf:~# obexftp -b 14:DD:A9:36:DD:FC -p file.txtBrowsing 14:DD:A9:36:DD:FC ...Connecting..\doneTried to connect for 20msSending "file.txt"...|doneDisconnecting../done
The transferred file is now available on the device and is shown by the Bluetooth File Transfer application.
The python packages python-dbus, python-pygobject and python itself are added for using D-Bus with Python in the simple-agent python script which is used for pairing. On a device with limited NAND flash like the Colibri VF50 it is possible that the generated image with these packages included, might not fit in the flash memory. It should be possible to do what the simple-agent python script does using the low-level D-Bus C API.