Search by Tags

Basic Bluetooth usage

 

Your progress

 

Overview

In this how-to section, you will enable the on-module Bluetooth and pair/connect to a device.

In this section you will:

  • Enable Bluetooth.
  • Scan for available devices.
  • Pair and connect to your smartphone.

The network manager used in the Toradex pre-built Linux images is ConnMan. This lesson was written based on the Toradex knowledge-base article Bluetooth (Linux).

Step 1

Access the Linux terminal and enable the Bluetooth interface:

connmanctl enable bluetooth

You should see a message printed on the terminal such as the one below:

Enabled bluetooth

Step 2

Start bluetoothctl

bluetoothctl

An output similar to the following will be printed and the console prompt will change:

[NEW] Controller 00:19:88:5E:10:B1 colibri-imx6ull [default]
Agent registered
[bluetooth]#

Step 3

Start scanning for Bluetooth devices:

[bluetooth]# scan on

Note: Make sure your smartphone's Bluetooth function is on and that it is visible to other devices.

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
[CHG] Device 98:39:8E:1B:D8:88 RSSI: -71
[CHG] Device 98:39:8E:1B:D8:88 RSSI: -63
[CHG] Device 98:39:8E:1B:D8:88 RSSI: -74
[CHG] Device 98:39:8E:1B:D8:88 RSSI: -62

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

Step 4

Pair to your smartphone using the MAC address:

[bluetooth]# pair 98:39:8E:1B:D8:88
Attempting to pair with 98:39:8E:1B:D8:88
[CHG] Device 98:39:8E:1B:D8:88 Connected: yes
Request confirmation
[agent] Confirm passkey 117022 (yes/no):

Confirm that the passkey is the same as displayed on your smartphone. You also need to confirm the passkey on your smartphone.

[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: yes
Pairing successful
...
[CHG] Device 98:39:8E:1B:D8:88 Connected: no

Step 5

Connect to the Bluetooth device:

[bluetooth]# connect 98:39:8E:1B:D8:88
Attempting to connect to 98:39:8E:1B:D8:88
[CHG] Device 98:39:8E:1B:D8:88 Connected: yes
Connection successful
[CHG] Device 98:39:8E:1B:D8:88 ServicesResolved: yes
[Galaxy A5 (2016)]#

Step 6

List the connected device information, including supported services:

[Galaxy A5 (2016)]# info 98:39:8E:1B:D8:88
Device 98:39:8E:1B:D8:88
Name: Galaxy A5 (2016)
Alias: Galaxy A5 (2016)
Class: 0x5a020c
Icon: phone
Paired: yes
Trusted: yes
Blocked: no
Connected: yes
LegacyPairing: no
UUID: 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:v0075p0100d0200
ManufacturerData Key: 0x0075
ManufacturerData Value: 0x77
ManufacturerData Value: 0x98
ManufacturerData Value: 0x39
ManufacturerData Value: 0x8e
ManufacturerData Value: 0x1b
ManufacturerData Value: 0xd8
ManufacturerData Value: 0x88

FAQ

More information about Bluetooth