imx6 usb bluetooth的连接与文件传输

开发平台: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:~# 

连接成功。

相关内容推荐