LIRC: Difference between revisions

From ArchWiki
m (Comment syntax)
(Usage examples)
Line 64: Line 64:
{{Warning|Reception from both ''alsa_audio'' and ''audio'' can be pretty unstable (''irw'' drops keypresses and works from time to time). If sound card is your only option and you only need to create an remote config with ''irrecord'', give a chance to [http://winlirc.sourceforge.net/ WinLIRC], as it uses different sound subsystem.}}
{{Warning|Reception from both ''alsa_audio'' and ''audio'' can be pretty unstable (''irw'' drops keypresses and works from time to time). If sound card is your only option and you only need to create an remote config with ''irrecord'', give a chance to [http://winlirc.sourceforge.net/ WinLIRC], as it uses different sound subsystem.}}


''audio_alsa'' [http://www.lirc.org/html/audio-alsa.html driver] included in {{pkg|lirc}}, but supports only reception.
''audio_alsa'' [http://www.lirc.org/html/audio-alsa.html driver] included in {{pkg|lirc}}, but supports only reception. Make sure microphone input is unmuted and has enough gain.


{{hc|/etc/lirc/lirc_options.conf|2=
{{hc|/etc/lirc/lirc_options.conf|2=
Line 121: Line 121:
  include "~/.config/lircrc/mythtv"
  include "~/.config/lircrc/mythtv"
  include "~/.config/lircrc/vlc"
  include "~/.config/lircrc/vlc"
== Usage ==
[[Start/enable]] {{ic|lircd.service}}.
Test the remote using {{man|1|irw}}, which writes to stdout known codes from config, received by LIRC, e.g.:
$ irw
000000037ff07bfe 00 One mceusb
000000037ff07bfd 00 Two mceusb
000000037ff07bfd 01 Two mceusb
000000037ff07bf2 00 Home mceusb
000000037ff07bf2 01 Home mceusb
If {{ic|irw}} gives no output, double check the config files in {{ic|/etc/lirc/lircd.conf.d/}} for errors.


=== Running as a regular user rather than as root ===
=== Running as a regular user rather than as root ===
Line 169: Line 154:


Reboot the system to verify expected function.
Reboot the system to verify expected function.
== Testing ==
[[Start/enable]] {{ic|lircd.service}}.
=== Receiving commands ===
Run {{man|1|irw}}, point remote to the receiver and press some buttons. Received codes will be printed to stdout.
$ irw
000000037ff07bfe 00 One mceusb
000000037ff07bfd 00 Two mceusb
000000037ff07bfd 01 Two mceusb
000000037ff07bf2 00 Home mceusb
000000037ff07bf2 01 Home mceusb
If {{ic|irw}} gives no output:
* Run ''mode2'' or ''xmode2'' to see if LIRC actually read something from IR sensor, if no - check the hardware
* Check the config files in {{ic|/etc/lirc/lircd.conf.d/}} for errors
=== Transmitting commands ===
List registered remotes (config files):
$ irsend LIST "" ""
LG_6710CMAP01A
List available codes for the specific device:
$ irsend LIST LG_6710CMAP01A ""
0000000000007887 KEY_POWER
000000000000f807 KEY_MUTE
000000000000e817 KEY_VOLUMEUP
...
Send some command using this device:
$ irsend SEND_ONCE LG_6710CMAP01A KEY_POWER


== Troubleshooting ==
== Troubleshooting ==
Line 247: Line 269:


== See also ==
== See also ==
 
* [http://sf.net/p/lirc Project site]
* [http://lirc.sourceforge.net/lirc.org/html/index.html Upstream documentation]
* [http://lirc.sourceforge.net/lirc.org/html/index.html Upstream documentation]
* [http://lirc.org/html/configuration-guide.html Upstream Configuration Guide]
* [http://lirc-remotes.sourceforge.net/remotes-table.html Remotes database]
* [http://lirc-remotes.sourceforge.net/remotes-table.html Remotes database]
* [http://sf.net/p/lirc Project site]
* [http://lirc.org/html/configuration-guide.html Upstream Configuration Guide]
* [http://www.mythtv.org/wiki/Category:Remote_Controls MythTV Wiki:Remotes article]
* [http://www.mythtv.org/wiki/Category:Remote_Controls MythTV Wiki:Remotes article]
* [https://github.com/graysky2/streamzap Linux Streamzap config files]
* [https://github.com/graysky2/streamzap Linux Streamzap config files]

Revision as of 15:18, 4 January 2020

From the official website:

LIRC (Linux Infrared Remote Control) is a package that decodes and sends infra-red signals of many (but not all) commonly used remote controls.
Note: Since 4.18 the kernel can decode the signals of some IR remote controls using BPF, making LIRC sometimes redundant.[1]

This article covers setup and usage of LIRC with serial or USB infrared devices.

LIRC is a daemon that can translate key presses on a supported remote into program specific commands. In this context, the term, "program specific" means that a key press can do different things depending on which program is running and taking commands from LIRC.

  1. A button on the remote is pressed causing it to transmit an IR or RF signal.
  2. The signal is received by the receiver connected to the Linux computer.
  3. The kernel (via the correct module) use presents pulse data from the remote on a device like /dev/lirc0, /dev/input/eventX, /dev/ttyUSBX or /dev/ttyS0.
  4. /usr/bin/lircd uses the information from /etc/lirc/lircd.conf.d/foo.conf to convert the pulse data into button press information.
  5. Programs that use LIRC translate the button press info from /usr/bin/lircd into user-defined actions according to ~/.config/lircrc or to program-specific mappings.

Installation

Install the lirc package. If you need audio driver, install lirc-gitAUR.

Configuration

Receiver and transmitter configuration

Note: This section is a quick summary. Complete documentation is available upstream.

The driver and/or the device for the LIRC service may need to be specified in order to run properly. Look for messages like these in the journalctl output if the service abruptly stops while running LIRC-dependent programs such as irrecord:

Driver `devinput' not found or not loadable (wrong or missing -U/--plugindir?).
readlink() failed for "auto": No such file or directory

Set these in the config file and then restart the service.

/etc/lirc/lirc_options.conf
[lircd]
driver = driver-name
device = /dev/path-to-dev

Serial port

Tip: For DIY schematic refer to serial port receivers and transmitters documentation. Note that serial port device much more reliable than audio_alsa or audio.

Modern kernel has serial_ir module, which supersedes older lirc_serial driver. It supports even DIY receivers and transmitters, connected to the motherboard's serial port. Install setserialAUR and run:

# setserial /dev/ttyS0 uart none
# modprobe serial_ir

After loading serial_ir module, device /dev/lirc0 will be created by kernel. If not, check dmesg | grep serial for errors. An LIRC config example for serial device:

/etc/lirc/lirc_options.conf
[lircd]
driver          = default
device          = auto

[modinit]
code = /usr/bin/setserial /dev/ttyS0 uart none
code1 = /usr/sbin/modprobe serial_ir

Sound card

Warning: Reception from both alsa_audio and audio can be pretty unstable (irw drops keypresses and works from time to time). If sound card is your only option and you only need to create an remote config with irrecord, give a chance to WinLIRC, as it uses different sound subsystem.

audio_alsa driver included in lirc, but supports only reception. Make sure microphone input is unmuted and has enough gain.

/etc/lirc/lirc_options.conf
driver          = audio_alsa
device          = default

audio driver (archived) included in lirc-gitAUR and supports both reception and transmission. Note, that default latency around 0.02 can cause "Warning: Output underflow" and corrupted transmission - receiver won't respond to it. Try a higher value like 0.05.

/etc/lirc/lirc_options.conf
driver          = audio
device          = ALSA:default@48000:0.05

Remote configuration

Directory /etc/lirc/lircd.conf.d/ contains system-wide configuration files for remotes. Each *.conf file corresponds to one device and describes it's protocol, scancodes and keycodes. It allows LIRC receive and send signals for specific hardware. These files aren't included in lirc package and should be found somewhere or created by user.

Searching for remote configuration

Plenty of configuration files can be found in the LIRC remotes database. Follow the url or use irdb-get(1) to search the database.

An example using irdb-get to find a config file for a "Streamzap" remote:

$ irdb-get find stream
atiusb/atiusb.lircd.conf
digital_stream/DTX9900.lircd.conf
snapstream/Firefly-Mini.lircd.conf
streamzap/PC_Remote.lircd.conf
streamzap/streamzap.lircd.conf
x10/atiusb.lircd.conf

$ irdb-get download streamzap/streamzap.lircd.conf 
Downloaded sourceforge.net/p/lirc-remotes/code/ci/master/tree/remotes/streamzap/streamzap.lircd.conf as streamzap.lircd.conf

Once identified, copy the needed conf to /etc/lirc/lircd.conf.d/ to allow the daemon to initialize support for it.

# cp streamzap.lircd.conf /etc/lirc/lircd.conf.d/

Creating remote configuration

Remote control configurations can be created using irrecord(1), which guides users trough the process. If using a detected remote, invoke it like so:

# irrecord --device=/dev/lirc0 MyRemote

The program will instruct user to begin hitting keys on the remote in an attempt to learn it, ultimately mapping out every button and it's corresponding scancode. When finished, save the resulting file to /etc/lirc/lircd.conf.d/foo.conf and proceed. Consider sharing configuration file with others.

Application-specific actions

Tip: Many application-specific lircrc files are available on the internet.

Bind keycodes to application-specific actions by placing their respective configuration files in ~/.config/lircrc/ which should be created manually if desired, see lircrc(5). This only works for LIRC-aware applications, like MPlayer, VLC, MythTV and totem (Kodi also supports LIRC but does so in a non-standard way, see Kodi#Using a remote control).

Define these application-specific configurations in separate files and include them in lircrc, like:

include "~/.config/lircrc/mplayer"
include "~/.config/lircrc/mythtv"
include "~/.config/lircrc/vlc"

Running as a regular user rather than as root

By default, lircd runs as user root. However, for increased stability and security, upstream recommends running it as a regular user. See Appendix 14 at this link.

To do this, create and provision a lirc user:

# groupadd -r lirc
# useradd -r -g lirc -d /var/lib/lirc -s /usr/bin/nologin -c "LIRC daemon user" lirc
# usermod -a -G lock,input lirc

Augment the package-providing service unit by creating a lircd Systemd#Drop-in files:

# systemctl edit lircd
[Service]
User=lirc
Group=lirc

CapabilityBoundingSet=CAP_SETEUID
MemoryDenyWriteExecute=true
NoNewPrivileges=true
PrivateTmp=true
ProtectHome=true
ProtectSystem=full

To allow /dev/lirc* devices to be accessible for the lirc group and to grant r/w access for the lirc group to USB devices using ACLs, copy the following udev rule into place:

# cp /usr/share/lirc/contrib/60-lirc.rules /etc/udev/rules.d/

To allow access to the lirc group to be able to create a PID file, create the following lircd tmpfile which will supersede the package provided one (which makes ownership only to root):

/etc/tmpfiles.d/lirc.conf
d /run/lirc 0755 lirc lirc -

Reboot the system to verify expected function.

Testing

Start/enable lircd.service.

Receiving commands

Run irw(1), point remote to the receiver and press some buttons. Received codes will be printed to stdout.

$ irw
000000037ff07bfe 00 One mceusb
000000037ff07bfd 00 Two mceusb
000000037ff07bfd 01 Two mceusb
000000037ff07bf2 00 Home mceusb
000000037ff07bf2 01 Home mceusb

If irw gives no output:

  • Run mode2 or xmode2 to see if LIRC actually read something from IR sensor, if no - check the hardware
  • Check the config files in /etc/lirc/lircd.conf.d/ for errors

Transmitting commands

List registered remotes (config files):

$ irsend LIST "" ""
LG_6710CMAP01A

List available codes for the specific device:

$ irsend LIST LG_6710CMAP01A ""
0000000000007887 KEY_POWER
000000000000f807 KEY_MUTE
000000000000e817 KEY_VOLUMEUP
...

Send some command using this device:

$ irsend SEND_ONCE LG_6710CMAP01A KEY_POWER

Troubleshooting

Remote functions as a keyboard

When using Xorg

Xorg detects some remotes, such as the Streamzap USB PC Remote, as a Human Interface Device (HID) which means some or all of the keys will show up as key strokes as if entered from the physical keyboard. This behavior will present problems if LIRC is to be used to manage the device.

To disable, create the following file and restart X:

/etc/X11/xorg.conf.d/90-streamzap.conf
Section "InputClass"
  Identifier "Ignore Streamzap IR"
  MatchProduct "Streamzap"
  MatchIsKeyboard "true"
  Option "Ignore" "true"
EndSection

Do not forget to alter the MatchProduct property according to one shown in Name from output of

$ cat /proc/bus/input/devices | grep -e IR

For example WinFast for N: Name="cx88 IR (WinFast DTV2000 H rev."

On an ARM device not using Xorg

Blacklist the offending modules by creating /etc/modprobed.d/streamzap.conf to suppress this behavior. An example is provided for the Streamzap remote.

install ir_sharp_decoder /bin/false
install ir_xmp_decoder /bin/false
install ir_rc5_decoder /bin/false
install ir_nec_decoder /bin/false
install ir_sony_decoder /bin/false
install ir_mce_kbd_decoder /bin/false
install ir_jvc_decoder /bin/false
install ir_rc6_decoder /bin/false
install ir_sanyo_decoder /bin/false

Changing default configuration

Users not getting any output from irw may have the default configuration in /etc/lirc/lirc_options.conf incorrectly setup (or might have been overwritten by an update).

First, check if /dev/lirc0 is present:

$ mode2 --driver default --device /dev/lirc0

Watch the output while pressing buttons on the remote. If output is present, edit /etc/lirc/lirc_options.conf changing the driver and device appropriately.

If no output is presented, the task becomes locating the correct driver/device combination. First check what combination lirc detected by default. Run ir-keytable from the v4l-utils package. and check the output. It will look similar to this:

 Found /sys/class/rc/rc0/ (/dev/input/event5) with:
       Driver ite-cir, table rc-rc6-mce
       Supported protocols: unknown other lirc rc-5 jvc sony nec sanyo mce-kbd rc-6 sharp xmp
       Enabled protocols: lirc
       Extra capabilities: <access denied>

In this case, LIRC automatically detected /dev/input/event5 as the IR device, which uses the devinput driver. Check if this combination is working by running:

$ mode2 --driver devinput --device /dev/input/event5

Now try pressing buttons on the remote. If there is no output, try different driver and device combinations. Once a working combination has been identified, change driver and device in /etc/lirc/lirc_options.conf appropriately.

Example

An example configuration for a MCE RC6 compatible receiver:

/etc/lirc/lirc_options.conf
[lircd]
nodaemon        = False
driver          = default
device          = /dev/lirc0
output          = /var/run/lirc/lircd
pidfile         = /var/run/lirc/lircd.pid
plugindir       = /usr/lib/lirc/plugins
permission      = 666
allow-simulate  = No
repeat-max      = 600

[lircmd]
uinput          = False
nodaemon        = False

See also