BlueZ版本 :2.25arm linux版本 :2.6.17.8bluez使用的重点就是配置问题,这里主要讲rfcomm的使用,就是蓝牙模拟串口的使用。
- #
- # HCI daemon configuration file.
- #
-
- # HCId options
- options {
- # Automatically initialize new devices
- autoinit yes;
-
- # Security Manager mode
- # none - Security manager disabled
- # auto - Use local PIN for incoming connections
- # user - Always ask user for a PIN
- #
- security user;
-
- # Pairing mode
- # none - Pairing disabled
- # multi - Allow pairing with already paired devices
- # once - Pair once and deny successive attempts
- pairing multi;
-
- # PIN helper
- pin_helper /home/pin;
-
- # D-Bus PIN helper
- #dbus_pin_helper;
- }
-
- # Default settings for HCI devices
- device {
- # Local device name
- # %d - device id
- # %h - host name
- name "Bluez (%d)";
-
- # Local device class
- class 0x3e0100;
-
- # Default packet type
- #pkt_type DH1,DM1,HV1;
-
- # Inquiry and Page scan
- iscan enable; pscan enable;
-
- # Default link mode
- # none - no specific policy
- # accept - always accept incoming connections
- # master - become master on incoming connections,
- # deny role switch on outgoing connections
- lm accept;
-
- # Default link policy
- # none - no specific policy
- # rswitch - allow role switch
- # hold - allow hold mode
- # sniff - allow sniff mode
- # park - allow park mode
- lp rswitch,hold,sniff,park;
-
- # Authentication and Encryption (Security Mode 3)
- #auth enable;
- #encrypt enable;
- }
关键的修改是: security auto; ---> security user;//auto极不稳定pin_helper /usr/sbin/pin; --->pin_helper /home/pin;//只是便于自己修改其中/home/pin就是个简单的脚本:#!/bin/shecho "PIN:0000"如果要修改密码就修改PIN:后面的部分. 1.加载初始化文件:hcid -f /etc/bluetooth/hcid.conf2.设置SDP: sdpdsdptool 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:XXXX: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口来进行正常串口通讯了.