script wont run via kodi

  • Hi

    I am trying to run a script from a remote control button press, I have tested with 2 python scripts on 2 different buttons and switched them over when testing, either button will only run one of the scripts.

    The script that wont run is using UART on /dev/ttyS0 and originally Python CLI wouldn't run it as it was in dialout group, quick chown and it ran in Python and the terminal with no problem, after rebooting the permissions have reverted back to root:dialout

    Code
    LibreELEC:/dev # ls -la ttyS0  
    crw-rw----    1 root     dialout     4,  64 Jan 14 20:01 ttyS0

    How do i change it permanently so root can run from the terminal if needed and kodi can run it via the button press?

    Code
    System.Exec("/storage/myscript.py")
  • Thanks Da Flex it didn't make any difference, its driving me nuts now as it turns out with or without the UDEV rule the script runs fine from the terminal as the root user, works exactly as expected first time every time its ran. But will not run from the button press even though kodi sees the key press and attempts to run it.

    Code
    2021-01-14 23:38:33.399 T:3011923984   DEBUG: HandleKey: 202 (0xca, obc53) pressed, action is System.Exec("/storage/myscript.py")

    Things just got weirder, Finally got it working by replacing System.Exec("/storage/myscript.py") with RunScript("/storage/myscript.py")

    but it will only run once or twice then it stops working, then running it from the terminal does not work either, reboot and same again 1-2 work then non responsive in terminal.

    but if i reboot and don't do the button press i can run it a dozen times in the terminal and it works every time.

    Edited once, last by Veedub (January 15, 2021 at 12:44 AM).

  • Did you also try to run myscript.sh containing python myscript.py inside to test if there's a same issue?

    The another solution perhaps could be to run the python script permanently, sniffing for the commands which you could put somewhere by another script invoked by button...

  • If you run that script as root, it does not matter what permissions are set on device. You got rw permissions as owner. If you face permission problem in /dev/, you should understand why permissions are causing the problem and fix that instead of changing permissions on devfs.

  • Did you also try to run myscript.sh containing python myscript.py inside to test if there's a same issue?

    The another solution perhaps could be to run the python script permanently, sniffing for the commands which you could put somewhere by another script invoked by button...

    Yeah I tried that but no joy same result as running the .py script. Good shout on the sniffing though I might look into that later see if i can figure something out that way.

    If you run that script as root, it does not matter what permissions are set on device. You got rw permissions as owner. If you face permission problem in /dev/, you should understand why permissions are causing the problem and fix that instead of changing permissions on devfs.

    Yeah I was wondering about that initially but realised that root could run it regardless shortly after, Do you know what user kodi runs as?

  • That's what i thought, thanks for the input, looks like a bit of refactoring is required ^^

    Update:

    Turns out there was a few reasons for above to happen, with using serial UART the ser.close() was causing the script to fail as I had it in a for block rather than at the end of the file and also the USB capture device, when in use was playing havoc with the IR receiver so it would appear this also applies to the Pi4 Infra-Red Remotes - LibreELEC.wiki

    As the system looks like its not responding when pressing the button on the remote but if controlled via web remote it operates normally.

    Least I got to the bottom of it, Just need to find a USB Ir-receiver instead of GPIO receiver

    Edited once, last by Veedub (January 15, 2021 at 8:03 PM).

  • Just to throw this out there as a possible solution and even a mention of some sort on the remote sections of the Wiki - The Ardruino microcontrollers with the ATmega32u4 chip get recognised as USB keyboards so very easy to pick one up cheaply and convert your current GPIO IR-Receiver to USB,

    lots of support for Ir-Receiver libraries for ardruino and plenty of guides and code on github to map remote buttons then remap them via the keyboard.xml file

    Effectively giving the same outcome as Flirc device