라즈베리파이 LIRC(리모컨 송수신) 설정 #2

서론

전편에서 설정한 LIRC 서비스를 활용하여 실제 리모컨을 등록하는 방법을 알아보도록 하겠습니다.

irrecord

irrecord는 리모컨 수신기로 받은 실제 리모컨 신호를 lirc 라이브러리에서 사용할 수 있게 리모컨 설정 파일을 생성해주는 프로그램입니다.  help를 통해 알아보는 사용법은 다음과 같습니다.

pi@raspberrypi:~ $ irrecord -h
Usage: irrecord [options] [config file]
irrecord -u <config file>
irrecord -a <config file>
irrecord -l

Options:
-H –driver=driver Use given driver
-d –device=device Read from given device
-a –analyse Analyse raw_codes config files
-k –keep-root Don’t drop root privileges
-l –list-namespace List valid button names
-u –update Amend buttons to existing file
-U –plugindir=dir Load drivers from dir
-f –force Force raw mode
-n –disable-namespace Disable namespace checks
-Y –dynamic-codes Enable dynamic codes
-O –options-file Use alternative lirc_options.conf file
-D –loglevel=level ‘error’, ‘info’, ‘notice’,… or 3..10
-h –help Display this message
-v –version Display version

전편을 잘 따라했다면 새로운 리모컨 설정 파일을 만들때는 어떠한 옵션도 달 필요 없이 그냥 irrecord를 실행하면 됩니다. 단, lircd 서비스는 중단하셔야합니다.

pi@raspberrypi:~ $ irrecord
Using driver default on device /dev/lirc0
irrecord: could not open logfile “/home/pi/.cache/irrecord.log”
irrecord: Permission denied

irrecord – application for recording IR-codes for usage with lirc
Copyright (C) 1998,1999 Christoph Bartelmus(lirc@bartelmus.de)

This program will record the signals from your remote control
and create a config file for lircd.

A proper config file for lircd is maybe the most vital part of this
package, so you should invest some time to create a working config
file. Although I put a good deal of effort in this program it is often
not possible to automatically recognize all features of a remote
control. Often short-comings of the receiver hardware make it nearly
impossible. If you have problems to create a config file READ THE
DOCUMENTATION at https://sf.net/p/lirc-remotes/wiki

If there already is a remote control of the same brand available at
http://sf.net/p/lirc-remotes you might want to try using such a
remote as a template. The config files already contains all
parameters of the protocol used by remotes of a certain brand and
knowing these parameters makes the job of this program much
easier. There are also template files for the most common protocols
available. Templates can be downloaded using irdb-get(1). You use a
template file by providing the path of the file as a command line
parameter.

Please take the time to finish the file as described in
https://sourceforge.net/p/lirc-remotes/wiki/Checklist/ an send it
to <lirc@bartelmus.de> so it can be made available to others.

Press RETURN to continue.

위의 강조표시한 주소로 가면 알려져있는 브랜드의 리모컨 설정 파일을 받을 수 있다고 합니다. 그냥 ENTER 키를 눌러 넘어갑시다.

Checking for ambient light creating too much disturbances.
Please don’t press any buttons, just wait a few seconds…

No significant noise (received 96 bytes)

ENTER키를 누르면 주변에 잡신호가 많이 있는지 확인하는 과정을 거칩니다. 키보드와 리모컨 둘다 아무것도 누르지 마시고 가만히 계시면 됩니다. 만약 아래와 같이 노이즈가 많다고하면 일단 Ctrl+C로 작업을 중단하고, 주변에 적외선 신호를 발생시킬만한 것이 있는지(형광등, 직사광선 등) 다시한번 확인한 뒤 irrecord를 실행하시기 바랍니다. 만약 무시하고 진행하겠다하면 ENTER키를 누르셔서 진행하시면 됩니다. 참고로 저는 리모컨 등록 절차 수행중일때는 불꺼놓고 합니다.

Here is a lof of noise (2288 bytes received)
Running irrecord with this level of noise will not give good results.
Please try to turn off fluorescent lamps or tubes and other sources
of variable IR radiation and restart. If nothing else works, you
might have to mask the receiving IR diode. You REALLY should press
ctrl-C at this point, but it’s technically possible to proceed
by pressing RETURN

