linux 用蓝牙和手机通信
加载模块:
# modprobe hci_usb
# modprobe rfcomm
# hciconfig hci0 up
# hciconfig hci0 up
查看状况:
# hciconfig -a
hci0: Type: USB
BD Address: 00:10:60:A3:68:9F ACL MTU: 192:8 SCO MTU: 64:8
UP RUNNING PSCAN ISCAN
RX bytes:1860 acl:10 sco:0 events:88 errors:0
TX bytes:1432 acl:10 sco:0 commands:52 errors:0
Features: 0xff 0xff 0x0f 0x00
Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
Link policy: HOLD SNIFF PARK
Link mode: SLAVE ACCEPT
Name: 'Debian'
Class: 0x000100
Service Classes: Unspecified
Device Class: Computer, Uncategorized
HCI Ver: 1.1 (0x1) HCI Rev: 0x20d LMP Ver: 1.1 (0x1) LMP Subver: 0x20d
Manufacturer: Cambridge Silicon Radio (10)
扫描周围蓝牙设备:
# hcitool scan
Scanning...
00:80:37:B5:A8:3A T68i
00:0E:07:1C:AE:1D T628
Ping一下看看:
# l2ping 00:0E:07:1C:AE:1D #(l2ping,是小写的L而不是数字1)
Ping: 00:0E:07:1C:AE:1D from 00:10:60:A3:68:9F (data size 20) ...
0 bytes from 00:0E:07:1C:AE:1D id 200 time 39.62ms
0 bytes from 00:0E:07:1C:AE:1D id 201 time 35.25ms
0 bytes from 00:0E:07:1C:AE:1D id 202 time 33.60ms
0 bytes from 00:0E:07:1C:AE:1D id 203 time 40.57ms
0 bytes from 00:0E:07:1C:AE:1D id 204 time 38.96ms
0 bytes from 00:0E:07:1C:AE:1D id 205 time 34.60ms
6 sent, 6 received, 0% loss
本地主机配置文件(主机名等参数):
/etc/bluetooth/hcid.conf
PIN配对码所在文件:
/etc/bluetooth/pin
加载配置文件:
#hcid -f /etc/bluetooth/hcid.conf