原文地址:http://blog.youkuaiyun.com/luotong86/article/details/37743553
1、查看hcitool支持哪些命令
# hcitool -h
hcitool - HCI Tool ver 4.101
Usage:
hcitool [options] <command> [command parameters]
Options:
--help Display help
-i dev HCI device
Commands:
dev Display local devices
inq Inquire remote devices
scan Scan for remote devices
name Get name from remote device
info Get information from remote device
spinq Start periodic inquiry
epinq Exit periodic inquiry
cmd Submit arbitrary HCI commands
con Display active connections
cc Create connection to remote device
dc Disconnect from remote device
sr Switch master/slave role
cpt Change connection packet type
rssi Display connection RSSI
lq Display link quality
tpl Display transmit power level
afh Display AFH channel map
lp Set/display link policy settings
lst Set/display link supervision timeout
auth Request authentication
enc Set connection encryption
key Change connection link key
clkoff Read clock offset
clock Read local or remote clock
lescan Start LE scan
lewladd Add device to LE White List
lewlrm Remove device from LE White List
lewlsz Read size of LE White List
lewlclr Clear LE White list
lecc Create a LE Connection
ledc Disconnect a LE Connection
lecup LE Connection Update
For more information on the usage of each command use:
hcitool <command> --help
2、扫描ble设备
# hcitool lescan
LE Scan ...
D0:39:72:BE:D2:26 (unknown)
D0:39:72:BE:D2:26 HMDongle
3、把设备添加到白名单
# hcitool lewladd D0:39:72:BE:D2:26
4、连接设备
有两种方式,一种是直接指定地址
# hcitool lecc D0:39:72:BE:D2:26
另一种是通过白名单
# hcitool lecc --whitelist
连接成功后返回连接句柄
Connection handle 18176
5、断开连接,指定连接句柄
# hcitool ledc 18176