首页 » 网站建设 » php蓝牙配对技巧_arm 运用bluetoothctl连接蓝牙耳机

php蓝牙配对技巧_arm 运用bluetoothctl连接蓝牙耳机

访客 2024-11-28 0

扫一扫用手机浏览

文章目录 [+]

目标:arm板

利用IMX6的arm板,接了一个USB外接蓝牙,利用的是bluz 5.50版本协议栈,利用USB蓝牙连接蓝牙耳机,终极要能通过蓝牙耳机录音。

php蓝牙配对技巧_arm 运用bluetoothctl连接蓝牙耳机

安装 bluez,这个软件包供应蓝牙的协议栈

php蓝牙配对技巧_arm 运用bluetoothctl连接蓝牙耳机
(图片来自网络侵删)

安装 bluez-utils, 其供应 bluetoothctl 工具

插入USB蓝牙后之后,可以利用lsusb命令查看USB设备

运行hciconfig可以看到USB蓝牙

第一步,先确保pulseaudio已经启动

# 查看pulseaudio是否在运行pgrep -af pulseaudio# 或者ps -A |grep pulseaudio# 如果没运行以前要先启动pulseaudio,如果连接蓝牙耳机时,就会直接返回连接失落败# 参数解释:--start Start the daemon if it is not running# pulseaudio -h 可以查看帮助/usr/bin/pulseaudio --start# pulseaudio --kill

PulseAudio 5.x 开始默认支持 A2DP。
确保这些包已经安装Install: pulseaudio-alsa, pulseaudio-bluetooth, bluez, bluez-libs, bluez-utils, bluez-firmwareAUR. 如果没有安装 pulseaudio-bluetooth,蓝牙设备在配对完成后,连接会失落败,而且你不会得到任何有用的提示。

第二步,启动bluetoothd做事

# 我利用的arm板是通过如下命令启动bluetoothd/etc/init.d/bluetooth start

/etc/init.d/bluetooth文件内容如下:

#!/bin/shPATH=/sbin:/bin:/usr/sbin:/usr/binDESC=bluetoothDAEMON=/usr/libexec/bluetooth/bluetoothd# If you want to be ignore error of \"大众org.freedesktop.hostname1\"大众,# please enable NOPLUGIN_OPTION.# NOPLUGIN_OPTION=\公众--noplugin=hostname\公众NOPLUGIN_OPTION=\公众\公众SSD_OPTIONS=\"大众--oknodo --quiet --exec $DAEMON -- $NOPLUGIN_OPTION\公众test -f $DAEMON || exit 0# FIXME: any of the sourced files may fail if/with syntax errorstest -f /etc/default/bluetooth && . /etc/default/bluetoothtest -f /etc/default/rcS && . /etc/default/rcSset -ecase $1 in start)echo \公众Starting $DESC\"大众if test \"大众$BLUETOOTH_ENABLED\公众 = 0; thenecho \"大众disabled. see /etc/default/bluetooth\公众exit 0fistart-stop-daemon --start --background $SSD_OPTIONSecho \"大众${DAEMON##/}\公众 ;; stop)echo \公众Stopping $DESC\"大众if test \"大众$BLUETOOTH_ENABLED\公众 = 0; thenecho \"大众disabled.\"大众exit 0fistart-stop-daemon --stop $SSD_OPTIONSecho \"大众${DAEMON}\"大众 ;; restart|force-reload)$0 stopsleep 1$0 start ;; status) pidof ${DAEMON} >/dev/null status=$? if [ $status -eq 0 ]; then echo \公众bluetooth is running.\"大众 else echo \公众bluetooth is not running\公众 fi exit $status ;; )N=/etc/init.d/bluetoothecho \"大众Usage: $N {start|stop|restart|force-reload|status}\公众 >&2exit 1;;esacexit 0# vim:noet

第三步,使能USB蓝牙设备

hciconfig hci0 up

可以试一下扫描蓝牙设备

# 可以利用如下命令扫描当前可见的蓝牙,不过彷佛看到有人说这个命令有些过期,但是我以为挺好用的hcitool scan# 利用l2ping可以像ping命令一样检讨蓝牙是否能在线# 蓝牙地址比如:E3:28:E9:24:21:07l2ping 蓝牙地址# sdptool browse查看蓝牙可用做事sdptool browse E3:28:E9:24:21:07

第四步,利用bluetoothctl连接蓝牙耳机

