【树莓派】树莓派3与手机之间蓝牙链接配置记录

配置树莓派3是支持蓝牙链接的。php

这让在进行文件传输,或者音频等均可以使用,能够带来必定的便捷性。linux

具体怎么作呢?我实践了一下,发现是能够的,下面截取部分相关命令和截图等,供参考。ide

 

一.树莓派与手机之间蓝牙配对:ui

树莓派3直接支持蓝牙,使用直接使用自带命令便可,先打开要链接的蓝牙设备,而后配置树莓派:spa

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

看了这些命令,基本知道怎么操做了。3d

下面记录部分我实践的命令:代理

[bluetooth]# list
Controller B8:27:EB:F4:42:7E raspberrypi [default]

看下目前可搜索到的蓝牙设备:code

#查找设备
[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

链接配对:orm

[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中的发现倒计时和配对倒计时

试着在 /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

 

固然,这里只是一些初浅的基本使用,想深刻研究和应用的话,建议能够参考官方的一些介绍文档:https://wiki.archlinux.org/index.php/Bluetooth_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87) ,相对更为完善,更新也更及时。

相关文章
相关标签/搜索