N1200 And N2100 Fan Control Script

From NAS-Central Thecus Wiki
Jump to: navigation, search
Fan.gif

Information

The Thecus N1200 and N2100 have the same fan controller, a Fintek F75375. Below is an adapted version of the script commonly used on the N2100. Copy the file contents and paste them into a file, make it executable and ensure it is launched by one of your init scripts when your device boots.

You will only need this script if you are running custom firmware for your device, for example Gentoo or Ubuntu. If you are using the Thecus firmware and kernel then you do not need this. If you are using foonas it should be included already.

Installation

First copy and paste the script below into /usr/sbin/temper, then make sure it is executable:

chmod 755 /usr/sbin/temper

Now follow the instructions for your distribution below.

Gentoo

Edit /etc/conf.d/local.start in your favorite editor and the following to the bottom of the file:

temper &>/dev/null &

Ubuntu

Script

#!/bin/sh
# /usr/sbin/temper - N1200 and N2100 automatic fan control and logger

# Fan controller
F75375=`find /sys -name 0-002e | grep i2c-0`
# Chip temperature values and maximum allowed temperature
CHIPS=$F75375/temp?_input
TC_MAX=55

# Disk devices and maximum allowed temperature
DISKS=/dev/sd?
TD_MAX=55

# Fan device, lowest PWM value and control range
FAN=$F75375/pwm1
FAN_MIN=0
FAN_RNG=140

TMP_MIN=30

# logging interval, in minutes
LOG=1

# Disable PWM1 output
PWM1=$F75375/pwm1

# Enable the fan
echo 1 > $F75375/pwm1_enable

echo $$ > /var/run/temper.pid

while true ; do
i=0
while [ $i -lt $LOG ] ; do
   i=$(($i+1))
   # read the disk temperatures every minute
   TD=0
   for D in $DISKS ; do
      t=$(hddtemp -q -n $D)
      if [ $t -gt $TD ] ; then
         TD=$t
      fi
   done

   j=0
   while [ $j -lt 6 ] ; do
      j=$(($j+1))
      # read the chip temperatures every 10 seconds
      TC=0
      for C in $CHIPS ; do
         t=$(($(cat $C)/1000))
         if [ $t -gt $TC ] && [ $t -lt 255 ]; then
            TC=$t
         fi
      done

      FC=$(((($TC-$TMP_MIN)*$FAN_RNG)/($TC_MAX-$TMP_MIN)+$FAN_MIN))

      if [ $TC -gt $TC_MAX ] ; then
         FC=255
      elif [ $FC -gt $(($FAN_MIN+$FAN_RNG)) ] ; then
         FC=$FAN_MAX
      elif [ $FC -lt $FAN_MIN ] ; then
         FC=$FAN_MIN
      fi

      FD=$(((($TD-$TMP_MIN)*$FAN_RNG)/($TD_MAX-$TMP_MIN)+$FAN_MIN))

      if [ $TD -gt $TD_MAX ] ; then
         FD=255
      elif [ $FD -gt $(($FAN_MIN+$FAN_RNG)) ] ; then
         FD=$FAN_MAX
      elif [ $FD -lt $FAN_MIN ] ; then
         FD=$FAN_MIN
      fi

      if [ $FC -gt $FD ] ; then
         F=$FC
      else
         F=$FD
      fi

      if [ "$1" = "-m" ] ; then
         echo "chips $TC disks $TD -> fan $F"
         exit 0
      fi
      echo $F >$FAN
      # echo 0  >$PWM1

      sleep 10
   done

done

logger -p daemon.notice $0 "chips $TC disks $TD -> fan $F"

done

# EOF