開發平臺:imx6dl
開發環境:yocto poky1.7(linux kernel 3.14.28)
參考文檔:fsl-6dl-source/sources/meta-fsl-bsp-release/imx/meta-fsl-bluez/readme-bluez.txt(源碼提供的文檔說明)+網上資料博客
內核配置:
<*>Networking support ---->
<*>Bluetooth subsystem support ---->
下所有子選項全部選上。(可能會有多餘,以後再深入瞭解)
imx6 yocto編譯完成後自帶bluez5,所以不需要移植工作。
1.檢查USB藍牙適配器是否正常工作
root@imx6dlsabresd:~# lsusb
Bus 001 Device 003: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)
可以看到usb設備,說明驅動工作正常,這一步應該都沒什麼問題,因爲內核自帶bluez藍牙協議以及usb藍牙驅動,內核配置完成後應該都可以正常工作。
2.開啓藍牙
hciconfig命令:可以查看藍牙設備信息,具體使用到的命令有
root@imx6dlsabresd:~#hciconfig
hci0: Type: BR/EDR Bus: USB
BD Address: 00:1B:10:00:0E:BE ACL MTU: 1017:8 SCO MTU: 64:0
DOWN
RX bytes:494 acl:0 sco:0 events:20 errors:0
TX bytes:75 acl:0 sco:0 commands:20 errors:0
root@imx6dlsabresd:~#
可以看到藍牙設備hci0,DOWN說明爲關閉狀態。
可以使用:
root@imx6dlsabresd:~# hciconfig hci0 up
root@imx6dlsabresd:~# hciconfig
hci0: Type: BR/EDR Bus: USB
BD Address: 00:1B:10:00:0E:BE ACL MTU: 1017:8 SCO MTU: 64:0
UP RUNNING
RX bytes:974 acl:0 sco:0 events:39 errors:0
TX bytes:147 acl:0 sco:0 commands:39 errors:0
root@imx6dlsabresd:~#
開啓藍牙。
hciconfig的其他操作還有:
hciconfig hci0 iscan 設置藍牙設備可以被掃描到。
hciconfig hci0 pscan
可以使用hciconfig –help查看幫助。
3.連接設備
啓動藍牙後臺進程
root@imx6dlsabresd:~# /usr/lib/bluez5/bluetooth/bluetoothd &
root@imx6dlsabresd:~# bluetoothctl
[NEW] Controller 00:1B:10:00:0E:BE BlueZ 5.25 [default]
[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]# scan on
Discovery started
[CHG] Controller 00:1B:10:00:0E:BE Discovering: yes
[NEW] Device 00:1B:10:00:07:9F mei-PC
[CHG] Device 00:1B:10:00:07:9F RSSI: -64
[CHG] Device 00:1B:10:00:07:9F RSSI: -53
[bluetooth]# scan off
[CHG] Device 00:1B:10:00:07:9F RSSI is nil
[CHG] Controller 00:1B:10:00:0E:BE Discovering: no
Discovery stopped
[bluetooth]# agent on
Agent registered
[bluetooth]# default-agent
Default agent request successful
[bluetooth]# pair 00:1B:10:00:07:9F
Attempting to pair with 00:1B:10:00:07:9F
[CHG] Device 00:1B:10:00:07:9F Connected: yes
Request PIN code
[agent] Enter PIN code: 0000
[CHG] Device 00:1B:10:00:07:9F UUIDs:
00001101-0000-1000-8000-00805f9b34fb
00001105-0000-1000-8000-00805f9b34fb
00001106-0000-1000-8000-00805f9b34fb
00001108-0000-1000-8000-00805f9b34fb
0000110a-0000-1000-8000-00805f9b34fb
0000110b-0000-1000-8000-00805f9b34fb
0000110c-0000-1000-8000-00805f9b34fb
00001112-0000-1000-8000-00805f9b34fb
00001117-0000-1000-8000-00805f9b34fb
0000111b-0000-1000-8000-00805f9b34fb
0000111e-0000-1000-8000-00805f9b34fb
0000111f-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1B:10:00:07:9F Paired: yes
Pairing successful
[CHG] Device 00:1B:10:00:07:9F Connected: no
[bluetooth]# connect 00:1B:10:00:07:9F
Attempting to connect to 00:1B:10:00:07:9F
[CHG] Device 00:1B:10:00:07:9F Connected: yes
Connection successful
[bluetooth]# quit
Agent unregistered
[DEL] Controller 00:1B:10:00:0E:BE BlueZ 5.25 [default]
root@imx6dlsabresd:~#
連接成功。