노이즈를 확인하는 과정을 지나면 리모컨의 이름을 적어주고 Enter를 누릅니다. 이 이름은 lirc 서비스를 활용하는 다른 모듈들(python, node.js)에서 리모컨들을 구분하기 위한 이름이 됩니다. 리모컨끼리 구분이 되도록 이름을 지어줍시다. 리모컨 설정 파일이 완성이 되면 리모컨 설정 파일의 이름은 ‘remote-controller-name_as-you-want.lircd.conf’ 이 됩니다.

Enter name of remote (only ascii, no spaces) :remote-controller-name_as-you-want
Using remote-controller-name_as-you-want.lircd.conf as output filename

리모컨 이름을 입력하면 실제 리모컨 신호에서 신호 주파수가 얼마인지, 리모컨 신호를 구별해주는 ID는 무엇인지, 공통 부분의 값이 무잇인지 확인하는 절차를 가집니다. 엔터를 누르고  리모컨에 있는 버튼들을 꾹꾹(대략 1초씩) 눌러줍니다. 키를 누르면 화면에서 점(.)이 하나 또는 두개씩 늘어나는 것을 확인할 수 있습니다. 설명에는 무작위로 누르라고 되어있지만 버튼들을 순차적으로 눌러주어도 문제가 없었습니다. 단, 점이 처음 1 줄, 그리고 2줄이 보이고(터미널의 화면 크기에 따라서, 그리고 리모컨에 따라서 2줄까지 안보일 수도 있습니다) 아래의 강조, 이탤릭체 표시한(실제 터미널창에서는 강조, 이탤릭체가 되어있지 않습니다) 문장이 나올때까지 리모컨 버튼을 돌아가면서 누르는 것을 멈추면 안됩니다. 그리고, 같은 버튼을 점 기준으로 10개 연속으로 눌러서는 안됩니다.

Now start pressing buttons on your remote control.

It is very important that you press many different buttons randomly
and hold them down for approximately one second. Each button should
generate at least one dot but never more than ten dots of output.
Don’t stop pressing buttons until two lines of dots (2×80) have
been generated.

Press RETURN now to start recording.
……………………………………………………………………..
Got gap (108260 us)}

Please keep on pressing buttons like described above.
………………………………………………………………………………………………………………………………….

Please enter the name for the next button (press <ENTER> to finish recording)

 

이제 리모컨의 각 키들을 등록해줄 차례입니다. ‘irrecord –list-namespace’를 통해 lirc 안에 기술되어있는 키 이름을 볼 수 있습니다. 전체 목록은 Appendix를 참조해주세요. 대소문자를 구분하여(통상적으로 전부 대문자로 씁니다) 키 이름을 입력하고 ENTER키를 누르면 리모컨 버튼을 눌러달라고 요청합니다. irrecord에서는 키 이름의 대소문자를 구분하지 않지만, lirc를 활용하는 앱에서는 키의 대소문자를 구분하게됩니다. 따라서 왠만하면 대문자로 통일해서 사용하세요. 리모컨 버튼을 누르고 인식이 잘됬으면 다음 등록할 키 이름을 입력해달라고 합니다. 예시로 KEY_POWER와 KEY_MUTE를 등록한 결과는 아래와 같습니다.

Please enter the name for the next button (press <ENTER> to finish recording)
KEY_POWER <- 직접 입력함

Now hold down button “KEY_POWER”.  <- 이 문장이 나타나면 리모컨 키를 누릅니다.

Please enter the name for the next button (press <ENTER> to finish recording) <- 등록이 정상적으로 이루어지면 바로 이 문장이 나타납니다.
KEY_MUTE <- 계속해서 등록하고 싶은 키를 입력하면 됩니다.

Now hold down button “KEY_MUTE”. <- 마찬가지로 이 문장이 나타나면 리모컨 키를 누릅니다.

Please enter the name for the next button (press <ENTER> to finish recording)

키 등록을 마치겠다면 위에서 키 이름을 입력하는 단계에서 아무것도 입력하지 않고 ENTER 키를 누르면 됩니다.

Please enter the name for the next button (press <ENTER> to finish recording)

<- 아무것도 입력하지 않고 ENTER키를 누르면  키 등록을 종료합니다.

마지막 단계로 키를 눌렀다 뗐다를 이야기해주는 toggle bit의 존재 유무를 판단하는 절차를 수행합니다. ENTER키를 누르고 임의의(arbitrary) 키 한 개를 반복해서 빠르게 눌러주면 됩니다. (꾹 누르고 있으면 안됩니다)

