# 执行蓝牙 SPP 客户端功能

Source: [https://docs.qualcomm.com/doc/80-70017-13SC/topic/perform_bluetooth_functions_in_spp_client.html](https://docs.qualcomm.com/doc/80-70017-13SC/topic/perform_bluetooth_functions_in_spp_client.html)

您可以使用 `spp_client_menu` 选项执行 SPP 客户端功能。

## 关于此任务

在开始之前，设置设备并转到 SPP 客户端菜单，如[设置设备的蓝牙 SPP 功能](https://docs.qualcomm.com/doc/80-70017-13SC/topic/set_up_bluetooth_in_spp.html#set_up_bluetooth_in_spp__context_bgp_lts_s1c)所述。

**上一级主题：** [串行端口配置文件](https://docs.qualcomm.com/doc/80-70017-13SC/topic/set_up_bluetooth_in_spp.html)

## 配置 DUT 为 SPP 客户端角色

Source: [https://docs.qualcomm.com/doc/80-70017-13SC/topic/perform_bluetooth_functions_in_spp_client.html](https://docs.qualcomm.com/doc/80-70017-13SC/topic/perform_bluetooth_functions_in_spp_client.html)

### 关于此任务

要配置 DUT 为 SPP 客户端角色，执行以下操作：

### 过程

1. 在对端设备 SPP 应用程序中运行 SPP 服务器。
2. 通过运行以下命令从 DUT 启动 SPP 配置文件连接：
                    
connect <bt_addr>Copy to clipboard

**参数**

`<bt_addr>` 是远程设备的蓝牙地址。

[运行蓝牙查询扫描](https://docs.qualcomm.com/doc/80-70017-13SC/topic/gap_commands.html#gap_commands__section_iy1_xnf_41c)以获取
                            `<bt_addr>`。
3. 查看 DUT 上的输出以确定 SPP 连接是否成功。
                    
**示例输出**

以下示例输出显示已成功建立 SPP 连接：

spp_client_menu
        
        ***************** Menu *******************
                 connect <bt_addr>
                 disconnect
                 send_file<space><directory_with_file_name>eg: send_file /var/fileName.txt
                 recv_file<space><directory_with_file_name>eg: recv_file /var/fileName.txt
                 send_data<space><with_size>eg: send_data 1000[Note:1000 means 1MB]
                 recv_data
                 main_menu
         ******************************************
        connect 22:22:85:3d:2e:50
        Connecting Device ... Please wait ...!!!
         ACL state:0 change with reason 00 for device: 22:22:85:3d:2e:50
        Device is Connected
        -----------------------
        Device Address       : 22:22:85:3d:2e:50
        Connection Direction : Client
        Copy to clipboard

注释： 如果您在 `/var` 目录中遇到任何权限问题，请使用 `/etc/bluetooth` 目录发送或接收文件。

## 以客户端角色发送文件

Source: [https://docs.qualcomm.com/doc/80-70017-13SC/topic/perform_bluetooth_functions_in_spp_client.html](https://docs.qualcomm.com/doc/80-70017-13SC/topic/perform_bluetooth_functions_in_spp_client.html)

### 关于此任务

以客户端角色发送文件，执行以下操作：

### 过程

1. 在 SPP 应用程序中将对端设备设置为接收模式（如果可行的话）。
2. 创建一个包含数据的测试文件，并将该文件放在 DUT /etc/bluetooth 的目录中。
                    
例如，创建一个测试文件 bt\_stack.conf。
3. 通过运行以下命令将测试文件发送到对端设备：
                    
send_file <directory_with_file_name>Copy to clipboard

**参数**

`<directory_with_file_name>` 是完整的文件路径和文件名。

**示例**

要发送位于 /etc/bluetooth 的测试文件 bt\_stack.conf，请运行以下命令：

        send_file /etc/bluetooth/bt_stack.confCopy to clipboard

**示例输出**

send_file /etc/bluetooth/bt_stack.conf
        File Transfer Complete
        ---------------------
        Device Address : 22:22:85:3d:2e:50
        File Name      : /etc/bluetooth/bt_stack.confCopy to clipboard

注释： 如果出现问题，断开与设备的连接并恢复该过程。
4. 查看对端应用程序上的文件接收状态。

## 以客户端角色接收文件

Source: [https://docs.qualcomm.com/doc/80-70017-13SC/topic/perform_bluetooth_functions_in_spp_client.html](https://docs.qualcomm.com/doc/80-70017-13SC/topic/perform_bluetooth_functions_in_spp_client.html)

### 关于此任务

以客户端角色接收文件，执行以下操作：

### 过程

1. 将 DUT 设置为接收模式。
2. 通过运行以下命令从对端设备接收文件：
                    
recv_file <directory_with_file_name>Copy to clipboard

**参数**

`<directory_with_file_name>` 是完整的文件路径和文件名。

注释： 要接收文件，请仅使用 /etc/bluetooth 目录。

**示例**

要从远程设备的 fileName.txt 处接收 /etc/bluetooth，请运行以下命令：

        recv_file /etc/bluetooth/fileName.txtCopy to clipboard
3. 从对端设备 SPP 服务应用程序发送文件。
4. 验证收到的文件，如下所示：
    1. 打开命令提示符窗口。
    2. 运行以下命令，拉取收到的文件：
                            
scp -r root@<IP_address>:<source_file_path> <destination_file_path>Copy to clipboard

要将文件拉取到当前文件路径，请在命令中输入 `<destination_file_path>` 作为 `.`。 
注释： 当系统提示输入密码时，输入 `oelinux123` 以通过安全复制协议 (SCP) 对文件传输进行鉴权。

**示例**

设备的 IP 地址是 `10.92.160.222`。要从 /etc/bluetooth 中提取 fileName.txt，请运行以下命令：

            scp -r root@10.92.160.222:/etc/bluetooth/fileName.txt .Copy to clipboard
    3. 打开收到的文件并验证内容。
5. 通过运行以下命令断开 SPP 与 DUT 的连接：
                    
disconnectCopy to clipboard

Last Published: Jan 23, 2025

[Previous Topic
执行蓝牙 SPP 服务器功能](https://docs.qualcomm.com/bundle/publicresource/80-70017-13SC/topics/perform_bluetooth_functions_in_spp_server.md) [Next Topic
通用属性配置文件](https://docs.qualcomm.com/bundle/publicresource/80-70017-13SC/topics/set_up_ble_gatt.md)