BlueZ在arm linux下的使用

來源:互聯網
上載者:User

BlueZ版本 :2.25

arm linux版本 :2.6.17.8

bluez使用的重點就是配置問題,這裡主要講rfcomm的使用,就是藍芽類比串口的使用.

## HCI daemon configuration file.## HCId optionsoptions {        # 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 devicesdevice {        # 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.conf

2.設定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: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口來進行正常串口通訊了.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.