配置樹莓派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 命令創建鏈接。
三.其餘常見問題:
若是不能從你的移動電話上找到你的電腦,打開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
這是目前惟一的可以使電腦對電話可見的方法。
若是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) ,相對更爲完善,更新也更及時。