You are here: Digi Embedded Yocto > System development > Linux v3.14 Board Support Package > Devices and interfaces > Bluetooth

Bluetooth

Some wireless variants of the ConnectCore 6 system-on-module assemble Atheros chip AR6233, which is Bluetooth capable. These modules are built with coexistence in mind and handle the Bluetooth coexistence internally.

The Bluetooth interface is connected to the i.MX6 via the UART2 port and GPIOs for some AR6233-specific pins.

Features

Atheros chip AR6233 supports the following Bluetooth features:

The following profiles have been validated in Digi Embedded Yocto:

Kernel configuration

You can manage the Bluetooth driver support through the kernel configuration option:

This option is enabled as built-in on the default ConnectCore 6 SBC kernel configuration file.

Platform driver mapping

The Atheros AR300x Bluetooth driver is located at drivers/bluetooth/hci_ath.c.

Device tree bindings and customization

Although there are no generic device tree bindings for the Bluetooth driver itself, there is a bluetooth node on the ConnectCore 6 device tree file that contains the following properties:

This node is also used as a placeholder for containing Digi's MAC address for the Bluetooth chip.

ConnectCore 6 device tree
bluetooth {
        digi,pwrdown-gpios = <&gpio_extender 4 0>;
        digi,disable-gpios = <&gpio1 9 0>;
        /* U-Boot will fill in the MAC address here */
};

MAC address

The MAC address of the ConnectCore 6 Bluetooth interface is stored in the ConnectCore 6 eMMC as part of the U-Boot bootloader environment (variable btaddr).

Before launching the operating system, U-Boot writes the MAC address into the device tree bluetooth node as property local-mac-address.

Known issues and limitations

Bluetooth classic usage from user space

To interact with a Bluetooth interface, you can use BlueZ hcitools.

BlueZ hcitools examples

Scan for other Bluetooth devices

hcitool scan --flush 

Many Bluetooth devices are not discoverable unless the user enables discovery on the device.

Make your Bluetooth device discoverable

 # hciconfig hci0 piscan

Pair your device with another device

# simple-agent hci0 <remote-MAC-address>

Ping a previously paired device

# l2ping <remote-MAC-address>

Bluetooth test applications

Oximeter (HDP profile)

Build the package dey-examples-hdp in your Yocto project to install the test application hdp_test.py. This application allows your embedded device (sink) to receive and print measurements from Nonin Onyx II 9560 Pulse oximeter (source).

  1. Run the bluetoothctl application for interactively commanding the Bluetooth interface.
	root@ccimx6sbc:~# bluetoothctl
	[bluetooth]#
  1. Power on the Bluetooth and enable an agent.

	[bluetooth]# power on
        Changing power on succeeded
        [bluetooth]# agent KeyboardOnly
        Agent registered
        [bluetooth]# default-agent
        Default agent request successful
  1. Enable scanning.

	[bluetooth]# scan on
        Discovery started
        [CHG] Controller 00:40:9D:8B:86:97 Discovering: yes
  1. Put your finger into the oximeter to make it discoverable and wait until its MAC address shows up (it may take about 30 seconds).
	[NEW] Device 00:1C:05:00:49:C9 00-1C-05-00-49-C9
        [CHG] Device 00:1C:05:00:49:C9 LegacyPairing: no
        [CHG] Device 00:1C:05:00:49:C9 Name: Nonin_Medical_Inc._285001
        [CHG] Device 00:1C:05:00:49:C9 Alias: Nonin_Medical_Inc._285001
  1. Turn off the scan process and pair the controller and the oximeter (during this process the controller asks for the PIN code, which is 285001 in this example).
	[bluetooth]# scan off
        [CHG] Device 00:1C:05:00:49:C9 RSSI is nil
        Discovery stopped
        [CHG] Controller 00:40:9D:8B:86:97 Discovering: no
         
        [bluetooth]# pair 00:1C:05:00:49:C9
        Attempting to pair with 00:1C:05:00:49:C9
        [CHG] Device 00:1C:05:00:49:C9 Connected: yes
        Request PIN code
        [agent] Enter PIN code: 285001
        [CHG] Device 00:1C:05:00:49:C9 Modalias: usb:v1C3Dp186Cd0600
        [CHG] Device 00:1C:05:00:49:C9 UUIDs: 00001101-0000-1000-8000-00805f9b34fb
        [CHG] Device 00:1C:05:00:49:C9 UUIDs: 00001200-0000-1000-8000-00805f9b34fb
        [CHG] Device 00:1C:05:00:49:C9 UUIDs: 00001401-0000-1000-8000-00805f9b34fb
        [CHG] Device 00:1C:05:00:49:C9 Paired: yes
        Pairing successful
        [CHG] Device 00:1C:05:00:49:C9 Connected: no
  1. Exit the bluetoothctl interactive shell with the quit command.
	[bluetooth]# exit
        [DEL] Controller 00:40:9D:7D:97:60 BlueZ 5.33 [default]
  1. Launch the hdp-test.py script and put your finger into the oximeter.
	root@ccimx6sbc:~# python hdp_test.py
        HDP application created, waiting for connection from
        a pulse oximeter. Press control-c to terminate.
        /org/bluez/hci0/dev_00_1C_05_00_49_C9 has connected
        SpO2 Level: 99, Beats/second: 53
        Disconnected from oximeter        

