当前位置:网站首页>树莓派连接蓝牙音箱
树莓派连接蓝牙音箱
2022-08-04 17:18:00 【ttyt1217】
安装依赖包
sudo apt-get update
sudo apt-get install pulseaudio pulseaudio-module-bluetooth
sudo apt-get install pi-bluetooth bluez bluez-firmware blueman
sudo apt install bluez bluez-firmware pulseaudio pulseaudio-module-bluetooth
sudo /etc/init.d/bluetooth restart
设置蓝牙配对连接音箱
bluetoothctl
show
power on
default-agent
scan on
pair 41:42:90:F3:9E:B5
trust 41:42:90:F3:9E:B5
connect 41:42:90:F3:9E:B5
info 41:42:90:F3:9E:B5
exit
树莓派每次开机后都要执行此脚本来连接蓝牙音箱/home/pi/myboot/startboot.sh
#!/bin/bash
sleep 1
pulseaudio --k
pulseaudio --start
bluetoothctl power on
bluetoothctl connect 41:42:90:F3:9E:B5
sleep 5
aplay /home/pi/myboot/startaudio.wav
echo 'audio OK~~~'
*下面这个蓝牙开机自连脚本其实是有问题的,开机自启后看似蓝牙音箱是已连接状态了,但是播放音乐还是无声,还需要在当前SSH连接终端手动执行一次上面startboot.sh脚本才行。
开机启动用/etc/init.d/startboot
#!/bin/sh
#/etc/init.d/startboot
### BEGIN INIT INFO
# Provides:startboot
# Required-Start:$remote_fs $syslog
# Required-Stop:$remote_fs $syslog
# Default-Start:2 3 4 5
# Default-Stop:0 1 6
# Short-Description: startboot
# Description: This service is used to start my applaction
### END INIT INFO
case "$1" in
start)
echo "start your app here."
su pi -c "sh /home/pi/myboot/startboot.sh"
;;
stop)
echo "stop your app here."
;;
*)
echo "Usage: service startboot start|stop"
exit 1
;;
esac
exit 0
启动服务service startboot start
播放音频测试:
ffplay -nodisp -autoexit /home/pi/myboot/startaudio.wav
aplay /home/pi/myboot/startaudio.wav
边栏推荐
猜你喜欢

shell函数内如何调用另一个函数

【商家联盟】云平台—异业联盟,打造线上线下商业相结合的系统

shell脚本详解 --------循环语句之for循环

How to convert an int attribute into a string in the json format returned by the Go language gin framework?

集群监控——Zabbix使用

全球电子产品需求萎靡:三星越南工厂大幅压缩产能,减少工人工作日

基于clipboard.js对复制组件的封装

php如何查询字符串以什么开头

88. (the home of cesium) cesium polymerization figure

荣耀互联对外开放,赋能智能硬件合作伙伴,促进全场景生态产品融合
随机推荐
shell函数内如何调用另一个函数
R语言ggplot2可视化:使用patchwork包的plot_layout函数将多个可视化图像组合起来,nrow参数指定行的个数、byrow参数指定按照列顺序排布图
移动平台助力推进智慧型科研院所信息化建设
(一)、线性表的顺序存储结构链式存储结构
R语言时间序列数据算术运算:使用diff函数计算时间序列数据的逐次差分、使用时间序列之间的除法计算相对变化率(乘以100获得百分比)
要有遥不可及的梦想,也要有脚踏实地的本事
软件基础的理论
《机器学习理论到应用》电子书免费下载
乐享购(分享购)的模式:优势、亮点、收益
太一集团宣布全资收购火币旗下社交产品火信
机器学习(十三):支持向量机(SVM)
dotnet core 隐藏控制台
动态数组底层是如何实现的
域名哪家便宜?怎么买便宜域名?
正则过滤字符串中 script 标签
SRM Supplier Collaborative Management System Function Introduction
php如何查询字符串以什么开头
使用Redis做某个时间段在线数统计
WEB 渗透之SSTI 模板注入
Learning and Exploration-Introducing Baidu Statistics to the Website