Logread, sbin/fan_ctrl.sh, wrt1900ac, dc502wrt

Using dc502wrt.org version:

uname -a
Linux OpenWrt 4.19.81 #0 SMP Sun Nov 3 19:25:07 2019 armv7l GNU/Linux.

/sbin/fan_ctrl.sh litters the system log with lots of messages like this:

----------------- Example of message, one every 5 minutes ----------------
Nov 29 15:45:00 2019 cron.err crond[2687]: USER root pid 14090 cmd /sbin/fan_ctrl.sh

Running the script in verbose mode produces this:

+ . /sbin/fan_ctrl.sh
#!/bin/sh

CPU_TEMP=$(cut -c1-2 /sys/class/hwmon/hwmon2/temp1_input)
+ cut -c1-2 /sys/class/hwmon/hwmon2/temp1_input
+ CPU_TEMP=70
DDR_TEMP=$(cut -c1-2 /sys/class/hwmon/hwmon1/temp1_input)
+ cut -c1-2 /sys/class/hwmon/hwmon1/temp1_input
+ DDR_TEMP=55
WIFI_TEMP=$(cut -c1-2 /sys/class/hwmon/hwmon1/temp2_input)
+ cut -c1-2 /sys/class/hwmon/hwmon1/temp2_input
+ WIFI_TEMP=55

CPU_LOW=85
+ CPU_LOW=85
CPU_HIGH=95
+ CPU_HIGH=95
DDR_LOW=65
+ DDR_LOW=65
DDR_HIGH=75
+ DDR_HIGH=75
WIFI_LOW=100
+ WIFI_LOW=100
WIFI_HIGH=115
+ WIFI_HIGH=115

if [ -d /sys/devices/pwm_fan ];then
        FAN_CTRL=/sys/devices/pwm_fan/hwmon/hwmon0/pwm1
elif [ -d /sys/devices/platform/pwm_fan ];then
        FAN_CTRL=/sys/devices/platform/pwm_fan/hwmon/hwmon0/pwm1
else
        exit 0
fi
+ '[' -d /sys/devices/pwm_fan ]
+ '[' -d /sys/devices/platform/pwm_fan ]
+ FAN_CTRL=/sys/devices/platform/pwm_fan/hwmon/hwmon0/pwm1

if [ "$CPU_TEMP" -ge "$CPU_HIGH" -o "$DDR_TEMP" -ge "$DDR_HIGH" -o "$WIFI_TEMP" -ge "$WIFI_HIGH" ];then
        echo "255" > $FAN_CTRL
elif [ "$CPU_TEMP" -ge "$CPU_LOW" -o "$DDR_TEMP" -ge "$DDR_LOW" -o "$WIFI_TEMP" -ge "$WIFI_LOW" ];then
        echo "100" > $FAN_CTRL
else
        echo "0" > $FAN_CTRL
fi
+ '[' 70 -ge 95 -o 55 -ge 75 -o 55 -ge 115 ]
+ '[' 70 -ge 85 -o 55 -ge 65 -o 55 -ge 100 ]
+ echo 0

Looking at my wrt 1900, through the holes/perforations on the top, it appears to have a fan.

Possible concerns:

  1. If a fan action is not required, could the script do an "exit 0" instead of trying to "echo "0" > "The Device"". Why? I suspect the "hardware" is modulating fan speed to control temperature. It appears the script might be trying to turn the fan "off" instead of letting the "hardware" continue with whatever it is trying to do.
  2. It appears that when the script determines it does not need to "correct" fan speed it is generating unnecessary messages in the system log.

If interested, here is a procd replacement for the cron job:

Place in /etc/init.d/fan_control

Summary
#!/bin/sh /etc/rc.common
# Copyright (C) 2016-2017 LEDE-Project.org

START=65
STOP=80
USE_PROCD=1
#PROCD_DEBUG=1

boot() {
. /lib/functions.sh

board=$(board_name)

case "$board" in
linksys,mamba)
    rc_procd start_service
    ;;
esac
}

start_service() {
    procd_open_instance
    procd_set_param command /usr/sbin/fan_monitor -b -a
    procd_set_param stdout 1
    procd_set_param stderr 1
    procd_close_instance
}

and in /usr/sbin/fan_monitor

Summary
#!/bin/sh

# put in /usr/sbin/fan_monitor
# fan_monitor
# Utility script to monitor temperatures and run fan at 50%/75%/100%
# For Reference the original Belkin specs.

INTERVAL=20  # sleep time in seconds between temp check
FANLOW=127   # low fan speed, set to 0 for off
FANMID=191   # mid fan speed
FANHI=255    # high fan speed

# Set fan to 100% on >= these temperatures
#CPU_HI=80000    # Belkin default is 85
#DDR_HI=58000    # Belkin default is 65
#WIFI_HI=75000   # Belkin default is 105

# Set fan to 75% <= these, otherwise 100% 
CPU_MID=80000     # Belkin sets no default
DDR_MID=58000     # Belkin sets no default
WIFI_MID=75000    # Belkin sets no default

# Set fan to 50% <= these temperatures
CPU_LOW=72000     # Belkin default is 80
DDR_LOW=52000     # Belkin default is 60
WIFI_LOW=55000    # Belkin default is 100

cur_pwm=0
new_pwm="$FANHI"  # start fan at HI while coming up

fan_set() {
    local ppwm
    cur_pwm=$1

    if [ "$1" -eq $FANLOW ]; then
        ppwm="50%"
    elif [ "$1" -eq $FANMID ]; then
        ppwm="75%"
    else
        ppwm="100%"
    fi

    logger -t FAN_MONITOR "Setting Fan to $ppwm"
    echo "$1" > /sys/devices/platform/pwm_fan/hwmon/hwmon0/pwm1
}

# Crank fan on exit
trap "{ logger -t FAN_MONITOR Fan monitor exiting; fan_set $FANHI; logger -t FAN_MONITOR as a precaution; exit; }" SIGINT SIGTERM

# Main fan control loop
while :
do
    if [ "$new_pwm" -ne "$cur_pwm" ]
    then
        fan_set "$new_pwm"
    fi
    sleep $INTERVAL

    cpu=`cat /sys/class/hwmon/hwmon2/temp1_input`
    ddr=`cat /sys/class/hwmon/hwmon1/temp1_input`
    wifi=`cat /sys/class/hwmon/hwmon1/temp2_input`

    if [ "$cpu" -le $CPU_LOW -a "$ddr" -le $DDR_LOW -a "$wifi" -le $WIFI_LOW ]
    then
        new_pwm="$FANLOW"
    elif [ "$cpu" -le $CPU_MID -a "$ddr" -le $DDR_MID -a "$wifi" -le $WIFI_MID ]
    then
        new_pwm="$FANMID"
    else
        new_pwm="$FANHI"
    fi
done

comment out the fan job in your crontab file, and enable /etc/init.d/fan_control enable; imo better than the other.

Keep meaning to update my github, but sloth gets the better of me

anomeome, Thank you for using some of your time to respond. I did a "first pass" read of the suggestions. First impression. There is more knowledge in the scripts. I need to read /lib/functions.sh and understand $(board_name). Not understanding the Arm processor features and how a "system fan" is supposed to be controlled leads to some "I want to understand more". I will give your suggestions a try, first by "testing/running" each script in verbose mode and then making them part of my configuration. I think I see a fan, but based on what the present script is doing, I am not sure it ever changes fan behavior. I will try using the Main Fan Control Loop to force the fan into HIGH SPEED. Hopefully I will be able to feel the air flow or hear the fan.