
CPU fan control script for banana-pi-BPI-R4 under immortalwrt firmware
banana-pi-BPI-R4 CPU fan control script under the immortalwrt firmware
The firmware for banana-pi-BPI-R4 provided officially can really be said to be very bad.
Even the basic wget-ssl is not provided. Flash the official openwrt system of banana-pi-BPI-R4.
Even the most basic opkg update cannot be executed.
The reason is that wget-ssl is not installed. The source address needs to be changed to http, and then install wget-ssl.
The official openwrt firmware of banana-pi-BPI-R4 is based on kernel 5.1, and the wifi driver is also closed source.
In addition to a very strong WiFi signal and support for MLO, the official firmware doesn't have much appeal.
The following is a CPU fan control script for banana-pi-BPI-R4 based on immortalwrt24.10.0.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
vi /sbin/fan-speed
#!/bin/sh /etc/rc.common
if [ ! -f /sys/class/pwm/pwmchip0/export ]; then
exit 0
fi
### 导出 PWM 通道 ###
echo 1 > /sys/class/pwm/pwmchip0/export 2>/dev/null
### 检查 PWM 通道是否已导出 ###
if [ -d /sys/class/pwm/pwmchip0/pwm1 ]; then
echo 10000 > /sys/class/pwm/pwmchip0/pwm1/period
echo 7000 > /sys/class/pwm/pwmchip0/pwm1/duty_cycle
echo normal > /sys/class/pwm/pwmchip0/pwm1/polarity
echo 1 > /sys/class/pwm/pwmchip0/pwm1/enable
else
echo "Failed to export PWM channel 1!"
exit 1
fi
### 温度控制循环 ###
while :
do
sleep 20
result=$(cat /sys/class/thermal/thermal_zone0/temp)
temperature=$((result))
if [ ${temperature} -ge 50000 ]; then
echo 5000 > /sys/class/pwm/pwmchip0/pwm1/duty_cycle
fi
if [ ${temperature} -ge 60000 ]; then
echo 1000 > /sys/class/pwm/pwmchip0/pwm1/duty_cycle
fi
if [ ${temperature} -le 48000 ]; then
echo 7000 > /sys/class/pwm/pwmchip0/pwm1/duty_cycle
fi
if [ ${temperature} -le 40000 ]; then
echo 10000 > /sys/class/pwm/pwmchip0/pwm1/duty_cycle
fi
done
startup on boot
vi /etc/rc.local
# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.
fan-speed
exit 0