当前位置:网站首页>树莓派连接蓝牙音箱
树莓派连接蓝牙音箱
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
边栏推荐
- 知乎高赞:拼多多和国家电网,选哪个?
- C# Sqlite database construction and use skills
- shell脚本详解-------循环语句wuile循环和until循环
- 】 【 LeetCode daily one problem - 540. The order of a single element of the array
- The second step through MySQL in four steps: MySQL index learning
- LeetCode 每日一题——1403. 非递增顺序的最小子序列
- 机器学习(十七):网格搜索(Grid Search)和SVM
- RecyclerView 缓存与复用机制
- 《机器学习的随机矩阵方法》
- Qt自动补全之QCompleter使用
猜你喜欢
随机推荐
抖音最重要的接口——item_search_video-根据关键词获取视频列表
Copycat CNN: Stealing Knowledge by Persuading Confession with Random Non-Labeled Data阅读心得
88. (the home of cesium) cesium polymerization figure
arm交叉编译
win11如何退出安全模式
【LeetCode每日一题】——540.有序数组中的单一元素
在VMD上可视化hdf5格式的分子轨迹文件
CF86D Powerful array
nyist 301 递推求值(矩阵快速幂)
pyhon爬虫之爬取图片(亲测可用)
重新审视分布式系统:永远不会有完美的一致性方案……
C# Sqlite database construction and use skills
LeetCode 每日一题——1403. 非递增顺序的最小子序列
学习探索-网站中引入百度统计
SRM Supplier Collaborative Management System Function Introduction
icu是哪个国家的域名?icu是什么域名?
使用Redis做某个时间段在线数统计
R语言计算时间序列数据的逐次差分(successive differences):使用diff函数计算时间序列数据的逐次差分值
餐饮供应链管理系统
机器学习(十):朴素贝叶斯