Remote control for kodi

Having issues with your DietPi installation, or, found a bug? Post it here.
ebohe

Re: Remote control for kodi

Post by ebohe »

Como configurar una tecla de un mando a distancia para abrir el kodi desde la terminal de Linux
Para realizar esta tarea vamos a crear un script python que este escuchando la tecla la cual queremos pulsar para que el realice la apertura de kodi.
Primero utilizamos el comando lsusb para ver que mandos usb tenemos conectados y sobre todo fijarnos el en Id de dicho dispositivo.
Al hacerlo podemos ver el id de nuestro mando en este caso el mío es el Xenta Wireless Receiver con un ID 1d57:ac01

root@DietPi:/# lsusb
Bus 001 Device 005: ID 1d57:ac01 Xenta Wireless Receiver (Keyboard and Mouse)
Bus 001 Device 004: ID 0fe6:9700 Kontron (Industrial Computer Source / ICS Advent) DM9601 Fast Ethernet Adapter
Bus 001 Device 003: ID 24ae:2000
Bus 001 Device 002: ID 1a40:0101 Terminus Technology Inc. 4-Port HUB
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
root@DietPi:/#

Después hacemos un cd /sys/kernel/debug/hid y ahí ejecutamos un ls -l como podemos ver .

root@DietPi:/sys/kernel/debug/hid# ls -l
total 0
drwxr-xr-x 2 root root 0 ene 1 1970 0003:1D57:AC01.0003
drwxr-xr-x 2 root root 0 ene 1 1970 0003:1D57:AC01.0004
drwxr-xr-x 2 root root 0 ene 1 1970 0003:24AE:2000.0001
drwxr-xr-x 2 root root 0 ene 1 1970 0003:24AE:2000.0002
root@DietPi:/sys/kernel/debug/hid#

Ahí vemos 4 carpetas y si nos fijamos las dos primeras contienen el ID de nuestro mando, yo entre en la primera de ellas no sé porque será por empezar por el principio. Ahí volví a ejecutar el comando ls-l y podemos ver dos archivos.

root@DietPi:/sys/kernel/debug/hid# cd 0003\:1D57\:AC01.0003/
root@DietPi:/sys/kernel/debug/hid/0003:1D57:AC01.0003# ls -l
total 0
-r-------- 1 root root 0 ene 1 1970 events
-r-------- 1 root root 0 ene 1 1970 rdesc
root@DietPi:/sys/kernel/debug/hid/0003:1D57:AC01.0003#

Vale pues si ahora hacemos un cat events el sistema se queda a la escucha para que pulsemos un botón de nuestro mando a distancia. Pulsamos la tecla a la cual le queremos dar la función para que abra nuestro kodi, si utilizamos el mando para más tareas sería bueno que eligiéramos un botón que no esté asignado a ninguna función.
Al pulsar el botón nos sale por pantalla unos códigos en mi caso estos:

report (size 8) (unnumbered) = 0c 00 28 00 00 00 00 00
Keyboard.00e0 = 0
Keyboard.00e1 = 0
Keyboard.00e2 = 1
Keyboard.00e3 = 1
Keyboard.00e4 = 0
Keyboard.00e5 = 0
Keyboard.00e6 = 0
Keyboard.00e7 = 0
Keyboard.0028 = 1

report (size 8) (unnumbered) = 00 00 00 00 00 00 00 00
Keyboard.00e0 = 0
Keyboard.00e1 = 0
Keyboard.00e2 = 0
Keyboard.00e3 = 0
Keyboard.00e4 = 0
Keyboard.00e5 = 0
Keyboard.00e6 = 0
Keyboard.00e7 = 0
Keyboard.0028 = 0

Ahí copie los códigos y me fije cuales son igual a 1 (Keyboard.00e2 = 1 Keyboard.00e3 = 1 Keyboard.0028 = 1) yo no sé porque razón cogí el ultimo código es decir el Keyboard.0028 = 1 y fue el que utilice el en código python.
Para crear el código python puse en pantalla nano kodi.py (yo utilizo nano porque me gusta más pero pueden utilizar el que más les guste) y ahí copie el siguiente código.

#!/usr/bin/python

import sys
import subprocess

x='si'

while x=='si':
tecla = sys.stdin.read(1)
subprocess.call('kodi', shell=True)
print 'Has presionado ', tecla
if tecla=='Keyboard.0028':
x='no'

