BT SPP Profile Example
Source code path: example/bt/spp
Supported Platforms
eh-lb52x
eh-lb56x
eh-lb58x
Overview
This example demonstrates SPP connection and disconnection, data transmission, file transfer, and speed testing, including:
SPP server
SPP client
SPP server and SPP client
Hardware Requirements
Before running this example, you need to prepare:
One development board supported by this example (Supported Platforms).
An Android phone (SPP only supports Android phones, iOS phones cannot use SPP), and you need to download an SPP Bluetooth serial port tool APP (e.g., SPP Bluetooth Serial Port, e-Debug, etc.).
Example Usage
The example will enable Bluetooth by default at startup, and the phone can enter the SPP Bluetooth serial port tool APP to search and connect (using e-Debug app as an example):
Phone app connects to development board SPP: Enter the classic Bluetooth device search interface on the phone to search for the development board:
After finding the specified device, you can long-press the device to modify the UUID of the SPP to connect (default is 0x1101 UUID). This example supports custom SPP UUIDs to increase the number of SPP connections, and supports up to 7 SPP connections with the same phone. Users can add custom UUIDs by implementing the bt_spp_srv_add_uuid_list interface. Also, if the phone wants to connect multiple SPP connections, it may need to establish one SPP connection in each app separately.
You can see the successful connection log in the serial port output:
Phone sends data to development board You can send data from the phone app to the development board, as shown below:
The development board’s serial port log will print the received data size and speed:
Development board sends data to phone Use the command
spp send_data + address + service channel
to send test data to the phone, where the service channel can be obtained from the serial port output:The phone app will display the received data:
Phone sends file to development board In the phone app, you can select to send a file to the development board:
The development board’s serial port log will print the received data size and speed, and the phone will also display the sending progress:
Development board sends file to phone If there are files on the development board, you can use the command
spp send_file + address + service channel + filename
to send the specified file to the phone, where the service channel can be obtained from the serial port output:The phone will display the received content and data size:
Development board initiates SPP connection The development board can also initiate SPP connections, but since many phones only support 0x1101 SPP, and the development board will be quickly disconnected by the phone after actively connecting, you can choose to connect development board to development board. Since this example supports custom SPP UUIDs to increase the number of SPP connections, you can flash this example to two development boards separately, allowing multiple SPP connections between development boards, with one acting as the phone role. For example, if development board A needs to connect to development board B’s 0x3001 SPP channel, you can use the command
spp search + address + uuid length + uuid
to first query whether the peer device supports 0x3001 SPP:Development board A can use the command
spp connect + address + uuid length + uuid
to connect to the peer device’s 0x3001 SPP:Throughput test between development boards The functions mentioned above also exist in connections between development boards. Here we mainly explain the throughput test between development boards. Development board A can use the command
spp through_put + address + service channel + transmitted data size
to transmit random data of specified size to development board B. Development board B will calculate the rate after receiving all data: The service channel can be obtained from the serial port output:Disconnect specified SPP connection The development board can use the command
spp disc + address + service channel
to disconnect the specified SPP connection: The service channel can be obtained from the serial port output:Disconnect all connected SPP The development board can use the command
spp disc_all
to disconnect all SPP connections.
Compilation and Flashing
Switch to the example project directory and run the scons command to compile:
> scons --board=eh-lb525 -j32
Switch to the example project/build_xx
directory and run uart_download.bat
, then select the port as prompted to download:
$ ./uart_download.bat
Uart Download
please input the serial port num:5
For detailed steps on compilation and downloading, please refer to the related introduction in Quick Start.
Expected Results
After the example starts:
SPP functionality works normally
Troubleshooting
Reference Documentation
Update History
Version |
Date |
Release Notes |
---|---|---|
0.0.1 |
03/2025 |
Initial version |