Tip Make sure the oximeter's batteries contain enough charge. Low batteries can prevent the oximeter from being detected or make it unable to pair.

Transfer a file (RFCOMM socket level)

Build the package dey-examples-bt in your Yocto project to install the test application bt_test.

The bt_test application demonstrates how to transfer data between two stations with Bluetooth. The application creates a Bluetooth socket connection at RFCOMM level (BTPROTO_RFCOMM) for data transmission/reception. You need to run this application on two different Bluetooth-capable devices.

  1. Perform a Bluetooth scan in your embedded device.
	# hcitool scan --flush
	Scanning ...
		00:16:A4:06:BF:CD       host_420260
  1. To pair the two devices, launch the simple_agent as listener on the embedded device.
	# /usr/lib/bluez/test/simple-agent
	Agent registered

Then launch the agent on the other device to pair with the MAC address of your embedded device.

	# /usr/lib/bluez/test/simple-agent hci0 <embedded-MAC-address>

The listener embedded device registers the connection and asks for confirmation of the pairing.

 	RequestConfirmation (/org/bluez/635/hci0/dev_00_16_A4_06_BF_CD, 311373)
	Confirm passkey (yes/no): yes

Note You only need to do the pairing once.

  1. Start the application on the receiver device first, indicating the path and filename to be created.
	# bt_test --file=<destination_filename>
  1. Start the application on the transmitter device, indicating the receiver MAC and the file to transfer.
	# bt_test --master --destination=<receiver_mac> --file=<transfer_filename>

Bluetooth Low Energy (BLE) usage from user space

Example using BlueZ

You can use the BlueZ tools to scan and interact with your BLE device.

  1. Turn on your BLE device and start the advertisement. Some BLE devices require you to press a button to do the advertisement. The duration of advertisement can be limited (normally 30 seconds), so you will need to repeat the advertisement process if you do not scan before that time elapses.
  1. Scan for BLE devices.
	root@ccimx6sbc:~# hcitool lescan
        LE Scan ...
        00:16:A4:06:BA:7B (unknown)
        00:16:A4:06:BA:7B myBleDevice
  1. Use gatttool to connect with a remote device in interactive mode.
	root@ccimx6sbc:~# gatttool -b 00:16:A4:06:BA:7B -I
	[00:16:A4:06:BA:7B][LE]> connect
	Attempting to connect to 00:16:A4:06:BA:7B
	Connection successful
	[00:16:A4:06:BA:7B][LE]>

Tip Some BLE devices do not accept connections unless you use a random MAC address (option -t random of gatttool command).

  1. Type primary to read the primary attributes the device supports.
	[00:16:A4:06:BA:7B][LE]> primary
	attr handle: 0x0001, end grp handle: 0x0008 uuid: 00001800-0000-1000-8000-00805f9b34fb
	attr handle: 0x0009, end grp handle: 0x000c uuid: 0000a002-0000-1000-8000-00805f9b34fb
	attr handle: 0x0010, end grp handle: 0x0010 uuid: 00001801-0000-1000-8000-00805f9b34fb
	attr handle: 0x001b, end grp handle: 0x0025 uuid: 0000a004-0000-1000-8000-00805f9b34fb
	attr handle: 0x0026, end grp handle: 0x0028 uuid: 00001803-0000-1000-8000-00805f9b34fb
	attr handle: 0x0029, end grp handle: 0x002c uuid: 00001804-0000-1000-8000-00805f9b34fb
	attr handle: 0x002d, end grp handle: 0x002f uuid: 00001802-0000-1000-8000-00805f9b34fb
	attr handle: 0x0030, end grp handle: 0x0035 uuid: 00001805-0000-1000-8000-00805f9b34fb
	attr handle: 0x0036, end grp handle: 0x003a uuid: 00001806-0000-1000-8000-00805f9b34fb
	attr handle: 0x003b, end grp handle: 0x0043 uuid: 0000180e-0000-1000-8000-00805f9b34fb
	attr handle: 0x0044, end grp handle: 0x0050 uuid: 00001811-0000-1000-8000-00805f9b34fb
	attr handle: 0xfffa, end grp handle: 0xfffe uuid: feee74dc-a8de-3196-1149-d43596c00a4f
	[00:16:A4:06:BA:7B][LE]> 

