歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> BlueZ在ARM Linux下的使用

BlueZ在ARM Linux下的使用

日期:2017/3/1 10:11:41   编辑:Linux編程

BlueZ版本 :2.25

arm linux版本 :2.6.17.8

bluez使用的重點就是配置問題,這裡主要講rfcomm的使用,就是藍牙模擬串口的使用。

  1. #
  2. # HCI daemon configuration file.
  3. #
  4. # HCId options
  5. options {
  6. # Automatically initialize new devices
  7. autoinit yes;
  8. # Security Manager mode
  9. # none - Security manager disabled
  10. # auto - Use local PIN for incoming connections
  11. # user - Always ask user for a PIN
  12. #
  13. security user;
  14. # Pairing mode
  15. # none - Pairing disabled
  16. # multi - Allow pairing with already paired devices
  17. # once - Pair once and deny successive attempts
  18. pairing multi;
  19. # PIN helper
  20. pin_helper /home/pin;
  21. # D-Bus PIN helper
  22. #dbus_pin_helper;
  23. }
  24. # Default settings for HCI devices
  25. device {
  26. # Local device name
  27. # %d - device id
  28. # %h - host name
  29. name "Bluez (%d)";
  30. # Local device class
  31. class 0x3e0100;
  32. # Default packet type
  33. #pkt_type DH1,DM1,HV1;
  34. # Inquiry and Page scan
  35. iscan enable; pscan enable;
  36. # Default link mode
  37. # none - no specific policy
  38. # accept - always accept incoming connections
  39. # master - become master on incoming connections,
  40. # deny role switch on outgoing connections
  41. lm accept;
  42. # Default link policy
  43. # none - no specific policy
  44. # rswitch - allow role switch
  45. # hold - allow hold mode
  46. # sniff - allow sniff mode
  47. # park - allow park mode
  48. lp rswitch,hold,sniff,park;
  49. # Authentication and Encryption (Security Mode 3)
  50. #auth enable;
  51. #encrypt enable;
  52. }

關鍵的修改是:

security auto; ---> security user;//auto極不穩定

pin_helper /usr/sbin/pin; --->pin_helper /home/pin;//只是便於自己修改

其中/home/pin就是個簡單的腳本:

#!/bin/sh
echo "PIN:0000"

如果要修改密碼就修改PIN:後面的部分.

1.加載初始化文件:

hcid -f /etc/bluetooth/hcid.conf

2.設置SDP:

sdpd
sdptool add SP

其中sdptool add SP默認使用的是channel 1,如果設置其他具體的channel就應該是 sdptool add --channel=x SP,x就是未使用的channel號.

是否添加成功是可以 sdptool browse local來查詢.

3.設置rfcomm後台監聽:

rfcomm listen /dev/rfcomm0 1&

如果你之前有設置channel就將這裡的1換成你的channel號.

以上是針對自己做slave的情況,如果做host,就需要先獲取對方的服務以及channel,初始化依然是上面的第一第二步,第二步也可以不要,第三部換成

sdptool browse XX:XX:XX:XX:XX

XX:XX:XX:XX:XX 是slave的Mac地址,然後可以浏覽到具體的sever和channel,找到自己需要連接的channel號x,然後連接之:

rfcomm connect 0 XX:XX:XX:XX:XX 1&

其中的1是channel,可以換成其他任意存在的channel號,其中前面的0是指rfcomm0,也可以將其換成/dev/rfcomm0.

以上兩種情況任何一種連接ok,就可以操作rfcomm0口來進行正常串口通訊了.

Copyright © Linux教程網 All Rights Reserved