TrumanWong

hcitool

hcitool is a Linux command line tool for managing and debugging Bluetooth devices. It can be used to scan surrounding Bluetooth devices, connect to Bluetooth devices to send commands and data packets, etc.

Install

hcitool is a Linux command line tool that is usually pre-installed in most Linux distributions. If hcitool is not installed in your system, you can use the following command to install it (debian series release example)

sudo apt-get install bluez

use

Precautions:

  1. To use ble related commands, you need to escalate your privileges, such as: lescan

grammar

hcitool [options] <command> [command parameters]

Order

     dev displays local devices
     inq queries remote devices
     scan scans remote devices
     name Get name from remote device
     info Get information from remote device
     spinq starts a periodic query
     epinq exit periodic query
     cmd Submit arbitrary HCI commands
     con shows active connections
     cc creates a connection to a remote device
     dc Disconnect from remote device
     sr switch central/peripheral role
     cpt changes connection packet type
     rssi show connection rssi
     lq displays link quality
     tpl displays transmit power level
     afh display afh channel map
     lp settings/show link policy settings
     lst sets/displays link monitoring timeout
     auth request authentication
     enc sets connection encryption
     key changes the connection link key
     clkoff reads clock offset
     clock reads local or remote clock
     lescan starts LE scan
     leinfo Get LE remote information
     lealadd Add device to LE accept list
     dealrm Remove device from LE accept list
     lealsz LE accept list read size
     lealclr Clear LE acceptance list

Commonly used simple examples

  1. Scan for surrounding Bluetooth devices

hcitool scan

  1. Connect to Bluetooth device via mac address

hcitool cc <MAC address>

  1. Display current Bluetooth adapter information

hcitooldev

  1. Find the Bluetooth name by mac address

hcitool name <MAC address>

  1. Display current Bluetooth active connection information

hcitool con