yuyu01 发表于 2023-8-31 16:03:05

mt3000自编译固件风扇控制分享

本帖最后由 yuyu01 于 2023-8-31 16:30 编辑

入手了mt3000,到手直接刷了自己编译的固件(lede),之后发现风扇总是启动一会,停一会,温度总是停在60左右。推测风扇启动阈值是60度。

折腾了一下,分享一下自己的方案。
风扇控制相关的文件如下:
root@OpenWrt:/sys/devices/virtual/thermal/thermal_zone0# ll
drwxr-xr-x    4 root   root             0 Jan11970 ./
drwxr-xr-x    6 root   root             0 Jan11970 ../
-r--r--r--    1 root   root          4096 Aug 31 15:50 available_policies
lrwxrwxrwx    1 root   root             0 Aug 31 06:01 cdev0 -> ../cooling_device0/
-r--r--r--    1 root   root          4096 Aug 31 15:50 cdev0_trip_point
-rw-r--r--    1 root   root          4096 Aug 31 15:50 cdev0_weight
lrwxrwxrwx    1 root   root             0 Aug 31 15:50 cdev1 -> ../cooling_device0/
-r--r--r--    1 root   root          4096 Aug 31 15:50 cdev1_trip_point
-rw-r--r--    1 root   root          4096 Aug 31 15:50 cdev1_weight
lrwxrwxrwx    1 root   root             0 Aug 31 15:50 cdev2 -> ../cooling_device0/
-r--r--r--    1 root   root          4096 Aug 31 15:50 cdev2_trip_point
-rw-r--r--    1 root   root          4096 Aug 31 15:50 cdev2_weight
drwxr-xr-x    3 root   root             0 Jan11970 hwmon0/
-rw-r--r--    1 root   root          4096 Aug 31 15:50 integral_cutoff
-rw-r--r--    1 root   root          4096 Aug 31 15:50 k_d
-rw-r--r--    1 root   root          4096 Aug 31 15:50 k_i
-rw-r--r--    1 root   root          4096 Aug 31 15:50 k_po
-rw-r--r--    1 root   root          4096 Aug 31 15:50 k_pu
-rw-r--r--    1 root   root          4096 Aug 31 15:50 mode
-rw-r--r--    1 root   root          4096 Aug 31 15:50 offset
-rw-r--r--    1 root   root          4096 Aug 31 15:50 policy
drwxr-xr-x    2 root   root             0 Aug 31 15:50 power/
-rw-r--r--    1 root   root          4096 Aug 31 15:50 slope
lrwxrwxrwx    1 root   root             0 Aug 31 15:50 subsystem -> ../../../../class/thermal/
-rw-r--r--    1 root   root          4096 Aug 31 15:50 sustainable_power
-r--r--r--    1 root   root          4096 Aug 31 06:01 temp
-rw-r--r--    1 root   root          4096 Aug 31 15:50 trip_point_0_hyst
-rw-r--r--    1 root   root          4096 Aug 31 15:50 trip_point_0_temp
-r--r--r--    1 root   root          4096 Aug 31 15:50 trip_point_0_type
-rw-r--r--    1 root   root          4096 Aug 31 15:50 trip_point_1_hyst
-rw-r--r--    1 root   root          4096 Aug 31 15:50 trip_point_1_temp
-r--r--r--    1 root   root          4096 Aug 31 15:50 trip_point_1_type
-rw-r--r--    1 root   root          4096 Aug 31 15:50 trip_point_2_hyst
-rw-r--r--    1 root   root          4096 Aug 31 15:50 trip_point_2_temp
-r--r--r--    1 root   root          4096 Aug 31 15:50 trip_point_2_type
-rw-r--r--    1 root   root          4096 Aug 31 15:50 trip_point_3_hyst
-rw-r--r--    1 root   root          4096 Aug 31 15:50 trip_point_3_temp
-r--r--r--    1 root   root          4096 Aug 31 15:50 trip_point_3_type
-rw-r--r--    1 root   root          4096 Aug 31 15:50 trip_point_4_hyst
-rw-r--r--    1 root   root          4096 Aug 31 12:20 trip_point_4_temp
-r--r--r--    1 root   root          4096 Aug 31 15:50 trip_point_4_type
-r--r--r--    1 root   root          4096 Aug 31 15:50 type
-rw-r--r--    1 root   root          4096 Aug 31 15:50 ueventtrip_point_X_temp:这个是风扇启动几个档位的阈值,trip_point_4_temp是最低档,值为60,说明温度到了60度,触发第一档的风扇开关(后面几档基本用不到,不管)。

所以写了个脚本:# 配置温度   
temp_max=65000
temp_min=55000

# 当前风扇状态
fan_cur_state=$(cat /sys/devices/virtual/thermal/thermal_zone0/cdev0/cur_state)
# 温度阈值路径
temp_point_4=/sys/devices/virtual/thermal/thermal_zone0/trip_point_4_temp
# 温度阈值
temp_point_4_before=$(cat $temp_point_4)
# 当前温度
curr_temp=$(cat /sys/devices/virtual/thermal/thermal_zone0/temp)
# 当前时间
current_time=$(date '+%Y-%m-%d %H:%M:%S')

if [ "$curr_temp" -gt "$temp_max" ]; then

    echo $temp_min > $temp_point_4

    temp_point_4_after=$(cat $temp_point_4)

    echo "current_time:$current_timecurr_temp:$curr_temptemp_point_4:$temp_point_4_before -> $temp_point_4_after" >> /root/temp_control.log
fi

if [ "$curr_temp" -lt "$temp_min" ]; then

    echo $temp_max > $temp_point_4

    temp_point_4_after=$(cat $temp_point_4)

    echo "current_time:$current_timecurr_temp:$curr_temptemp_point_4:$temp_point_4_before -> $temp_point_4_after" >> /root/temp_control.log
fi

temp_point_4_after=$(cat $temp_point_4)
echo "$current_timecur_temp:$curr_temptemp_point4:$temp_point_4_afterfan_cur_state:$fan_cur_state" >> /root/temp.log

添加到计划任务,每分钟执行一次 * * * * * /bin/bash /root/temp_control.sh

大致就是等温度到了65,将阈值设置为55度,风扇启动。温度降到55度之后,再将阈值调回65度,风扇关闭,如此往复。

实测下来,一天之中风扇只会启动几次。
注:本人固件是lede仓库编译的,openwrt应该也兼容,官方固件还没用过,不太清楚官方的风扇策略是怎样的。
注:开机/重启的时候,要将trip_point_4_temp调为55或者65,不然还是会卡在60频繁开关风扇(可以在/etc/init.d/中写个简单服务)。






页: [1]
查看完整版本: mt3000自编译固件风扇控制分享