centos7使用蓝牙_linux下使用蓝牙设备【转】

本文档详细介绍了如何在 CentOS 7 中配置和使用蓝牙设备,包括加载蓝牙内核模块、初始化配置、扫描设备、建立连接以及使用rfcomm进行串口通信。通过一系列hcitool和hciconfig命令,以及配置rfcomm.conf文件,实现与蓝牙设备的交互。
摘要由CSDN通过智能技术生成

# hcitool cc 00:08:AC:03:58:A6

|------------|

|   minicom -|

|------------|

|   RFCOMM   | /dev/rfcomm0

|------------|

|   L2CAP    |

|------------|

| --HCI_UART |

|------------|

|    COM     | /dev/ttyS0    OR

|------------|       /dev/ttyUSB0 (USB to RS232)

| BT Device –|

|------------|

# hcitool cmd 0x03 0x001A 0x00

< HCI Command: ogf 0x03, ocf 0x001a, plen 1

00

> HCI Event: 0x0e plen 4

01 1A 0C 00

# hciconfig hci0

hci0:    Type: USB

BD Address: 00:15:83:07:D5:78 ACL MTU: 310:10 SCO MTU: 64:8

UP RUNNING

RX bytes:1459 acl:0 sco:0 events:63 errors:0

TX bytes:764 acl:0 sco:0 commands:63 errors:0

# hcitool cmd 0x03 0x001A 0x01

< HCI Command: ogf 0x03, ocf 0x001a, plen 1

01

> HCI Event: 0x0e plen 4

01 1A 0C 00

# hciconfig hci0

hci0:    Type: USB

BD Address: 00:15:83:07:D5:78 ACL MTU: 310:10 SCO MTU: 64:8

UP RUNNING ISCAN

RX bytes:1472 acl:0 sco:0 events:65 errors:0

TX bytes:771 acl:0 sco:0 commands:65 errors:0

# hcitool cmd 0x03 0x001A 0x02

< HCI Command: ogf 0x03, ocf 0x001a, plen 1

02

> HCI Event: 0x0e plen 4

01 1A 0C 00

# hciconfig hci0

hci0:    Type: USB

BD Address: 00:15:83:07:D5:78 ACL MTU: 310:10 SCO MTU: 64:8

UP RUNNING PSCAN

RX bytes:1491 acl:0 sco:0 events:68 errors:0

TX bytes:785 acl:0 sco:0 commands:68 errors:0

# hcitool cmd 0x03 0x001A 0x03

< HCI Command: ogf 0x03, ocf 0x001a, plen 1

03

> HCI Event: 0x0e plen 4

01 1A 0C 00

# hciconfig hci0

hci0:    Type: USB

BD Address: 00:15:83:07:D5:78 ACL MTU: 310:10 SCO MTU: 64:8

UP RUNNING PSCAN ISCAN

RX bytes:1525 acl:0 sco:0 events:73 errors:0

TX bytes:811 acl:0 sco:0 commands:73 errors:0

# vi bluetooth.sh

-----------------------------------

#!/bin/bash

insmod /lib/modules/`uname -r`/kernel/net/bluetooth/bluetooth.ko     &>/dev/null

insmod /lib/modules/`uname -r`/kernel/net/bluetooth/l2cap.ko         &>/dev/null

insmod /lib/modules/`uname -r`/kernel/net/bluetooth/sco.ko           &>/dev/null

insmod /lib/modules/`uname -r`/kernel/net/bluetooth/bnep/bnep.ko     &>/dev/null

insmod /lib/modules/`uname -r`/kernel/net/bluetooth/rfcomm/rfcomm.ko &>/dev/null

insmod /lib/modules/`uname -r`/kernel/drivers/bluetooth/hci_uart.ko &>/dev/null

lsmod | grep bluetooth

/etc/init.d/bluetooth restart

sleep 5

hciconfig -a

hciconfig hci0 up

hcitool dev > locate_dev

hcitool scan      > remote_dev

rm /dev/rfcomm0   &>/dev/null

mknod /dev/rfcomm0 c 216 1

chmod 666 /dev/rfcomm0

# configure rfcomm.conf

locate_dev_mac=`awk '{ if(NR ==2) printf $2}' locate_dev`

rm locate_dev

cat > /etc/bluetooth/rfcomm.conf << EOF

rfcomm0 {

bind   no;

device     $locate_dev_mac;

channel    1;

comment    "HCI003"

}

EOF

sdptool add --channel=1 DID SP DUN LAN FAX OPUSH FTP HS HF SAP NAP GN PANU HID CIP CTP A2SRC A2SNK SYNCML NOKID PCSUITE SR1

remote_dev_mac=`awk '/DTK/{printf $1}' remote_dev`

rm remote_dev

rfcomm bind /dev/rfcomm0 $remote_dev_mac 1

hcitool cc $remote_dev_mac

hciattach - attach serial devices via UART HCI to BlueZ stack

---------------------------------------------------

hciattach [-n] [-p] [-t timeout] tty type|id speed flow bdaddr

-n

Don't detach from controlling terminal.

tty

This specifies the serial device to attach. A leading /dev can be omitted. Examples: /dev/ttyS1 ttyS2

type|id

The type or id of the Bluetooth device that is to be attached,i.e. vendor or other device specific identifier. Currently supported types are

type     description

any      Unspecified HCI_UART interface, no vendor specific options

ericsson Ericsson based modules

digi     Digianswer based cards

xircom   Xircom PCMCIA cards:Credit Card Adapter and Real Port Adapter

csr      CSR Casira serial adapter or BrainBoxes serial dongle(BL642)

bboxes   BrainBoxes PCMCIA card (BL620)

swave    Silicon Wave kits

bcsp     Serial adapters using CSR chips with BCSP serial protocol

Supported IDs are (manufacturer id, product id)

0x0105, 0x080a

Xircom PCMCIA cards:Credit Card Adapter and Real Port Adapter

0x0160, 0x0002

BrainBoxes PCMCIA card (BL620)

speed

The speed specifies the UART speed to use. Baudrates higher than 115.200bps require vendor specific initializations that are not implemented for all types of devices. In general the following speeds are supported:

9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600

Supported vendor devices are automatically initialised to their respective best settings.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值