RK3399 cron job issue at reboot

  • Hi!


    I am not sure if I should post this here or in Armbian's forum as I am not sure to whom this is concerned, but I am hoping to find some guidance on how to address my issue :)


    I have a NanoPi M4 + SATA hat which has a RK3399 processor with Armbian+OMV 4 installed and I want to run a script to turn on a fan connected to the PWM pin when the device is rebooted.


    I have written the following script to turn modulate the PWM pin which basically has the same instructions that the official documentation of my device provides:


    Bash: /sharedfolders/sys/activate_fan.hs
    #!/bin/bash
    echo "Enabling pwmchip1"
    echo 0 > /sys/class/pwm/pwmchip1/export
    echo 0 > /sys/class/pwm/pwmchip1/pwm0/enable
    echo 50000 > /sys/class/pwm/pwmchip1/pwm0/period
    echo 1 > /sys/class/pwm/pwmchip1/pwm0/enable
    echo 45000 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle
    echo "DONE"
    exit 0

    And I am using OMV's "Scheduled Jobs" to tell Cron to run the script at every reboot. These are the settings:


    ENABLED: enabled
    TIME OF EXECUTION: at reboot
    USER: root
    COMMAND: bash /sharedfolders/sys/activate_fan.sh
    SEND EMAIL: disabled
    COMMENT: Enable fan via de PWM pin


    The thing is that sometimes it works and sometimes it doesn't. I don't see anything weird in the Log's and when I setup the job to forward the output vía email, most of the times I get this which has a weird write error, but sometimes I don't and apparently that is not related to the PWM pin being activated or not (that means, even if I don't see the error message, the pin is not activated):


    Enabling pwmchip1
    /sharedfolders/sys/activate_fan.sh: line 3: echo: write error: Device or resource busy
    DONE


    Still, another weird thing happening here is that once the system starts and I log in via SSH as root, if I run the script like:


    bash /sharedfolders/sys/activate_fan.sh


    Always fails and throws the error message like last time. I have to run it several times to get the PWM pin activated and even when the script works, I still get the error message.


    The only way to activate the PWM pin flawlessly is to log in via SSH as root once the system gets running and run the content of the script manually (that is, line by line). That way I still get the error message, but the PWM pin is activated. From this, I can tell that the lines that apparently don't get execute correctly are these:


    echo 0 > /sys/class/pwm/pwmchip1/pwm0/enable


    echo 1 > /sys/class/pwm/pwmchip1/pwm0/enable


    Has anyone encountered a similar problem? Is this related to how OMV runs the scheduled jobs or should I post this on the Armbian forum?


    Thanks!

    • Offizieller Beitrag

    /sharedfolders/sys/activate_fan.sh

    Sharedfolders are not mounted executable. Either put the script somewhere that is executable (like /usr/local/bin/) or change your sharedfolder to be executable (search the forum for that).

    omv 7.0.5-1 sandworm | 64 bit | 6.8 proxmox kernel

    plugins :: omvextrasorg 7.0 | kvm 7.0.13 | compose 7.1.4 | k8s 7.1.0-3 | cputemp 7.0.1 | mergerfs 7.0.4


    omv-extras.org plugins source code and issue tracker - github - changelogs


    Please try ctrl-shift-R and read this before posting a question.

    Please put your OMV system details in your signature.
    Please don't PM for support... Too many PMs!

  • Thanks @ryecoaaron ! Indeed I moved the script to an executable folder and that fixed the error message, the only weird thing is that still the PWM pin was not getting activated and I had to change the order of the script a bit and duplicate a few lines to make it work (there's no particular reason. Just trial and error):


    #!/bin/bash
    echo "Enabling pwmchip1"
    echo 0 > /sys/class/pwm/pwmchip1/export
    echo 50000 > /sys/class/pwm/pwmchip1/pwm0/period
    echo 45000 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle
    echo 1 > /sys/class/pwm/pwmchip1/pwm0/enable
    echo 0 > /sys/class/pwm/pwmchip1/pwm0/enable
    echo 1 > /sys/class/pwm/pwmchip1/pwm0/enable
    echo "DONE"
    exit 0


    But it is working now. Thanks!

  • Stopped working again.


    Well, sometimes it works and sometimes (most of the times) it doesn't. The fan just doesn't turn on and still having the same error:


    line 3: echo: write error: Device or resource busy


    Also worth mentioning that when I log in as root and try to run the script manually, it gives the same result. But if I run directly line by line in the shell, it works.


    Has anyone had a similar issue?

  • So it has been running for around a week with a daily reboot and I think it's safe to say that it is working!


    Maybe you need to add some pause between the lines/commands.sleep 2

    I added the sleep between every command and apparently that did the trick! Plan B (as someone kindly suggested in another conversation) would have been to chain all the script in a single line with ANDs and (lol) ORs to make it fit in the single-lined input box in the OMV GUI, but luckily there was no need to get that dirty.


    Still I have no idea why if I don't echo 1, 0, 1 (in that order) to pwm0/enable it doesn't work, but I am willing to live with it.


    For the curious: when I echo the first 1, nothing happens. Then when I echo 0, the fan starts spinning like full power. Then when I echo 1, it slows down to what I like to think are my period/duty_cycle settings. I think 0 is supposed to turn it off and 1 to turn it on, but ‍♂️

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!