LINUX byDreamy postedMay 24, 2017

블루투스 사용하기 hci tool

?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

+ - Up Down Comment Print

http://examplenow.com/ko/hcitool/usage


hcitool

블루투스 연결을 구성

   hcitool - HCI Tool ver 4.69
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
	lecc	Create a LE Connection
	ledc	Disconnect a LE Connection

For more information on the usage of each command use:
	hcitool <command> --help





HCITOOL

Section: Linux System Administration (1)
Updated: Nov 12 2002
Index  

NAME

hcitool - configure Bluetooth connections  

SYNOPSIS

hcitool [-h] 
hcitool [-i <hciX>] [command [command parameters]]

 

DESCRIPTION

hcitool is used to configure Bluetooth connections and send some special command to Bluetooth devices. If no command is given, or if the option -h is used, hcitool prints some usage information and exits.  

OPTIONS

-h
Gives a list of possible commands
-i <hciX>
The command is applied to device hciX , which must be the name of an installed Bluetooth device. If not specified, the command will be sent to the first available Bluetooth device.

 

COMMANDS

dev
Display local devices
inq
Inquire remote devices. For each discovered device, Bluetooth device address, clock offset and class are printed.
scan
Inquire remote devices. For each discovered device, device name are printed.
name <bdaddr>
Print device name of remote device with Bluetooth address bdaddr.
info <bdaddr>
Print device name, version and supported features of remote device with Bluetooth address bdaddr.
spinq
Start periodic inquiry process. No inquiry results are printed.
epinq
Exit periodic inquiry process.
cmd <ogf> <ocf> [parameters]
Submit an arbitrary HCI command to local device. ogfocf and parameters are hexadecimal bytes.
con
Display active baseband connections
cc [--role=m|s] [--pkt-type=<ptype>] <bdaddr>
Create baseband connection to remote device with Bluetooth address bdaddr. Option --pkt-type specifies a list of allowed packet types. <ptype> is a comma-separated list of packet types, where the possible packet types are DM1DM3DM5DH1DH3DH5HV1HV2HV3. Default is to allow all packet types. Option --role can have value m (do not allow role switch, stay master) or s (allow role switch, become slave if the peer asks to become master). Default is m.
dc <bdaddr> [reason]
Delete baseband connection from remote device with Bluetooth address bdaddr. The reason can be one of the Bluetooth HCI error codes. Default is 19 for user ended connections. The value must be given in decimal.
sr <bdaddr> <role>
Switch role for the baseband connection from the remote device to master or slave.
cpt <bdaddr> <packet types>
Change packet types for baseband connection to device with Bluetooth address bdaddrpacket types is a comma-separated list of packet types, where the possible packet types are DM1DM3DM5DH1DH3DH5HV1HV2HV3.
rssi <bdaddr>
Display received signal strength information for the connection to the device with Bluetooth address bdaddr.
lq <bdaddr>
Display link quality for the connection to the device with Bluetooth address bdaddr.
tpl <bdaddr> [type]
Display transmit power level for the connection to the device with Bluetooth address bdaddr. The type can be 0 for the current transmit power level (which is default) or 1 for the maximum transmit power level.
afh <bdaddr>
Display AFH channel map for the connection to the device with Bluetooth address bdaddr.
lp <bdaddr> [value]
With no value, displays link policy settings for the connection to the device with Bluetooth address bdaddr. If value is given, sets the link policy settings for that connection to value. Possible values are RSWITCH, HOLD, SNIFF and PARK.
lst <bdaddr> [value]
With no value, displays link supervision timeout for the connection to the device with Bluetooth address bdaddr. If value is given, sets the link supervision timeout for that connection to value slots, or to infinite if value is 0.
auth <bdaddr>
Request authentication for the device with Bluetooth address bdaddr.
enc <bdaddr> [encrypt enable]
Enable or disable the encryption for the device with Bluetooth address bdaddr.
key <bdaddr>
Change the connection link key for the device with Bluetooth address bdaddr.
clkoff <bdaddr>
Read the clock offset for the device with Bluetooth address bdaddr.
clock [bdaddr] [which clock]
Read the clock for the device with Bluetooth address bdaddr. The clock can be 0 for the local clock or 1 for the piconet clock (which is default).


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


http://www.rasplay.org/?p=9928


1. 블루투스 패키지 설치

패키기지를 설치하기에 앞서 설치 시 발생할 수 있는 문제요소 제거를 위해 라즈비안에 설치되어 있는 패키지르ㄹ 최신 버전들로 업데이트 해 주도록 하자.

pi@openmake ~ $ sudo apt-get && sudo apt-get upgrade -y

pi@openmake ~ $ sudo apt-get install bluetooth bluez-utils bluez-compat

2. 블루투스 장치 확인

블루투스 동글이를 라즈베리파이 USB 에 연결 한 뒤 라즈비안에서 정상적으로 장치가 인식하는지를 확인 해 보도록 하자.

리눅스 명령어 중 USB에 연결되ㄴ 리스트 장치를 확인 할 수 있는 “lsusb”  커맨드를 입력 해 블루투스가 제대로 연결되어져 있는지를 확인 해 보자.