Bueno pues por ahora eso es todo lo que he realizado y ya funciona al apretar el botón que yo deseo se abre el kodi.
No sé si hay alguna manera de optimizar mejor la función se aceptan sugerencias y también me gustaría convertir ese código python en un servicio con lo cual espero que estoy sirva para otros que tengan mí mismo problema y que alguna alma caritativa me siga ayudando.

How to configure a key on a remote control to open the kodi from the Linux terminal
To perform this task we will create a python script that is listening to the key which we want to press for the kodi opening.
First we use the lsusb command to see which usb commands we have connected and above all to set the in Id of that device.
When doing so we can see the id of our command in this case mine is the Xenta Wireless Receiver with an ID 1d57: ac01

root @ DietPi: / # lsusb
Bus 001 Device 005: ID 1d57: ac01 Xenta Wireless Receiver (Keyboard and Mouse)
Bus 001 Device 004: ID 0fe6: 9700 Kontron (Industrial Computer Source / ICS Advent) DM9601 Fast Ethernet Adapter
Bus 001 Device 003: ID 24ae: 2000
Bus 001 Device 002: ID 1a40: 0101 Terminus Technology Inc. 4-Port HUB
Bus 001 Device 001: ID 1d6b: 0002 Linux Foundation 2.0 root hub
root @ DietPi: / #

Then we make a cd / sys / kernel / debug / hid and there we execute an ls -l as we can see.

root @ DietPi: / sys / kernel / debug / hid # ls -l
Total 0
drwxr-xr-x 2 root root 0 Jan 1 1970 0003: 1D57: AC01.0003
drwxr-xr-x 2 root root 0 Jan 1 1970 0003: 1D57: AC01.0004
drwxr-xr-x 2 root root 0 Jan 1 1970 0003: 24AE: 2000,0001
drwxr-xr-x 2 root root 0 Jan 1 1970 0003: 24AE: 2000,0002
root @ DietPi: / sys / kernel / debug / hid #

There we see 4 folders and if we look at the first two contain the ID of our command, I enter the first one I do not know because it will be to start at the beginning. There I ran the command ls-l again and we can see two files.

root @ DietPi: / sys / kernel / debug / hid # cd 0003 \: 1D57 \: AC01.0003 /
root @ DietPi: / sys / kernel / debug / hid / 0003: 1D57: AC01.0003 # ls -l
Total 0
-r -------- 1 root root 0 Jan 1 1970 events
-r -------- 1 root root 0 Jan 1 1970 rdesc
root @ DietPi: / sys / kernel / debug / hid / 0003: 1D57: AC01.0003 #

Okay, so if we do a cat events now, the system stays listening so we can press a button on our remote control. Press the key to which we want to give the function to open our kodi, if we use the command for more tasks it would be good to choose a button that is not assigned to any function.
When the button is pressed, a few codes appear in my case:

report (size 8) (unnumbered) = 0c 00 28 00 00 00 00 00
Keyboard.00e0 = 0
Keyboard.00e1 = 0
Keyboard.00e2 = 1
Keyboard.00e3 = 1
Keyboard.00e4 = 0
Keyboard.00e5 = 0
Keyboard.00e6 = 0
Keyboard.00e7 = 0
Keyboard.0028 = 1

report (size 8) (unnumbered) = 00 00 00 00 00 00 00 00 00
Keyboard.00e0 = 0
Keyboard.00e1 = 0
Keyboard.00e2 = 0
Keyboard.00e3 = 0
Keyboard.00e4 = 0
Keyboard.00e5 = 0
Keyboard.00e6 = 0
Keyboard.00e7 = 0
Keyboard.0028 = 0

There I copied the codes and I fixed which are equal to 1 (Keyboard.00e2 = 1 Keyboard.00e3 = 1 Keyboard.0028 = 1) I do not know why I took the last code ie Keyboard.0028 = 1 and it was the one use the in python code.
To create the python code I put on screen nano kodi.py (I use nano because I like more but can use the one that they like) and there copy the following code.

#! / usr / bin / python

import sys
import subprocess

x = 'yes'

while x == 'yes':
    key = sys.stdin.read (1)
    subprocess.call ('kodi', shell = True)
    print 'Press' key
    if key == 'Keyboard.0028':
        x = 'no'

Well, for now that's all I've done and it works by pressing the button I want the kodi to open.
I do not know if there is any way to better optimize the function I accept suggestions and I would also like to convert that python code into a service with which I hope I am useful to others who have myself problem and that some charitable soul will continue to help me.
Sorry for my English as a translator for Google, so I put it in Spanish first if someone understands me better.
Post Reply