Checking for toggle bit mask.
Please press an arbitrary button repeatedly as fast as possible.
Make sure you keep pressing the SAME button and that you DON’T HOLD
the button down!.
If you can’t see any dots appear, wait a bit between button presses.

Press RETURN to continue.
Cannot find any toggle mask.

Successfully written config file remote-controller-name_as-you-want.lircd.conf

successfully ~가 나오면 키 등록이 정상적으로 완료되었습니다. 이 중 막히는 부분이 있으면 Trubleshoot를 활용해 주세요

리모컨 설정 파일 등록

리모컨 설정 파일(*.conf)을 ‘/etc/lirc/lircd.conf.d’ 폴더에 복사하고 ‘/etc/init.d/lircd reload’로 불러오면 됩니다. ‘/etc/ini.d/lircd status’로 잘 불러왔는지 확인할 수 있습니다.

pi@raspberrypi:~ $ sudo cp remote-controller-name_as-you-want.lircd.conf /etc/lirc/lircd.conf.d/
pi@raspberrypi:~ $ sudo /etc/init.d/lircd reload
[ ok ] Reload configuration for remote control daemon: LIRCD.
pi@raspberrypi:~ $ /etc/init.d/lircd status
● lircd.service – Flexible IR remote input/output application support
Loaded: loaded (/lib/systemd/system/lircd.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2017-09-13 14:17:29 UTC; 19min ago
Docs: man:lircd(8)
http://lirc.org/html/configure.html
Main PID: 432 (lircd)
CGroup: /system.slice/lircd.service
└─432 /usr/sbin/lircd –nodaemon

Sep 13 14:37:06 raspberrypi lircd[432]: lircd-0.9.4c[432]: Info: Using remote: remote-controller-name_as-you-want.
Sep 13 14:37:06 raspberrypi lircd-0.9.4c[432]: Info: Using remote: remote-controller-name_as-you-want.
Sep 13 14:37:10 raspberrypi lircd[432]: lircd-0.9.4c[432]: Notice: accepted new client on /var/run/lirc/lircd
Sep 13 14:37:10 raspberrypi lircd-0.9.4c[432]: Notice: accepted new client on /var/run/lirc/lircd

여기서 위의 문장 외에 warning 같은 경고 문장이 있는 경우 trubleshoot를 참고하세요.

irw

리모컨 설정 파일을 등록하고 lircd 서비스가 실행 중일 때 리모컨 신호를 수신한 결과를 화면상에 보여주는 명령어 입니다. 이 실행 파일로 리모컨이 잘 등록되었는지 확인할 수 있습니다. lircd 서비스가 실행되었는지 확인하고 irw을 실행한 뒤 리모컨 버튼을 눌러서 잘 인식되는지 확인합시다. 여기서 아무 반응이 없으면 아래 trubleshoot를 참고하세요.

pi@raspberrypi:/etc/lirc/lircd.conf.d $ sudo /etc/init.d/lircd reload
[ ok ] Reload configuration for remote control daemon: LIRCD.
pi@raspberrypi:/etc/lirc/lircd.conf.d $ irw
0000000000fed02f 00 KEY_POWER remote-controller-name_as-you-want
0000000000feb04f 00 KEY_MUTE remote-controller-name_as-you-want
0000000000fec03f 00 KEY_CHANNELUP remote-controller-name_as-you-want
0000000000feda25 00 KEY_CHANNELDOWN remote-controller-name_as-you-want
0000000000fe807f 00 KEY_VOLUMEUP remote-controller-name_as-you-want
0000000000fe40bf 00 KEY_VOLUMEDOWN remote-controller-name_as-you-want

정상적으로 작동하면 Cntl+C로 irw을 종료합니다.

 

Trubleshoot

irrecord

irrecord를 실행할 수 없을 때

lircd 서비스 데몬 또는 lircd를 활용하는 다른 프로그램(python, node.js 등)이 실행중인지, 실행중이면 종료하면 됩니다.

pi@raspberrypi:~ $ irrecord
Using driver default on device /dev/lirc0
irrecord: could not open logfile “/home/pi/.cache/irrecord.log”
irrecord: Permission denied
Could not init hardware (lircd running ? –> close it, check permissions)

리모컨 키를 제대로 등록할 수 없을 때 1

노이즈를 일으킬 수 있는 요인(형광등, 직사광선 등)을 차단하고 리모컨 인식절차를 처음부터 수행하세요. 계속해서 이러한 문제가 발생하면 그 리모컨을 등록할 때는 극도로 빛을 차단한 환경에서 ‘irrecord -f’로 raw code로 리모컨 설정 파일을 만들어야 합니다. raw code에 대한 내용은 여기서 다루지 않습니다.

Please enter the name for the next button (press <ENTER> to finish recording)
KEY_POWER

Now hold down button “KEY_POWER”.
Something went wrong: Cannot decode data
Please try again. (28 retries left)

Now hold down button “KEY_POWER”.
Something went wrong: Cannot decode data
Please try again. (27 retries left)

리모컨 키 등록을 마치고 다음 단계로 넘어갈 때 멈추는 경우

가끔씩 irrecord로 키 등록을 ENTER키로 종료하고 toggle mask를 감지하는 부분으로 넘어가지지 않거나 toggle mask를 감지하고 완전히 종료되는 단계로 넘어가지 않고 멈추는 경우가 있습니다. 이 때는 10초정도 충분한 시간을 기다린 후 Cntl+C로 irrecord를 강제종료합니다. 그리고 작업한 폴더에서 ‘ls -aZl irrecord-tmp*’ 명령어로 임시 저장된 파일 중 최근에 작업한 파일을 찾아서 열어보면 리모컨 설정 파일이 있을 가능성이 높습니다.

Now hold down button “key_mute”.

Please enter the name for the next button (press <ENTER> to finish recording)
<- 여기서 엔터를 눌렀지만 아무 반응이 없을 때

또는

Checking for toggle bit mask.
Please press an arbitrary button repeatedly as fast as possible.
Make sure you keep pressing the SAME button and that you DON’T HOLD
the button down!.
If you can’t see any dots appear, wait a bit between button presses.

Press RETURN to continue.
Cannot find any toggle mask.
 <- 이 단계에서 아무 반응이 없을 때

Cntl+C로 강제종료 후 ‘irrecord-tmp-*’ 파일을 찾아봅시다. 날짜 중 월 표시 왼쪽이 용량, 오른쪽이 작성시간입니다. 용량이 0이 아닌 것 중에서 작업시간에 가장 가까운 파일을 열어보면 내용이 정상적으로 작성되어 있을 것입니다. 시간은 별도의 설정을 하지 않으면 그리니치 표준시(GMT+00:00)로 표시되니 9시간 전으로 생각하시면 됩니다. 이름을 ‘자신의 리모컨 이름.lircd.conf’ 으로 바꾸어 쓰시면 됩니다.

^C <- Cntl+C를 누르면 터미널창에서 이렇게 뜹니다.
pi@raspberrypi:~ $ ls -aZl irrecord-tmp-*
-rw——- 1 pi pi ? 1089 Sep 13 15:37 irrecord-tmp-4D60Cv <- 오전 12시 39분 현재
-rw——- 1 pi pi ? 0 Sep 13 15:33 irrecord-tmp-aJXrwD
-rw——- 1 pi pi ? 0 Sep 13 13:00 irrecord-tmp-lxICwa
-rw——- 1 pi pi ? 0 Sep 13 13:05 irrecord-tmp-pD0XQ2
-rw——- 1 pi pi ? 0 Sep 13 13:05 irrecord-tmp-Pp1M9Q
pi@raspberrypi:~ $ mv irrecord-tmp-4D60Cv remote-controller-name.lircd.conf

 

irw

mode2에서도 제대로 인식하고 irrecord도 아무 문제 없이 수행했는데 irw에서 인식만 안되는 경우 두가지를 확인해보아야 합니다.

헤더가 코드에 포함된 경우

리모컨 설정 파일(*.conf)를 열어보았을 때 각 키에 동일한 값(0x00000000인 경우도 있고 아래와 같이 임의의 값인 경우도 있습니다)이 들어가있는게 보입니다. 헤더에 해당하는 부분이 키의 실제 코드로 오인되어서 irw에서 인식이 안됬던 겁니다. 이 부분(강조 표시)을 전부 지워주고 저장한다음 (‘/etc/lirc/lircd.conf.d’ 폴더에 리모컨 설정 파일을 복사해주고) ‘/etc/init.d/lircd reload’로 불러온다음 irw로 다시 테스트 해보세요.

begin remote

name remote-controller-name_as-you-want
bits 32
flags SPACE_ENC|CONST_LENGTH
eps 30
aeps 100

header 9090 4502
one 608 1638
zero 608 534
ptrail 605
repeat 9090 2232
gap 108228
toggle_bit_mask 0x0
frequency 38000

begin codes
KEY_POWER 0x00FED02F 0xBEF0320C
KEY_MUTE 0x00FEB04F 0xBEF0320C
KEY_CHANNELUP 0x00FEC03F 0xBEF0320C
KEY_CHANNELDOWN 0x00FEDA25 0xBEF0320C
KEY_VOLUMEUP 0x00FE807F 0xBEF0320C
KEY_VOLUMEDOWN 0x00FE40BF 0xBEF0320C
KEY_CYCLEWINDOWS 0x00FE2CD3 0xBEF0320C
end codes

end remote

toggle mask가 잘못 계산된 경우

제가 듣기로는 toggle mask가 키를 눌렀다 뗐다 한 부분을 알려주는 것이라 알고 있습니다. 이 부분이 실제와 다르게 기록이 되어서 irw에서 인식을 못한 것일 가능성이 있습니다. toggle mask의 값(강조 표시)을 ‘0x0’으로 바꾼 후 저장하고 리모컨 설정파일을 복사하여 다시 불러온 뒤 irw로 확인합시다.

begin remote

name remote-controller-name_as-you-want
bits 32
flags SPACE_ENC|CONST_LENGTH
eps 30
aeps 100

header 9090 4502
one 608 1638
zero 608 534
ptrail 605
repeat 9090 2232
gap 108228
toggle_bit_mask 0x800 <- 이 부분을 0x0 으로 수정해야합니다.
frequency 38000

begin codes
KEY_POWER 0x00FED02F
KEY_MUTE 0x00FEB04F
KEY_CHANNELUP 0x00FEC03F
KEY_CHANNELDOWN 0x00FEDA25
KEY_VOLUMEUP 0x00FE807F
KEY_VOLUMEDOWN 0x00FE40BF
KEY_CYCLEWINDOWS 0x00FE2CD3
end codes

end remote

 

Appendix

기본 키 값들

광고

라즈베리파이 LIRC(리모컨 송수신) 설정 #2”의 5개의 생각

    1. 이상한데요….. 위에서 irrecord 실행할 때 putty에서 복사해온 명령어(pi@raspberrypi:~ $ irrecord)를 보면 실행 계정이 root 계정이 아니라 pi(기본 계정)으로 나옵니다. 제가 이 글을 쓸 때 sudo가 필요한 부분은 정확히 sudo 까지 포함해서 적어놓았습니다.
      차후 강좌 수정을 위해 sudo를 안하고 irrecord를 실행시켰을 때 어떤식으로 오류가 났는지 복사해서 붙여주실 수 있나요?

      좋아요

  1. irrecord 에서
    Please keep on pressing buttons like described above.
    다음에 ……. 이 쭉 늘어다가 멈추더니 더 이상 진행이 안되는건 원인이 뭘까요ㅠㅠ
    엄한 리모컨만 10분을 넘게 뚜들겼네요…하…

    좋아요

    1. Press RETURN now to start recording.
      ……………………………………………………………………..
      Got gap (108260 us)}
      Please keep on pressing buttons like described above.

      여기서 첫번째 점찍히는거 아랫줄에 갭이 몇마이크로초로 나타나던가요

      좋아요

      1. 약 8600 정도욤…
        삼성 에어컨 리모컨을 저장하려고 하는데
        두 번째 점찍힐 땐 점이 버튼 1개당 3개씩 올라가네요…….
        계속 누르다 보면 무반응 상태로 빠지구욤

        irrecord -f 로 해서 raw로 하면 인식, 저장 다 잘 되긴 합니다만….

        좋아요

답글 남기기

아래 항목을 채우거나 오른쪽 아이콘 중 하나를 클릭하여 로그 인 하세요:

WordPress.com 로고

WordPress.com의 계정을 사용하여 댓글을 남깁니다. 로그아웃 /  변경 )

Facebook 사진

Facebook의 계정을 사용하여 댓글을 남깁니다. 로그아웃 /  변경 )

%s에 연결하는 중