Linux下Bluetooth的使用

1. 激活设备

首先要有一个蓝牙适配器,这个不用说,一般都是USB接口类型。

lsusb               查看系统中连接的蓝牙设备
hciconfig           查看设备的详细信息
hciconfig hci0 up   将设备激活

2. 配置bluez

配置文件位于目录/etc/bluetooth

3. bluetooth服务

/etc/rc.d/init.d/bluetooth stop
/etc/rc.d/init.d/bluetooth start

4. 扫描设备

hcitool scan
通过以上命令可以查找周围的Bluetooth设备

5. 绑定设备

有两种方式来绑定目的蓝牙设备
@1 修改/etc/bluetooth/rfcomm.conf
@2 rfcomm bind /dev/rfcomm0 XX:XX:XX:XX:XX:XX

解除绑定方法是
# rfcomm unbind /dev/rfcomm0 BD_ADDR channel

tip: 如果没有虚拟串口设备(rfcomm0),则需要手动创建(rfcomm_create_dev?)

# mknod /dev/rfcomm0 c 216 1
# chmod 666 /dev/rfcomm0

6. 添加通道

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

后面的参数表示系统支持的全部服务

7. 连接设备

hcitool cc XX:XX:XX:XX:XX:XX

8. 发送文件

obex-send *.*

9. bluez tools

bccmd:            used to issue BlueCore commands to Cambridge Silicon Radio devices.
bluetoothd:       the Bluetooth daemon.
ciptool:          used to set up, maintain, and inspect the CIP configuration of the Bluetooth subsystem in the Linux kernel.
hciattach:        used to attach a serial UART to the Bluetooth stack as HCI transport interface.
hciconfig:        used to configure Bluetooth devices.
hcitool:          used to configure Bluetooth connections and send some special command to Bluetooth devices.
hid2hci:          used to set up switch supported Bluetooth devices into the HCI mode and back.
l2ping:           used to send a L2CAP echo request to the Bluetooth MAC address given in dotted hex notation.
rctest:           used to test RFCOMM communications on the Bluetooth stack.
rfcomm:           used to set up, maintain, and inspect the RFCOMM configuration of the Bluetooth subsystem in the Linux kernel.
sdptool:          used to perform SDP queries on Bluetooth devices.
libbluetooth.so:  contains the BlueZ 4 API functions. 



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章