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:
#!/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!