树莓派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
相关推荐
薛定谔的悦几秒前
嵌入式设备OTA升级实战:从MQTT命令到自动重启的全流程解析
linux·算法·ota·ems
2501_9181269143 分钟前
学习所有6502写游戏控制器的语句
java·linux·网络·汇编·嵌入式硬件
JuckenBoy44 分钟前
Linux环境安装SGLang框架运行自选大模型(以Rocky9.7为例)
linux·运维·大模型·qwen·rocky·deepseek·sglang
十巷无终1 小时前
Kali Virtual Machines(虚拟机镜像)安装后问题及解决办法
linux·运维·服务器
赵民勇1 小时前
gtkmm库之GtkWindow与ApplicationWindow用法详解
linux·c++
BestOrNothing_20151 小时前
(4)Ubuntu 22.04 安装后使用 GParted 重新分区实战记录
linux·gparted·ubuntu22.04·ubuntu磁盘分区
架构指南1 小时前
Centos上安装Claude Code报GLIBC_2.27 not found
linux·运维·centos
Predestination王瀞潞1 小时前
4.3.1 存储->微软文件系统标准(微软,自有技术标准):exFAT(Extended File Allocation Table)扩展文件分配表系统
linux·运维·microsoft·exfat·ex4
你有按下913的勇气吗1 小时前
【Agent,RAG,Transform】
linux·运维·服务器
ken22321 小时前
linux OS : apt update 使用代理与环境变量
linux