viernes, 10 de febrero de 2017

Using two irtrans USB devices in one Ubuntu PC.

IRTrans is a little USB device to capture and send IR commands (like a remote control).

The irtrans USB device documentation states that "Individual control of multiple external transmitters is not possible". The reason for that is the provided irtrans server (irserver64) listen to two predefined ports (21000 for the irtrans protocol and 8765 for the lirc protocol). When the second server tries to bind to any of these ports it fails because the ports are already taken.

There is a workaround for this problem using docker containers. The simple idea is, we launch two servers in two separated containers and we configure these with a different IP address.

The first thing we need to do is to install docker in our Ubuntu computer. See here how to do that.

The we need to create our container. In an empty directory we copy:
  •  the irserver64 file. 
  •  the remotes/ directory, containing a number of files with the keypresses of the remotes we want to simulate. 
  • a file called Dockerfile with the following content: 


FROM ubuntu:16.04

RUN mkdir /irtrans
RUN mkdir /irtrans/remotes

COPY irserver64 /irtrans
COPY remotes/file.rem /irtrans/remotes

WORKDIR /irtrans
ENTRYPOINT ["./irserver64"]
From this directory we can compile our container with (irtrans.1 is an arbitrary name we give to our container):

dockebuild -t irtrans.1 .
Then we need to create our docker network.

docker network create --subnet=172.18.0.0/16 mynet123=
And now we can run two containers in different ip addresses. Remember to give the container access to the serial port:

docker run --net mynet123 --ip 172.18.0.22 --device=/dev/ttyUSB0 irtrans.1 /dev/ttyUSB0
docker run --net mynet123 --ip 172.18.0.23 --device=/dev/ttyUSB2 irtrans.1 /dev/ttyUSB2