2018년 6월 3일 일요일

Raspberry Pi KODI 와 harmony 연결

OpenELEC 나 Libreelc 의 KODI 를 사용하시는 분은 아래 설정은 필요 없습니다.
KODI setting 에서 bluetooth 를 on 하고 setting bluetooth 메뉴에서 Harmony Keyboard 를 페어링 하면 됩니다.

아래 Libreelc 에서의 블루투스 연결 방법 참조 
https://www.hifiberry.com/build/guides/connecting-an-amazon-echo-via-bluetooth-and-libreelec/

라즈비안을 이용하여 직접 커맨드 콘솔로 연결하실 경우 아래를 보시면 됩니다.

라즈베리파이2 모델의 경우
블루투스 동글이가 필요합니다. 5천원정도 할꺼예요

블루투스 동글이를 usb 포트에 꼽으면 아래와 같이 인식되었는지 알수 있습니다.
root 권한이 필요합니다.
pi@raspberrypi:~ $ sudo -s
root@raspberrypi:/home/pi# 

root@raspberrypi:/home/pi# lsusb
Bus 001 Device 004: ID 13fd:3940 Initio Corporation
Bus 001 Device 005: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. SMC9514 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub



"Cambridge Silicon Radio, Ltd Bluetooth Dongle" 이 USB 에 잘 인식 된것을 알수 있습니다. 

아래부터는 라즈베리파이2와3이 같습니다. 라즈베리3 부터는 블루투스가 내장되어 있습니다.

hcitool 명령으로 주변에 연결가능한 블루투스 디바이스를 찾아봅니다.

root@raspberrypi:/home/pi# hcitool scan
Scanning ...
       C8:DB:26:03:DE:ED       Harmony Keyboard
       8C:C8:CD:84:6B:21       TVBluetooth

여기서 디바이스들이 안나와도 상관없습니다. 
bluetoothctl 명령어로도 재 스캔 가능합니다.

root@raspberrypi:/home/pi# bluetoothctl
[NEW] Controller B8:27:EB:BC:AD:FC raspberrypi [default]
[bluetooth]# 

블루투스 명령 콘솔로 들어왔으면 help 를 쳐서 어떠한 명령들이 지원되는지 한번 봅니다.

