BlueZ在arm linux下的使用

BlueZ版本 :2.25

arm linux版本 :2.6.17.8

bluez使用的重点就是配置问题,这里主要讲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/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口来进行正常串口通讯了.


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值