Ads 468x60px

##EasyReadMore##

14 12月, 2017

BlueTooth 藍牙指令介紹

rfkill(用於開啟或關閉藍牙)、hcitools(用於配置藍牙)。
當一個藍牙模塊連接到USB並rfkill啟用Bluetooth時,hciattach會自動啟動並接管藍牙,同時其他命令也會自動開始運行。

關於bluetoothd。它是一個在系統啟動時就運行加載的daemon,他會初始化相關的plugins, 並在內核中監聽硬件事件,當一個HCI設備發出MGMT_EV_INDEX_ADDED響應時,這個daemon會開始初始化藍牙的相關程序和控制。

# 開啟或關閉藍牙的命令是:
$ rfkill unblock bluetooth
$ rfkill block bluetooth
# 可以同時起到systemctl start connman和connmanctl enable bluetooth的作用

# 當藍牙使能時,可以通過rfkill列出可以使用的接口,命令是:
$ rfkill block bluetooth
$ rfkill list
# 以及
$ rfkill unblock bluetooth
$ rfkill list

# 該profile用於提供有關於藍牙設備的額外信息,可以通過在bluetoothctl程序下輸入:
[bluetooth]# show
Controller 80:A5:89:35:82:F4
        Name: intel-quark
        Alias: intel-quark
        Class: 0x000104
        Powered: yes
        Discoverable: no
        Pairable: yes
        UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
        UUID: A/V Remote Control        (0000110e-0000-1000-8000-00805f9b34fb)
        UUID: PnP Information           (00001200-0000-1000-8000-00805f9b34fb)
        UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
        UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
        Modalias: usb:v1D6Bp0246d0529
        Discovering: no

# list devices and status
$ hciconfig dev
Devices:
        hci0    80:A5:89:35:82:F4

# find bluetooth.service
$systemctl status bluetooth -l | grep Loaded

# 配對流程
# 通過bluetoothctl軟件搜索scan on時,提示:
$ bluetoothctl
[bluetooth]# scan on
# Failed to start discovery: org.bluez.Error.NotReady/ 參考 (註1)

# 會開始搜索設備,直到搜索到想匹配的設備時
[bluetooth]# pair [MAC地址]
[bluetooth]# scan off
[bluetooth]# connect [MAC地址]
[bluetooth]# info [MAC地址]
[bluetooth]# quit

# 註1) Failed to start discovery: org.bluez.Error.NotReady
 # 這個問題是人機接口層沒有成功開啟,輸入:
 $ hciconfig
 
 # 查看是否打開,是DOWN還是UP RUNNING PSCAN,如果是DOWN,輸入:
 $ hciconfig hci0 up
 # 出現 Can't init device hci0: Operation not possible due to RF-kill (132) 藍牙不能啟動錯誤 參考 ( 註2)
# 然後再次查看,發現已經變成了UP RUNNING PSCAN,這次再搜索就正常了。

# 註2) Can't init device hci0: Operation not possible due to RF-kill (132):
 # You can check of what is blocked by this command:
  $ rfkill list
  0: hci0: bluetooth
          Soft blocked: yes
          Hard blocked: no
  1: phy0: wlan
          Soft blocked: no
          Hard blocked: no
  
  # My bluetooth was Soft blocked. I used this command:
  $ rfkill unblock bluetooth
  # or
  $ rfkill unblock all
  
  # Check agin ,you will see no blocked.
  $ rfkill list
  0: hci0: bluetooth
          Soft blocked: no
          Hard blocked: no
  1: phy0: wlan
          Soft blocked: no
          Hard blocked: no
  # 有兩個介面是因為做在同一個 module 上

# test flow:
 $ rfkill unblock bluetooth
 $ hciconfig hci0
 $ hciconfig dev | grep Address |cut -d " " -f 3
 80:A5:89:35:82:F4

Refer:
  Edison 藍牙模塊 學習筆記 - 作業部落 Cmd Markdown 編輯閱讀器 - https://goo.gl/DJuAuy
 
  在Edison調試藍牙時的遇到的問題 - 作業部落 Cmd Markdown 編輯閱讀器 - https://goo.gl/9i8Ak6
 
  Bluetooth: Can't init device hci0: Operation not possible due to RF-kill (132) · Issue #171 ·  ev3dev/ev3dev - https://goo.gl/ot65hz
 
  Can't init device hci0: Operation not possible due to RF-kill (132) 藍牙不能啟動錯誤 - CSDN博客 - https://goo.gl/1pm5us

0 意見:

張貼留言

 
Blogger Templates