[RPi4, LE12.0.1] Autostart.sh with python script for fan control won't work

  • Hey everyone ! Hope you are well !^^

    I am trying to have a fan control script working at startup. I have a Pi 4 with Libreelec 12.0.1 freshly installed with RPi tools addon. Fan is controlled by PWM on PIN 18.

    The control script runs well when I use the command: python /storage/fan_control.py

    I have created an autostart.sh file and it also works (fan is controlled) when I execute sh /storage/.config/autostart.sh

    When I boot the Raspberry, the fan is always running at full speed which means the python script isn't launched.

    Here is the result of systemctl status kodi-autostart.service:

    I have tried to increase the sleep delay in autostart.sh to 60 and 120 but it does not make any difference.

    Any idea ? :blush:

  • It works !!!! Thank you so much HarryH :D


    For those who wants details, here is the content of fan_control.py:


    Here is the content of autostart.sh:

    Bash
    #!/bin/bash
    (
    sleep 180
    sh /storage/.config/fan_control.sh start
    )&


    Here is the content of fan_control.sh:

  • Hello all,

    I have written a service addon that covers partial code from here. The idea behind the development of a service addon is that it is easy to use, no further scripts are required and it runs ootB. The addon is now part of the Kodinerds repo, the source code you'll find on github: https://github.com/b-jesch/service.joy-it.fancontrol. The addon is primary written for the Joy-IT Multimedia case but runs with other cases and integrated fans connected to GPIO17 too.

    Anyway: While this service addon runs perfect in normal circumstances, it throws an exception when the addon is disabled and enabled again by the user in addon settings.

    Why it's throwing "GPIO busy"? Normally all GPIO should be unlocked (closed) by gpiozero when the service finished - and it does so.

  • Code
    2024-10-06 15:32:15.351 T:1041    debug <general>: CPythonInvoker(1, /storage/.kodi/addons/service.joy-it.fancontrol/fan.py): trigger Monitor abort request
    2024-10-06 15:32:15.352 T:939      info <general>: [Joy-IT Fan Controller 1.0.9] Joy-IT fan control service finished
    2024-10-06 15:32:15.352 T:939     debug <general>: CPythonInvoker(1, /storage/.kodi/addons/service.joy-it.fancontrol/fan.py): script successfully run
    2024-10-06 15:32:15.352 T:939      info <general>: CPythonInvoker(1, /storage/.kodi/addons/service.joy-it.fancontrol/fan.py): waiting on thread 1496097344
    2024-10-06 15:32:20.359 T:1041    error <general>: CPythonInvoker(1, /storage/.kodi/addons/service.joy-it.fancontrol/fan.py): script didn't stop in 5 seconds - let's kill it

    _PvD Guess without any knowledge about gpiozero: GPIO "resource" is not freed because thread is killed instead of terminated gracefully.

  • A new version of the service addon is using lgpio instead gpiozero. This avoids the 'GPIO busy' exception now. Thank you for pointing me in the right direction.