[bluetooth]# help
Available commands:
  list                       List available controllers
  show [ctrl]                Controller information
  select               Select default controller
  devices                    List available devices
  paired-devices             List paired devices
  power              Set controller power
  pairable           Set controller pairable mode
  discoverable       Set controller discoverable mode
  agent   Enable/disable agent with given capability
  default-agent              Set agent as the default one
  advertise     Enable/disable advertising with given type
  set-advertise-uuids [uuid1 uuid2 ...] Set advertise uuids
  set-advertise-service [uuid][data=[xx xx ...] Set advertise service data
  set-advertise-manufacturer [id][data=[xx xx ...] Set advertise manufacturer data
  set-advertise-tx-power Enable/disable TX power to be advertised
  set-scan-filter-uuids [uuid1 uuid2 ...] Set scan filter uuids
  set-scan-filter-rssi [rssi] Set scan filter rssi, and clears pathloss
  set-scan-filter-pathloss [pathloss] Set scan filter pathloss, and clears rssi
  set-scan-filter-transport [transport] Set scan filter transport
  set-scan-filter-clear      Clears discovery filter.
  scan               Scan for devices
  info [dev]                 Device information
  pair [dev]                 Pair with device
  trust [dev]                Trust device
  untrust [dev]              Untrust device
  block [dev]                Block device
  unblock [dev]              Unblock device
  remove                Remove device
  connect               Connect device
  disconnect [dev]           Disconnect device
  list-attributes [dev]      List attributes
  set-alias           Set device alias
  select-attribute Select attribute
  attribute-info [attribute] Select attribute
  read                       Read attribute value
  write    Write attribute value
  notify             Notify attribute value
  register-profile Register profile to connect
  unregister-profile         Unregister profile
  version                    Display version
  quit                       Quit program


먼저 블루투스 power 를 on 하고 scan 을 해봅니다.
harmony 모바일 앱 에선 
Devices > Edit Devices > +Device > ENTERTAINMENT DEVICE :
Manufacturer Name : Apple
Model Number : KODI

이렇게해서 미리 추가합니다.

추가 후 추가된 Devices 에서 Apple Media Player 로 가서 아무키를 누르면 아래와 같이 페어링 하겠냐고 나옵니다.

이럴때 scan 을하면 목록이 나옵니다.

[bluetooth]# power on
Changing power on succeeded
[bluetooth]# scan on
Discovery started
[CHG] Controller B8:27:EB:BC:AD:FC Discovering: yes
[NEW] Device 88:0F:10:91:7B:FA MI_SCALE
[NEW] Device 8C:C8:CD:84:6B:21 TVBluetooth
[NEW] Device 00:9E:C8:B1:DE:22 MIBOX3
[bluetooth]# 

아까 hcitool scan 에서 나오지 않는 장치들을 볼수 있습니다.

[bluetooth]# scan on
Discovery started
[CHG] Controller B8:27:EB:BC:AD:FC Discovering: yes
[CHG] Device 88:0F:10:91:7B:FA RSSI: -82
[CHG] Device 00:9E:C8:B1:DE:22 RSSI: -94
[CHG] Device 8C:C8:CD:84:6B:21 RSSI: -99
[CHG] Device 8C:C8:CD:84:6B:21 TxPower: 0
[NEW] Device C8:DB:26:03:DE:ED Harmony Keyboard
[NEW] Device 88:0F:10:91:7B:FA MI_SCALE
[NEW] Device 00:9E:C8:B1:DE:22 MIBOX3

하모니 블루투스 HW주소를 통해 페어링을 합니다.
[bluetooth]# pair C8:DB:26:03:DE:ED 
Attempting to pair with C8:DB:26:03:DE:ED
[CHG] Device C8:DB:26:03:DE:ED Connected: yes
[CHG] Device C8:DB:26:03:DE:ED UUIDs: 00001124-0000-1000-8000-00805f9b34fb
[CHG] Device C8:DB:26:03:DE:ED UUIDs: 00001801-0000-1000-8000-00805f9b34fb
[CHG] Device C8:DB:26:03:DE:ED UUIDs: 830a5548-5c66-23bd-0949-c0040000227e
[CHG] Device C8:DB:26:03:DE:ED ServicesResolved: yes
[CHG] Device C8:DB:26:03:DE:ED Paired: yes
Pairing successful

페어링후 연결을 합니다.
[bluetooth]# connect C8:DB:26:03:DE:ED 
Attempting to connect to C8:DB:26:03:DE:ED
[CHG] Device C8:DB:26:03:DE:ED Connected: yes
[CHG] Device C8:DB:26:03:DE:ED ServicesResolved: yes
Connection successful

라즈베리파이가 재 부팅후에도 지속 적인 연결을 위하면 trust 명령어로 신뢰관계를 구축합니다.
[Harmony Keyboard]# trust C8:DB:26:03:DE:ED 
[CHG] Device C8:DB:26:03:DE:ED Trusted: yes
Changing C8:DB:26:03:DE:ED trust succeeded

이제 Harmony 리모콘으로도 KODI를 제어 가능합니다.

만약 하모니 모바일 앱에서 액티비티를 만들때 다시 페어링을 하라고 하면 페어링과 연결과정을 다시해줍니다.
아래와 같은 다시 페어링 하라는 메시지가 나올수 있음

[bluetooth]# pair C8:DB:26:03:DE:ED
Attempting to pair with C8:DB:26:03:DE:ED
Failed to pair: org.bluez.Error.AlreadyExists
[bluetooth]# connect C8:DB:26:03:DE:ED
Attempting to connect to C8:DB:26:03:DE:ED
[CHG] Device C8:DB:26:03:DE:ED Connected: yes
Connection successful
[CHG] Device C8:DB:26:03:DE:ED ServicesResolved: yes

재 페어링과 재 연결을 해주면 하모니앱에서 아래와 같이 연결되었다고 나옵니다.