配置树莓派3是支持蓝牙连接的。
这让在进行文件传输,或者音频等都可以使用,可以带来一定的便捷性。
具体怎么做呢?我实践了一下,发现是可以的,下面截取部分相关命令和截图等,供参考。
一.树莓派与手机之间蓝牙配对:
树莓派3直接支持蓝牙,使用直接使用自带命令即可,先打开要连接的蓝牙设备,然后配置树莓派:
lifeccp@raspberrypi:~ $ sudo bluetoothctl [sudo] password for lifeccp: [NEW] Controller B8:27:EB:F4:42:7E raspberrypi [default] [bluetooth]# list Controller B8:27:EB:F4:42:7E raspberrypi [default] [bluetooth]# power on Changing power on succeeded [bluetooth]# scan on Discovery started [CHG] Controller B8:27:EB:F4:42:7E Discovering: yes [NEW] Device 77:D9:21:04:ED:AD 77-D9-21-04-ED-AD [bluetooth]# agent on Agent registered [NEW] Device 7C:E9:D3:BE:49:15 DOUHAO-PC
看了上面这些命令,第一次配置的同学可能不知道怎么回事。没关系,下面有帮助信息,官方提供了很多的help信息可以参考:
[bluetooth]# help Available commands: list List available controllers show [ctrl] Controller information select <ctrl> Select default controller devices List available devices paired-devices List paired devices power <on/off> Set controller power pairable <on/off> Set controller pairable mode discoverable <on/off> Set controller discoverable mode agent <on/off/capability> Enable/disable agent with given capability default-agent Set agent as the default one scan <on/off> Scan for devices info <dev> Device information pair <dev> Pair with device trust <dev> Trust device untrust <dev> Untrust device block <dev> Block device unblock <dev> Unblock device remove <dev> Remove device connect <dev> Connect device disconnect <dev> Disconnect device version Display version quit Quit program
看了这些命令,基本知道怎么操作了。
下面记录部分我实践的命令:
[bluetooth]# list Controller B8:27:EB:F4:42:7E raspberrypi [default]
看下目前可搜索到的蓝牙设备:
#查找设备
[bluetooth]# devices Device 77:D9:21:04:ED:AD 77-D9-21-04-ED-AD Device 7C:E9:D3:BE:49:15 DOUHAO-PC Device 55:34:0C:4E:DC:04 55-34-0C-4E-DC-04
连接配对:
[bluetooth]# pair FC:64:BA:C2:7B:57 Attempting to pair with FC:64:BA:C2:7B:57 [CHG] Device FC:64:BA:C2:7B:57 Connected: yes Request confirmation [agent] Confirm passkey 744237 (yes/no): yes [DEL] Device 77:D9:21:04:ED:AD 77-D9-21-04-ED-AD
添加信任:
[bluetooth]# trust FC:64:BA:C2:7B:57 [CHG] Device FC:64:BA:C2:7B:57 Trusted: yes Changing FC:64:BA:C2:7B:57 trust succeeded
连接设备:
[bluetooth]# connect FC:64:BA:C2:7B:57 Attempting to connect to FC:64:BA:C2:7B:57 [CHG] Device FC:64:BA:C2:7B:57 Connected: yes [CHG] Device FC:64:BA:C2:7B:57 Modalias: bluetooth:v0046p0802d0903 [CHG] Device FC:64:BA:C2:7B:57 UUIDs: 00001105-0000-1000-8000-00805f9b34fb 0000110a-0000-1000-8000-00805f9b34fb 0000110c-0000-1000-8000-00805f9b34fb 0000110f-0000-1000-8000-00805f9b34fb 00001112-0000-1000-8000-00805f9b34fb 00001115-0000-1000-8000-00805f9b34fb 00001116-0000-1000-8000-00805f9b34fb 0000111f-0000-1000-8000-00805f9b34fb 0000112f-0000-1000-8000-00805f9b34fb 00001132-0000-1000-8000-00805f9b34fb 00001200-0000-1000-8000-00805f9b34fb 00001800-0000-1000-8000-00805f9b34fb
下面是2张截图:
(1)在手机上看到这个提示,选择“配对”;
(2)配对成功之后,在已配对列表中,可见相关的树莓派设备;
停止使用:
当使用结束之后,想关掉蓝牙,可以这么操作:
[bluetooth]# scan off
[CHG] Device 7F:BB:20:BB:0F:CE RSSI is nil
[CHG] Device 7C:E9:D3:BE:49:15 RSSI is nil
[CHG] Device D0:03:4B:35:6E:C1 RSSI is nil
[CHG] Device 55:34:0C:4E:DC:04 RSSI is nil
[CHG] Device D4:A7:4E:10:54:5A RSSI is nil
[CHG] Device FC:64:BA:C2:7B:57 RSSI is nil
Discovery stopped
[CHG] Controller B8:27:EB:F4:42:7E Discovering: no
[bluetooth]# power off
Changing power off succeeded
[CHG] Controller B8:27:EB:F4:42:7E Powered: no
[CHG] Controller B8:27:EB:F4:42:7E Discovering: no
[bluetooth]# discoverable off
Failed to set discoverable off: org.bluez.Error.Failed
[bluetooth]# agent off
Agent unregistered
[DEL] Device D4:A7:4E:10:54:5A MI Band 2
[DEL] Device 55:34:0C:4E:DC:04 55-34-0C-4E-DC-04
[DEL] Device D0:03:4B:35:6E:C1 D0-03-4B-35-6E-C1
[DEL] Device 7C:E9:D3:BE:49:15 DOUHAO-PC
[DEL] Device 7F:BB:20:BB:0F:CE 7F-BB-20-BB-0F-CE
如果想连接音箱设备的话,需要安装一下相关组件:
sudo apt-get install pulseaudio pulseaudio-module-bluetooth
二.其他说明:
Bluetoothctl
通过命令行配对是最可靠的选择。准确的配对过程依不同设备类型及其所提供的输入功能而各不相同。下面提供使用/usr/bin/bluetoothctl配对的一般过程:
启动 bluetoothctl 交互命令。可以输入 help 列出所有有效的命令。
输入power on 命令打开控制器电源。默认是关闭的。
输入devices 命令获取要配对设备的 MAC 地址。
如果设备未在清单中列出,输入 scan on 命令设置设备发现模式。
输入agent on 命令打开代理。
输入 pair MAC Address 开始配对(支持 tab 键补全)。
如果使用无 PIN 码设备,再次连接可能需要手工认证。输入 trust MAC Address 命令。
最后,用 connect MAC_address 命令建立连接。
三.其他常见问题:
FAQ1:我的电脑不可见
如果不能从你的移动电话上找到你的电脑,打开PSCAN和ISCAN:
# 打开 PSCAN 和 ISCAN $ hciconfig hci0 piscan # 确认操作有效 $ hciconfig hci0: Type: USB BD Address: 00:12:34:56:78:9A ACL MTU: 192:8 SCO MTU: 64:8 UP RUNNING PSCAN ISCAN RX bytes:20425 acl:115 sco:0 events:526 errors:0 TX bytes:5543 acl:84 sco:0 commands:340 errors:0
试着在 /etc/bluetooth/main.conf 改变设备的class
# Default device class. Only the major and minor device class bits are # considered. #Class = 0x000100 (from default config) Class = 0x100100
这是目前唯一的能够使电脑对电话可见的方法。
FAQ2:Nautilus无法浏览文件
如果Nautilus无法打开并且显示如下错误:
Nautilus cannot handle obex: locations. Couldn't display "obex://[XX:XX:XX:XX:XX:XX]/".
安装gvfs-obexftp软件包:
# pacman -S gvfs-obexftp
本文转自 念槐聚 博客园博客,原文链接:http://www.cnblogs.com/haochuang/p/7115691.html,如需转载请自行联系原作者