# 进入bluetoothctl命令行bluetoothctl# 进入bluetoothctl命令行后,类似:[bluetooth]## Controller代表arm板上的蓝牙设备,Device代表蓝牙耳机# 按如下步骤初始化蓝牙设备,并连接蓝牙耳机# 查看帮组help# power onagent ondefault-agent # 启动扫描scan on # 如果蓝牙耳机地址为:E3:28:E9:24:21:07trust E3:28:E9:24:21:07# 配对pair E3:28:E9:24:21:07# 连接connect E3:28:E9:24:21:07# 查看蓝牙耳机信息info E3:28:E9:24:21:07# 断开连接disconnect E3:28:E9:24:21:07# 不想自动连接上蓝牙耳机,可以删除配对信息remove E3:28:E9:24:21:07

不出什么问题,则已经连接上蓝牙耳机了。

如果创造连接上了但是蓝牙耳机的音频用不了要做如下检讨。

# 查看当前音频卡,是否有蓝牙的耳机,蓝牙耳机对应设备一样平常以蓝牙地址作为名称的一部分,# 比如:name: <bluez_card.E3_28_E9_24_21_07>pacmd list-cards# 查看音频输入源,是否有蓝牙的耳机pacmd list-sources# 比如:name: <bluez_source.E3_28_E9_24_21_07># 如果创造有name: <bluez_sink.E3_28_E9_24_21_07.monitor># 但是没有bluez_source.E3_28_E9_24_21_07# 解释蓝牙配置不对# bluez_sink.E3_28_E9_24_21_07.monitor是不能用于录音的

蓝牙耳机设置设置如下类型:

a2dp_sink -- High Fidelity Playback (A2DP Sink) (sinks: 1, sources: 0, priority: 10, available: yes)headset_head_unit -- Headset Head Unit (HSP/HFP) (sinks: 1, sources: 1, priority: 20, available: yes)off -- Off (sinks: 0, sources: 0, priority: 0, available: yes)

这里可选择\"大众a2dp_sink\"大众或\"大众headset_head_unit\"大众两种配置,个中\"大众headset_head_unit\"大众可以支持音频输入/输出,\"大众a2dp_sink\"大众只支持输出。

以是设置为headset_head_unit才能有蓝牙输入

# 修正配置为:headset_head_unitpacmd set-card-profile bluez_card.E3_28_E9_24_21_07 headset_head_unit

# 查看可用于播放的音频设备pacmd list-sinks# 查看帮助pacmd help# 查看状态,包括默认输入输入音频,默认采样等pacmd stat# 设置默认音频输出设备pacmd set-default-sink bluez_sink.E3_28_E9_24_21_07# 设置默认音频输入设备,默认麦克风pacmd set-default-source bluez_source.E3_28_E9_24_21_07

参考:

https://wiki.archlinux.org/index.php/Bluetooth_headset_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)

https://www.cnblogs.com/zjutlitao/p/9576589.html

https://wiki.archlinux.org/index.php?title=PulseAudio_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&oldid=349911

http://blog.lujun9972.win/blog/2017/07/18/%E5%9C%A8archlinux%E4%B8%AD%E4%BD%BF%E7%94%A8%E8%93%9D%E7%89%99%E8%80%B3%E6%9C%BA/

https://blog.csdn.net/chenjk10/article/details/89283578

标签:

相关文章

PHP实现文字转图片的代码与应用

图片处理技术在各个领域得到了广泛应用。在PHP编程中,文字转图片功能同样具有很高的实用价值。本文将针对PHP实现文字转图片的代码进...

网站建设 2025-03-02 阅读1 评论0

NAN0017探索新型纳米材料的奥秘与应用

纳米技术作为一门新兴的交叉学科,近年来在材料科学、生物医学、电子工程等领域取得了举世瞩目的成果。其中,NAN0017作为一种新型纳...

网站建设 2025-03-02 阅读3 评论0

L26368XO代码其背后的创新与突破

编程语言在各个领域发挥着越来越重要的作用。在众多编程语言中,L26368XO代码以其独特的优势,成为了业界关注的焦点。本文将深入剖...

网站建设 2025-03-02 阅读1 评论0

HTML字体背景打造个化网页设计的关键元素

网页设计已经成为现代网络传播的重要手段。在众多网页设计元素中,字体和背景的搭配尤为关键。本文将从HTML字体背景设置的角度,探讨其...

网站建设 2025-03-02 阅读1 评论0