Setting Up Bluetooth Serial Port Profile on Raspberry Pi using sdptool

This post shows steps to set up Bluetooth Serial Port Profile (or SPP)[1] on Raspberry Pi.

The goal is to establish SPP connection between Raspberry Pi 3 and Android phone, then send/receive text using serial terminal applications on both ends.

SPP is not available by default. There are two options to enable it in BlueZ (which is the default Bluetooth stack in Linux). This post shows steps for the 1st option (sdptool).

  1. sdptool
  2. D-bus API (please see this post for this option)

 

Prerequisites (parentheses indicate my environment)

 

Steps
1. Installation
1-1. Install a serial terminal application on Raspberry Pi. In this post, I’ll use minicom[2].

 

2. Enable SPP on Raspberry Pi
In order to use SPP, Bluetooth service needs to be restarted with ‘compatibility’ flag[3].

2-1. Open Bluetooth service configuration file.

2-2. Look for a line starts with “ExecStart” and add compatibility flag ‘-C’ at the end of the line.

2-3. Add a line below immediately after “ExecStart” line, then save and close the file.

2-4. Reload the configuration file.

2-5. Restart the service.

 

3. Pairing
To establish a connection, Raspberry Pi and the phone need to be paired.

3-1. Launch bluetoothctl.

3-2. Enter below in order to be discovered from the phone.

3-3. On the phone, scan for Raspberry Pi and pair. You should be able to see something like below.

3-4. Press Ctrl+D to quit.

 

4. Establishing Connection from Phone

4-1. Listen for incoming connection on Raspberry Pi.

4-2. Install and launch “Serial Bluetooth Terminal” app[4] on the phone.

4-3. In the app, go to “Device” menu and select Raspberry Pi. If everything goes well and the connection is established, you should be able to see like this:

 

5. Connecting Serial Terminal on Raspberry Pi
5-1. Open another terminal and launch the serial terminal.

 

6. Test
6-1. Input some text on the phone.

You should be able to see the text on Raspberry Pi’s serial terminal.

6-2. Input some text back to the phone on Raspberry Pi.

You should be able to see the text on the phone.

 

References
[1] Serial_Port_Profile_(SPP) – Wikipedia
[2] minicom(1) – Linux man page
[3] sdptool is broken in Bluez 5 – Arch Linux
[4] Serial Bluetooth Terminal – Google Play
[5] Bluetooth issues – Raspberry Pi Forum

 

 

Sponsor Link

Leave a Reply

Your email address will not be published. Required fields are marked *