树莓派ubuntu:手机蓝牙连接树莓派开发板,取消配对验证操作,自动完成连接

蓝牙取消配对验证

我们使用 bt-agent tool来实现蓝牙自动配对连接

bt-agent tool:

bt-agent是一个用于对蓝牙设备进行管理和操作的工具。它提供了一组命令行工具,可以控制和配置蓝牙设备的各种功能和特性。bt-agent工具可以在Linux系统上使用,并且需要安装BlueZ蓝牙库。

1. 开启bt-agent

bash 复制代码
bt-agent --capability=NoInputNoOutput 

2. 查看bt-agent是否已开启

bash 复制代码
ps -aux | grep bt-agent

3. 创建脚本

bash 复制代码
sudo vim /usr/local/bin/btagent_auto.sh
复制代码
#!/bin/sh
bt-agent --capability=NoInputNoOutput

保存并退出

vim(esc :qw!)

4. 添加执行权限

复制代码
sudo chmod +x /usr/local/bin/btagent_auto.sh

5. 开机自启动

5.1 创建service文件

bash 复制代码
sudo vim /etc/systemd/system/btagent_auto.service

文件内容

bash 复制代码
[Unit]
Description=Bt Agent Auto Service
 
[Service]
ExecStart=/usr/local/bin/btagent_auto.sh
 
[Install]
WantedBy=multi-user.target

5.2 启动服务并设置开机自启

复制代码
sudo systemctl daemon-reload
sudo systemctl start btagent_auto.service
sudo systemctl enable btagent_auto.service

5.3 重启系统检查是否成功自动运行

bash 复制代码
sudo systemctl status btagent_auto.service

5.4 停止该服务并禁用开机自启

如果要取消自启动可按如下操作:

bash 复制代码
sudo systemctl stop btagent_auto.service
sudo systemctl disable btagent_auto.service

使用手机蓝牙连接树莓派开发板测试,现在应该可以不需要配对操作就可以连接成功了

6. 介绍其他两种方式替代bt-agent tool

6.1 bluetoothctl内置的agent

bash 复制代码
bluetoothctl
Agent registered
[bluetooth]# agent off
Agent unregistered
[bluetooth]# agent NoInputNoOutput
Agent registered
[bluetooth]# default-agent
Default agent request successful

6.2 Bluetoothctl options

bash 复制代码
bluetoothctl --agent=NoInputNoOutput
Agent registered
[bluetooth]# default-agent
Default agent request successful
相关推荐
剑锋所指,所向披靡!8 分钟前
Linux常用指令(2)
linux·运维·服务器
不愿透露姓名的大鹏27 分钟前
Oracle归档日志爆满急救指南
linux·数据库·oracle·dba
W.W.H.39 分钟前
嵌入式常见的面试题1
linux·网络·经验分享·网络协议·tcp/ip
木白CPP40 分钟前
DMA-Buffer内核驱动API文档
linux
筱谙1 小时前
BES 芯片跨核通讯与共享内存设计原理
嵌入式硬件·音频·蓝牙
HXQ_晴天1 小时前
Linux 系统的交互式进程监控工具htop
linux·服务器·网络
song8581 小时前
韦东山开发手册阅读笔记(五)
linux
LIZhang20161 小时前
linux写一个脚本实时保存内存占用情况
linux·运维·服务器
IDC02-阿杰2 小时前
Windows WSL2安装Ubuntu24.04全攻略
linux·windows
s09071362 小时前
ZYNQ7000 AXI DMA 接收中断(S2MM_introut)全解析:从硬件原理到Linux驱动开发
linux·驱动开发·dma·zynq