Setup LIRC bridge

Hi,

I have a Raspberry Pi 3+ (OpenHab Server) and a Raspberry Pi Zero WH (My Bridge/LIRC-System).
I want to control the Bridge from my OpenHab System. Regarding the Documentation at https://www.openhab.org/addons/bindings/lirc/ this is possible.
When I connect using telnet to my Bridge on my configured Port 8700, the connection is established and stays open. So I guess the Raspi Zero is listening on port 8700.
I installed the LIRC Binding on the OpenHab Server and created a lirc.things in the things-directory with this content:

Bridge lirc:bridge:local [ host="192.168.0.145", port="8700" ] {
    Thing remote Logtech_Audio [ remote="Logitech_Audio" ]
}

When I take a look at the logs of OpenHab (log:tail), I see the following error:

20:12:12.630 [ERROR] [inding.lirc.handler.LIRCBridgeHandler] - Connection to LIRC failed
java.net.ConnectException: Connection refused
[...]

So the question is: What I did wrong or what is not working?
If it will not run using the binding, I will try to use lirc by using SSH directly but I like to use what is already in place before reinventing the wheel.

How did you configure that port?
Lirc listens on port 8765 by default did you try that?

From the docs:

LIRC must be started with TCP enabled. On systemd based systems, TCP can be enabled by editing the file /usr/lib/systemd/system/lirc.service and adding --listen to the end of the ExecStart line. An example systemd service file for LIRC is shown below.

[Unit]
Description=Linux Infrared Remote Control
After=network.target

[Service]
RuntimeDirectory=lirc
ExecStart=/usr/sbin/lircd --nodaemon --driver=default --device=/dev/lirc0 --listen

[Install]
WantedBy=multi-user.target

By default, LIRC will listen on IP address 0.0.0.0 (any available IP address) and port 8765. If you would rather run LIRC on a specific port or IP address, you can use --listen=192.168.1.100:9001 instead.

The port is configured in one of the configs at /etc/lirc. In the line that starts with “listen” or “listener”. (I don’t have access to the system right now).
The files mentioned in the doc doesn’t exist, so I cannot configure it. But the telnet connection acts different on port 8700 than on others so there is something at that port.

You need to create it

Hi,
I used this guide (with the the modifications that are commented below by me) to install my bridge and lirc. It is currently offline but maybe it comes back:
https://itquickie.de/raspberry-pi-infrarot-sender-und-empfaenger-ueber-ccu2-nutzen

I know that there is already a service, because I start lirc with “sudo systemctl start lircd”. Is this using systemd so the config I have to create (and also the “system”-folder in the systemd directory) will be effective? I am using Raspian on the RaspberryPis.
Now I am at home, so my complete config in the /etc/lirc/lirc_options.conf-file is:

[lircd]
nodaemon        = False
#driver          = devinput
#device          = auto
driver		= default
device		= /dev/lirc0
output          = /var/run/lirc/lircd
pidfile         = /var/run/lirc/lircd.pid
plugindir       = /usr/lib/arm-linux-gnueabihf/lirc/plugins
permission      = 666
allow-simulate  = No
repeat-max      = 600
#effective-user =
listen         = 0.0.0.0:8700
#connect        = host[:port]
#loglevel       = 6
#uinput         = ...
#release        = ...
#logfile        = ...

[lircmd]
uinput          = False
nodaemon        = False

There is already the statement for the listener parameter. So why do I have to define it again in the service config file?

Edit: I found my comment of the linked guide above on my local PC how I setup the software part (in German). That also means, that the listener configuration is the default for the current lirc version! So here it is:

Dies gilt fĂĽr: Raspbian Stretch und Lirc 0.9.4c-9
1. sudo apt-get install lirc
2. Zu /etc/modules folgendes hinzufĂĽgen:
lirc_dev
lirc_rpi gpio_in_pin=18 gpio_out_pin=17
3. Die Datei /etc/lirc/hardware.conf anlegen und mit folgendem Inhalt fĂĽllen:
LIRCD_ARGS="--uinput"
LOAD_MODULES=true
DRIVER="default"
DEVICE="/dev/lirc0"
MODULES="lirc_rpi"
4. Folgende Datei in /boot/config.txt hinzufĂĽgen (oder wenn dtoverlay bereits existiert, die Parameter hinzufĂĽgen)
dtoverlay=lirc-rpi,gpio_in_pin=18,gpio_out_pin=17
5. In der /etc/lirc/lirc_options.conf die Zeilen beginnend mit driver und device wie folgt ändern:
driver    = default
device    = /dev/lirc0
6. Neustarten