The UUIDs in the list point to services supported by the BLE device. For example, the first tuple of the first UUID in the list (00001800) is the "Generic Access"; 00001801 corresponds to "Generic Attribute", and so on. The full list is available at https://developer.bluetooth.org/gatt/services/Pages/ServicesHome.aspx.

  1. Type characteristics to get a list of the characteristics of your BLE device.
	[00:16:A4:06:BA:7B][LE]> characteristics
	handle: 0x0004, char properties: 0x02, char value handle: 0x0006, uuid: 00002a00-0000-1000-8000-00805f9b34fb
	handle: 0x0007, char properties: 0x02, char value handle: 0x0008, uuid: 00002a01-0000-1000-8000-00805f9b34fb
	handle: 0x000a, char properties: 0x12, char value handle: 0x000b, uuid: 0000a003-0000-1000-8000-00805f9b34fb
	handle: 0x000e, char properties: 0x02, char value handle: 0x000f, uuid: 0000a00f-0000-1000-8000-00805f9b34fb
	handle: 0x0012, char properties: 0x02, char value handle: 0x0013, uuid: 0000a00c-0000-1000-8000-00805f9b34fb
	handle: 0x0014, char properties: 0x02, char value handle: 0x0015, uuid: 0000a00d-0000-1000-8000-00805f9b34fb
	handle: 0x0017, char properties: 0x02, char value handle: 0x0018, uuid: 0000a00c-0000-1000-8000-00805f9b34fb
	handle: 0x0019, char properties: 0x02, char value handle: 0x001a, uuid: 0000a00d-0000-1000-8000-00805f9b34fb
	handle: 0x001e, char properties: 0x02, char value handle: 0x001f, uuid: 0000a006-0000-1000-8000-00805f9b34fb
	handle: 0x0022, char properties: 0x02, char value handle: 0x0023, uuid: 0000a009-0000-1000-8000-00805f9b34fb
	handle: 0x0027, char properties: 0x0a, char value handle: 0x0028, uuid: 00002a06-0000-1000-8000-00805f9b34fb
	handle: 0x002a, char properties: 0x12, char value handle: 0x002b, uuid: 00002a07-0000-1000-8000-00805f9b34fb
	handle: 0x002e, char properties: 0x04, char value handle: 0x002f, uuid: 00002a06-0000-1000-8000-00805f9b34fb
	handle: 0x0031, char properties: 0x12, char value handle: 0x0032, uuid: 00002a2b-0000-1000-8000-00805f9b34fb
	handle: 0x0034, char properties: 0x02, char value handle: 0x0035, uuid: 00002a0f-0000-1000-8000-00805f9b34fb
	handle: 0x0037, char properties: 0x04, char value handle: 0x0038, uuid: 00002a16-0000-1000-8000-00805f9b34fb
	handle: 0x0039, char properties: 0x02, char value handle: 0x003a, uuid: 00002a17-0000-1000-8000-00805f9b34fb
	handle: 0x003c, char properties: 0x12, char value handle: 0x003d, uuid: 00002a3f-0000-1000-8000-00805f9b34fb
	handle: 0x003f, char properties: 0x04, char value handle: 0x0040, uuid: 00002a40-0000-1000-8000-00805f9b34fb
	handle: 0x0041, char properties: 0x12, char value handle: 0x0042, uuid: 00002a41-0000-1000-8000-00805f9b34fb
	handle: 0x0045, char properties: 0x02, char value handle: 0x0046, uuid: 00002a47-0000-1000-8000-00805f9b34fb
	handle: 0x0047, char properties: 0x10, char value handle: 0x0048, uuid: 00002a46-0000-1000-8000-00805f9b34fb
	handle: 0x004a, char properties: 0x02, char value handle: 0x004b, uuid: 00002a48-0000-1000-8000-00805f9b34fb
	handle: 0x004c, char properties: 0x10, char value handle: 0x004d, uuid: 00002a45-0000-1000-8000-00805f9b34fb
	handle: 0x004f, char properties: 0x08, char value handle: 0x0050, uuid: 00002a44-0000-1000-8000-00805f9b34fb
	handle: 0xfffc, char properties: 0x02, char value handle: 0xfffd, uuid: e9258c1e-8962-c4b6-0b45-2c9018f28880
	[00:16:A4:06:BA:7B][LE]> 

The UUIDs in the list point to supported characteristics of the BLE device. For example, the first tuple of the first UUID in the list (00002a00) is the "Device Name". The full list is available at https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicsHome.aspx.

  1. Type char-read-hnd <value> to read any characteristic using a handler.
 	[00:16:A4:06:BA:7B][LE]> char-read-hnd 0x004c
	Characteristic value/descriptor: 10 4d 00 45 2a
	[00:16:A4:06:BA:7B][LE]>

Tip Handlers and characteristics are device-specific. Refer to the manual for your BLE device to learn more.

 

© 2017 Digi International Inc. All rights reserved.
Bluetooth updated on 24 April 2017 11:48:25 PM