pi@openmake ~ $ lsusb | grep -i bluetooth

bluetooth_2

 

3. 블루투스 페어링(연결) 하기

리눅스 명령어 중 블루투스 장치 검색을 할 수 있는 “hcitool scan” 명령어를  이용해 USB동글이와 연결할 장치 맥 어드레스를 확인 해 보도록 하자.

명령어를 입력하기 전에 반듯이 USB 동글이와 페어링 할 대상의 scan 허용 버튼을 눌러 준 뒤에 명령어를 입력 하도록 하자.

pi@openmake ~ $ hcitool scan

bluetooth_3

블루투스 USB동글이는 사용하는 유저의 대부분이 가장 많이 만나게 될 오류 두가지 일 것이다.

1)

bluetooth_4

2)

bluetooth_6

위 두가지 오류를 해결 하기 위해서는 “/usr/bin/bluez-simple-agent” 파일 내용 중,

capability = “KeyboardDisplay” 를 capability = “DisplayYesNo” 으로 변경 해 , 위와 같은 오류 현상을 해결 할 수가 있다.

그럼 아래와 같이 커맨드 창에 입력하여 파일 속 내용을 변경 해 보도록 하자.

pi@raspberrypi ~ $ grep KeyboardDisplay /usr/bin/bluez-simple-agent
pi@raspberrypi ~ $ sudo perl -i -pe ‘s/KeyboardDisplay/DisplayYesNo/’ /usr/bin/bluez-simple-agent
pi@raspberrypi ~ $ grep DisplayYesNo /usr/bin/bluez-simple-agent

bluetooth_7

위 사진 속 내용과 같이 capability 의 내용을 변경 후 블루투스 페어링 명령어를 입력 시 정상적으로 키보드와 페어링 되었음을 알 수가 있다.

pi@raspberrypi ~ $ sudo bluez-simple-agent hci0 DC:2C:26:E6:28:DE

위 페어링(연결) 명령어를 입력 후에는 라즈베리파이와 연결 될 장치의 연결 버튼을 반듯이 눌러 주어야만 된다.

 

4. 블루투스 페어링(연결) 후, 장치관리 팁 모음

그럼 마지막으로 블루투스 기기 페어링 후, 매번 위와 같이 블루투스 디바이스 별로 연동 및 PIN Code 입력을 해 주어야 하는 불편함이 있다.

이러한 불편한 요소를 제거 해 보자.

 

4.1. 신뢰성 장치 등록하기

라즈비안 쉘 커맨드 창에서 아래 명령어를 입력 해  매번  등록해야 하는 디바이스 인증절차를 제거 해 보도록 하자.

* 아래 MAC ADDRESS 는 각 장치별로 별도의 별도 어드레스로 등록을 해 주어야 만 한다.

pi@raspberrypi ~ $ sudo bluez-simple-agent hci0 DC:2C:26:E6:28:DE

 

4.2. 신뢰성 장치 제거하기

3.1을 통해 새로구입한 장치를 등록하였다면, 이를 제거 할 수가 있다.

장치를 등록 했듯이 아래 명령어 입력으로 제거 해 보도록 하자.

pi@raspberrypi ~ $ sudo bluez-test-device remove DC:2C:26:E6:28:DE

 

4.3  블루투스 키보드 활성화

라즈비안에서는 브ㄹ블루투스 키보드를 사용하기 위해선 위 절차를 진행 후, 입력이 가능토록 한번 더 활성화  명령어를 실행 해 주어야 했다.

pi@raspberrypi ~ $ bluez-test-input connect  DC:2C:26:E6:28:DE

마지막으로 라즈베리파이를 재부팅을 하게 되면 블루투스 키보드가 지속적으로 연동이 되어 있는 확인이 가능한 명령어는 아래 명령어를 사용 하면 된다.

pi@raspberrypi ~ $ hcitool con

Connections:
< ACL DC:2C:26:E6:28:DE handle 41 state 1 lm MASTER AUTH ENCRYPT

 

위와 같이 연결된 장치의 정보가 보이지 않는다면 키보드 입력이 되지 않을 것이다.

또한, 재부팅 후 바로 사용이 가능한 것은 아니였다.

필자가 테스트 한 바로는  라즈비안이 모두 부팅된 이후 약 5 ~ 10초 정도 오토페어링이 되는 시간이 필요하였다.

pi@raspberrypi ~ $ hcitool con

Connections:

pi@raspberrypi ~ $

 

이상으로 라즈베리파이 쉘 커맨드에서 블루투스 4.0 디바이스 강좌를 마치도록 하겠다.

P.S  : 키보드 입력과 같은 입력장치들의 경우에는 위와 같은 방법으로 모두 활성화 테스트를 마치었고, PS3 및 블루투스 조이스틱 역시 모두 테스트를 완료하였다.

 

[참고사이트]

http://www.correlatedcontent.com/blog/bluetooth-keyboard-on-the-raspberry-pi

http://elinux.org/RPi_Bluetooth_keyboard_setup

http://www.wolfteck.com/projects/raspi/iphone

 





나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소

Designed by sketchbooks.co.kr / sketchbook5 board skin

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5