Incompatible CPU Fan Script

I just migrated from Hamvoip to ASL 3. The Hamvoip script I used, to control the CPU fan, doesn't work with ASL 3. I did do some research, along with some trial and error, for a couple of hours, I guess it's time to admit defeat. Would someone please be kind enough to help me modify this script, to work with ASL 3?

#!/bin/bash
ontemp=48
gpio -g mode 3 out
temp=$(vcgencmd measure_temp | egrep -o '[0-9].[0-9]')
echo $temp #use BCM pin 3, as pin 2 is used for PSU control
temp0=${temp%.*}
echo $temp0

if [ $temp0 -gt $ontemp ]
then
echo greater than $ontemp fan on
gpio -g write 3 1
else
echo less than or equal to $ontemp fan off
gpio -g write 3 0
fi

This is probably a permission issue as ASL3 runs as an asterisk user.
Check that your script will run as the asterisk user
sudo -u asterisk <script>

1 Like

On addition to the above, you can change the permissions of the script with

sudo chown asterisk:asterisk /full/path/of/script

Did it transfer as executable? If not, make it executable with

sudo chmod +x /full/path/of/script

What happens if you just call the script from the command line? Do you get any errors?

sudo ./temp-fan.sh
./temp-fan.sh: line 3: gpio: command not found
60.1
60
greater than 48 fan on
./temp-fan.sh: line 12: gpio: command not found

I suspected this. The script is written to use a command called gpio but I could not find that command on my system, nor could I find any Debian 12 package that supplies that command, so there doesn't seem to be a replacemetn for it.

In order to get this script to work, you will have to find a different tool that does the same thing that the gpio tool was doing. It looks like this might help you: How to Install and Use pigpio for GPIO Control on Raspberry Pi – TheLinuxCode

You would need to run pigpiod as a system service, and then modify your script to change gpio -g write 3 1 to probably look like pigs w 3 1. This is just a guess as I have not tried it.

On my RPi I appear to have the gpiod package installed. That package looks to provide a number of commands. You can use man -k gpio to see the related "man" pages ... and then man <page-of-interest> for more info.

Thanks to everyone who tried to help. I finally managed to get the fan working through a python script I found on Github. The Rasperry Pi OS has a built in fan control but for whatever reason it was removed from this particular distro.

If it's something packaged with stock Raspberry Pi OS, it's simply a matter of doing apt install for the package you seek. It's likely just not installed by default in the "lite" image that is the basis of the ASL3 Pi Appliance image.