BlueZ在ARM Linux下的使用


BlueZ版本 :2.25

arm linux版本 :2.6.17.8

bluez使用的重点就是配置问题,这里主要讲rfcomm的使用,就是蓝牙模拟串口的使用。

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

关键的修改是:

security auto; ---> security user;//auto极不稳定

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

其中/home/pin就是个简单的脚本:

如果要修改密码就修改PIN:后面的部分.

1.加载初始化文件:

2.设置SDP:

其中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口来进行正常串口通讯了.

相关内容