[...]
Starten: sudo systemctl start lircd
Stoppen: sudo systemctl stop lircd
[...]

No, if the file doesn’t exist at the location in the documentation it means that your Linux distro stores the file in another location. On Debian based systems this appears to be in /lib/systemd/system/lircd.service.

All right.
I modified the existing file in /lib/systemd/system/lircd.service and rebooted the Raspi. The file looks like this now:

[Unit]
Documentation=man:lircd(8)
Documentation=http://lirc.org/html/configure.html
Description=Flexible IR remote input/output application support
Wants=lircd-setup.service
After=network.target lircd-setup.service

[Service]
Type=simple
; ExecStart=/usr/sbin/lircd --nodaemon
RuntimeDirectory=lirc
ExecStart=/usr/sbin/lircd --nodaemon --driver=default --device=/dev/lirc0 --listen=0.0.0.0:8700
; User=lirc
; Group=lirc

; Hardening opts, see systemd.exec(5). Doesn't add much unless
; not running as root.
;
; # Required for dropping privileges in --effective-user.
; CapabilityBoundingSet=CAP_SETEUID
; MemoryDenyWriteExecute=true
; NoNewPrivileges=true
; PrivateTmp=true
; ProtectHome=true
; ProtectSystem=full

[Install]
WantedBy=multi-user.target

The error is still the same like mentioned in my first post.

Hi,

after I get a little bit more into touch with Linux and had some time today, I start to work on my issue above.
I think that lirc has a new version, that is different at some basic parts. i.e. it is not using systemd anymore but systemctl.

I figured out, that my telnet-session on my custom port is working. When I connect via Telnet and type an “a” and execute “systemctl status lircd.service” on my lirc-device, I see the following in the logs:

Sep 23 09:09:17 raspberrypi lircd[467]: lircd-0.9.4c[467]: Notice: accepted new client from 192.168.0.25
Sep 23 09:09:17 raspberrypi lircd-0.9.4c[467]: Notice: accepted new client from 192.168.0.25
Sep 23 09:09:20 raspberrypi lircd[467]: lircd-0.9.4c[467]: Error: bad send packet: "a"
Sep 23 09:09:20 raspberrypi lircd-0.9.4c[467]: Error: bad send packet: "a"
Sep 23 09:09:20 raspberrypi lircd[467]: lircd-0.9.4c[467]: Info: removed client
Sep 23 09:09:20 raspberrypi lircd-0.9.4c[467]: Info: removed client

That means: The config was read successful and my custom port is working in general.
I checked the services (command “systemctl”) and see three running lirc-services:
lircd-uinput.service
lircd.service
lircmd.service

So at this point I assume, that lirc on my remote-device is configured correctly.
My next step was, that I investigated the traffic that is send from my OpenHab to my RemoteRaspberry. I installed tcpdump and checked the traffic. And voila, here is the problem:

pi@raspberrypi:~ $ sudo tcpdump -i wlan0 src 192.168.0.126
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on wlan0, link-type EN10MB (Ethernet), capture size 262144 bytes
09:37:28.208897 IP raspberryOpenHab.fritz.box.39778 > raspberrypi.fritz.box.8765: Flags [S], seq 472628587, win 29200, options [mss 1460,sackOK,TS val 1802440188 ecr 0,nop,wscale 7], length 0

In the 4th line you see that the OpenHab Binding seems to use the default Port 8765 instead of my custom port 8700. I checked the documentation of the binding and my config again. This seems to be correct. I put a config-file in the things-folder with the following content:

Bridge lirc:bridge:local [ host="192.168.0.145", port="8700" ] {
    Thing remote Logitech_AudioSystem [ remote="Logitech_AudioSystem" ]
}

I cannot find the source code of the lirc-binding somewhere to check this. Does anybody know where it is?
Beside of this: am I doing anything else wrong?

Edit:
After I changed my port from 8700 to the default 8765 the binding instantly found my lirc-remotes. It seems to be “only” the port configuration issue.

It looks like the documentation needs to be updated. The config value is named portNumber, not port.

So you’ll want to update your .thing file to look like this:

Bridge lirc:bridge:local [ host="192.168.0.145", portNumber="8700" ] {
    Thing remote Logitech_AudioSystem [ remote="Logitech_AudioSystem" ]
}

The LIRC binding is part of the Ecplise Smarthome project that OpenHAB uses, instead than being an OpenHAB binding itself. The source is at https://github.com/eclipse/smarthome/tree/master/extensions/binding/org.eclipse.smarthome.binding.lirc

1 Like