DSM-G600, DNS-3xx and NSA-220 Hack Forum

Unfortunately no one can be told what fun_plug is - you have to see it for yourself.

You are not logged in.

Announcement

#1 2010-04-27 23:02:35

getik
New member
Registered: 2010-04-27
Posts: 2

Fan control DNS-323 revision C1 (or DNS-321?)

Excuse if this has been covered, but I've searched the forum/wiki and haven't found an answer, only the same question...

It appears as if the C1 revision uses a different fan control chip than the older hardware versions and not the fanctl binary or any of the control scripts appear to work.

The reason being that fanspeed does not accept RPM values, but only h, l or s for high, low or stop speeds.  (Possibly the same as for the DNS-321?)

I'm going to try and brush up my non-existing scripting skills and see if I can modify an existing fan script to rather make use of 3 temperature thresholds for the different speeds (instead of a gliding RPM curve).

However, before I attempt that and get it all wrong, I'd just though I'd ask if anyone else maybe had success with controlling the fan on the C1 (or even the DNS-321) using this or another method?

Thanks!

Offline

 

#2 2010-05-08 20:23:09

getik
New member
Registered: 2010-04-27
Posts: 2

Re: Fan control DNS-323 revision C1 (or DNS-321?)

Right, since no-one responded, I assumed that no-one had an answer.  So I created one.

This is my new fan_ctrl.sh script that works for the C1 hardware revision.  Has switch on/off hysteresis and now, after some tweaks, won't keep the hard drives spun up either.

Code:

#!/bin/sh
#
# Script by getik
# It sets the fanspeed on the DNS-323 hardware revision
# C1 depending on the device temperature.
# It is loosely based on scripts originally by FIB,
# leper, fonz, gartylad and Uriel which can be found
# at http://dns323.kood.org.
# All temps in Fahrenheit.  If your device measures in
# Celcius, you will need to adjust the script.

PATH=/usr/bin:/bin:/usr/sbin:/sbin

# Kill fancontrol process
OLDPID=`pidof fancontrol`
if [ "$OLDPID" != "" ]; then
    kill -9 $OLDPID
fi

# T1 = temp where fan switches on
# T2 = temp where fan switches to high
# T3 = temp where fan switches off when it is already running
update_interval=30
T1=110
T2=120
T3=105

while [ 1 ]
do
# get the current temperature and fan status
T=`temperature g 0`
T=${T##*=}
S=`fanspeed g`

if [ $S -lt 1 ]; then
#    echo "Fan status: stopped"
    if [ $T -gt $T2 ]; then
#        echo "Fan set: high"
        fanspeed h > /dev/null
    elif [ $T -gt $T1 ]; then
#        echo "Fan set: low"
        fanspeed l > /dev/null
    fi
else
#    echo "Fan status: running"
    if [ $T -lt $T3 ]; then
#        echo "Fan set: stop"
        fanspeed s > /dev/null
    elif [ $T -lt $T2 ]; then
#        echo "Fan set: low"
        fanspeed l > /dev/null
    else
#        echo "Fan set: high"
        fanspeed h > /dev/null
    fi
fi 

sleep $update_interval
done

I've also had to make changes to my fan.sh startup script to copy this script to the ramdrive.  This MIGHT not be required any more, but was one of the things I ended up doing to ensure that my drives spin down.

Code:

#!/ffp/bin/sh
 
# PROVIDE: fan_ctrl.sh
# REQUIRE: LOGIN
 
. /ffp/etc/ffp.subr
 
name="fan_ctrl.sh"
command="/ffp/bin/$name"
sshd_flags=
 
start_cmd="fan_ctrl_start"
 
fan_ctrl_start()
{
        cp $command /usr/bin/fan_ctrl.sh
        proc_start_bg /usr/bin/fan_ctrl.sh
}
 
run_rc_command "$1"

If you use this, please post here and let me know if it works for you too.  You will most likely have to tweak the temperatures for your ambient and your device's temperature sensor (mine seems to over read significantly).  I also haven't ever had my device breach the upper limit, so my fan is always on low or off.

Enjoy!

Offline

 

#3 2010-05-22 23:56:07

superjhemp
New member
Registered: 2010-05-22
Posts: 1

Re: Fan control DNS-323 revision C1 (or DNS-321?)

Have it running for a few hours now on my C1 DNS323 and seems to work alright. Shuts off the fan a minute or two after the drives go to sleep.

Thanks.

Offline

 

#4 2010-10-08 22:04:21

konke
Member
Registered: 2010-10-08
Posts: 12

Re: Fan control DNS-323 revision C1 (or DNS-321?)

Could you write a "how to" to make this script work?
I have the C1 and i dont get the fanct1 script to work, could i just copy your script and set it in the fanct1.conf???

Offline

 

#5 2010-10-16 12:27:40

J0hn
New member
Registered: 2010-10-16
Posts: 1

Re: Fan control DNS-323 revision C1 (or DNS-321?)

getik, I have C1 device, and this script works for me, thank you!
Also, I have noticed that fancontrol can start again on some events. For example, when change "Turn Off Hard Drives" time thru web-interface.  Maybe need move "pidof" and "kill" inside while loop.

Offline

 

#6 2010-12-21 04:20:52

bgravato
Member
Registered: 2010-11-04
Posts: 44

Re: Fan control DNS-323 revision C1 (or DNS-321?)

Sorry for the late reply but I don't check this forum very often...

Anyways I've also written my own fan control script some time ago and I've shared it here on this post: http://dns323.kood.org/forum/viewtopic.php?id=6072

My approaches uses cron (and copying script to ramdisk) to avoid accessing the harddisk.

I have revision B1 but I wrote the script so that it would work on C1 too. It also has hysteresis.

Offline

 

#7 2011-01-10 21:17:36

Mizu001
Member
Registered: 2010-12-02
Posts: 15

Re: Fan control DNS-323 revision C1 (or DNS-321?)

I have this getik's script working but I need to manually restart it after every reboot. Is their a way to automate fan.sh script so it starts automatically after the system reboots?

Thanks for your help in advance.

Offline

 

#8 2011-01-10 23:46:11

mfpockets
Member
Registered: 2011-01-10
Posts: 44

Re: Fan control DNS-323 revision C1 (or DNS-321?)

konke wrote:

Could you write a "how to" to make this script work?
I have the C1 and i dont get the fanct1 script to work, could i just copy your script and set it in the fanct1.conf???

When someone answers Mizu can you also let me know how to use this script?

I understand what it is doing based on the comments but I am really new to all this scripting and linux and I dont know what to do with it. 

I know you dump the contents of the script into a notepad++ and save as a .sh extension, but what do I do with the file afterwards and what commands to use in the ssh terminal to set them to be persistent on reboot?

Thanks

Offline

 

#9 2011-01-11 02:26:11

bgravato
Member
Registered: 2010-11-04
Posts: 44

Re: Fan control DNS-323 revision C1 (or DNS-321?)

My approach was a bit different from all other scripts I've seen here. I prefer to use the cron to run the script. Anyways this what I did (assuming you already ffp installed and running):

1) Save the code bellow to a file named fan-cron.sh and put it on the nas in the folder ffp/start/

Code:

#!/bin/sh

# copy script to rootfs to avoid preventing the disks from spinning down
cp /ffp/bin/fan_ctrl_cron.sh /usr/bin/

# add the fan control script to the current cron list at 1 minute intervals
echo "$(crontab -l;echo '*/1 * * * * /usr/bin/fan_ctrl_cron.sh')"|crontab -

2) Save the code bellow to a file called fan_ctrl_cron.sh and copy it to the nas to the folder ffp/bin/

Code:

#!/bin/sh
#
# Script to control the fan speed on a D-Link DNS-323
#
# Note: This script is intended to be ran from the cron
#
# Author: Bruno Gravato
#
# version: 1.0
#

PATH=/usr/bin:/bin:/usr/sbin:/sbin

# kill original fancontrol daemon
PID=`pidof fancontrol`   
if [ "$PID" != "" ]   
then
  kill -9 $PID   
fi

# variables (temperatures are in Fahrenheit)
#
# fan will stop when temperature reaches this value
TEMP_STOP=96
# fan will spin at low speed when temperature reaches this value 
TEMP_LOW=104
# fan will spin at high speed when temperature reaches this value
TEMP_HIGH=113
# this is fan's rpm (rotations per minute) reference point to determine
# wether the fan is rotating at high or low speed
RPM_REF=4000

# get current temperature and fan speed
TEMP=$(temperature g 0)
TEMP=${TEMP##*=}
SPEED=$(fanspeed g)

# check fan speed
if [ $SPEED -lt 1 ]
    # fan is stopped
then
    if [ $TEMP -ge $TEMP_HIGH ]
    then
        # set high speed
        fanspeed h
    elif [ $TEMP -ge $TEMP_LOW ]
    then
        # set low speed
        fanspeed l
    fi
else
    # fan is spinning
    if [ $TEMP -le $TEMP_STOP ]
    then
        # stop the fan
        fanspeed s
    elif [ $SPEED -lt $RPM_REF ]
        # fan at low speed
    then
        if [ $TEMP -ge $TEMP_HIGH ]
        then
            # set high speed
            fanspeed h
        fi
    else
        # fan at high speed
        if [ $TEMP -le $TEMP_LOW ]
        then
            # set low speed
            fanspeed l
        fi
    fi
fi

3) To change permissions and make this files executable, establish a ssh or telnet connection to the nas and change to the ffp folder. Then change the permissions. Should be something like this:

Code:

cd /mnt/HD_a2/ffp/
chmod +x start/fan-cron.sh
chmod +x bin/fan_ctrl_cron.sh

4) Press Ctrl-D to terminate the ssh/telnet connection.

All should be fine upon the next reboot.

Note: In the code boxes above, when copying the code do not copy the first line that says Code: (that's from the BBCode). The first line in the scripts should be #!/bin/sh

I hope this is clear enough. If not let me know and I'll try to explain in other words.

Offline

 

#10 2011-01-11 03:16:28

mfpockets
Member
Registered: 2011-01-10
Posts: 44

Re: Fan control DNS-323 revision C1 (or DNS-321?)

Thanks! this looks great. 

Only problem is I dont have access to the start folder when I browse to it from windows

What is the command to allow access or the CP syntax to copy from local windows PC to the NAS?

Offline

 

#11 2011-01-11 03:20:24

bgravato
Member
Registered: 2010-11-04
Posts: 44

Re: Fan control DNS-323 revision C1 (or DNS-321?)

Copy to the ffp folder and then move it to the start folder from the terminal:

Code:

cd /mnt/HD_a2/ffp
mv fan-cron.sh start/

Offline

 

#12 2011-01-11 04:11:49

mfpockets
Member
Registered: 2011-01-10
Posts: 44

Re: Fan control DNS-323 revision C1 (or DNS-321?)

Thanks bgravato, managed to run all the commands and save all appropriate scripts.

Does this work with C1 though? 

I saved the sh files to proper directory's and set permissions as per step 3, but my fan is on after reboot and temperature g 0 shows current temp as 91, according to the script that should mean the fan is off correct?

Last edited by mfpockets (2011-01-11 04:23:00)

Offline

 

#13 2011-01-11 04:20:54

bgravato
Member
Registered: 2010-11-04
Posts: 44

Re: Fan control DNS-323 revision C1 (or DNS-321?)

Great! smile

Let me know if you find any problem with the scripts.

You can also change the temperature tresholds by editing ffp/bin/fan_ctrl_cron.sh script where it says:

Code:

# variables (temperatures are in Fahrenheit)
#
# fan will stop when temperature reaches this value
TEMP_STOP=96
# fan will spin at low speed when temperature reaches this value 
TEMP_LOW=104
# fan will spin at high speed when temperature reaches this value
TEMP_HIGH=113

(just change the numbers 96, 104 and 113, which are the temperature in fahrenheit)

Offline

 

#14 2011-01-11 04:23:39

mfpockets
Member
Registered: 2011-01-10
Posts: 44

Re: Fan control DNS-323 revision C1 (or DNS-321?)

Just edited my previous post while you were posting.   See above

Offline

 

#15 2011-01-11 04:29:16

bgravato
Member
Registered: 2010-11-04
Posts: 44

Re: Fan control DNS-323 revision C1 (or DNS-321?)

mfpockets wrote:

Thanks bgravato, managed to run all the commands and save all appropriate scripts.

Does this work with C1 though? 

I saved the sh files to proper directory's and set permissions as per step 3, but my fan is on after reboot and temperature g 0 shows current temp as 91, according to the script that should mean the fan is off correct?

Mine is B1, but it should work with C1. I use fanspeed s|l|h commands instead of rpm value (the reason why other scripts don't work in C1).
To test the fanspeed command you can just type fanspeed s and see if it stops.

Also note that the script is ran only once a minute, so it might take up to a minute for it to stop the fan after reading a temperature value below the threshold.

There might be other changes in C1 that I'm not aware that might be causing it to fail... I have no way of testing that unfortunately since mine is B1.

Offline

 

#16 2011-01-11 04:32:06

mfpockets
Member
Registered: 2011-01-10
Posts: 44

Re: Fan control DNS-323 revision C1 (or DNS-321?)

Ok so

fanspeed s did stop my fan.  I saw it took a minute from what I did understand from the script.  Where would I need to alter this?  "fanspeed s|l|h"

Or is applying the script from the OP the same as applying this one?  How do I appropriately remove the one I applied?  simply cd to the directory and then use whatever command is the unix command for del?

Last edited by mfpockets (2011-01-11 04:34:26)

Offline

 

#17 2011-01-11 04:34:10

bgravato
Member
Registered: 2010-11-04
Posts: 44

Re: Fan control DNS-323 revision C1 (or DNS-321?)

Also please let me know what's the output of the command fanspeed g
In B1 it returns the fan speed in rpm, but in C1 that might have a different output and that might be what's causing the script to fail.

Offline

 

#18 2011-01-11 04:36:07

mfpockets
Member
Registered: 2011-01-10
Posts: 44

Re: Fan control DNS-323 revision C1 (or DNS-321?)

it gave me an output of 0 as it is currently stopped I guess

I guess it was fanspeed h for high and then it returned 1 and it returns a 1 as well.....

Offline

 

#19 2011-01-11 04:42:27

mfpockets
Member
Registered: 2011-01-10
Posts: 44

Re: Fan control DNS-323 revision C1 (or DNS-321?)

should I just replace this:

# variables (temperatures are in Fahrenheit)
#
# fan will stop when temperature reaches this value
TEMP_STOP=96
# fan will spin at low speed when temperature reaches this value
TEMP_LOW=104
# fan will spin at high speed when temperature reaches this value
TEMP_HIGH=113
# this is fan's rpm (rotations per minute) reference point to determine
# wether the fan is rotating at high or low speed
RPM_REF=4000

# get current temperature and fan speed
TEMP=$(temperature g 0)
TEMP=${TEMP##*=}
SPEED=$(fanspeed g)

# check fan speed
if [ $SPEED -lt 1 ]
    # fan is stopped
then
    if [ $TEMP -ge $TEMP_HIGH ]
    then
        # set high speed
        fanspeed h
    elif [ $TEMP -ge $TEMP_LOW ]
    then
        # set low speed
        fanspeed l
    fi
else
    # fan is spinning
    if [ $TEMP -le $TEMP_STOP ]
    then
        # stop the fan
        fanspeed s
    elif [ $SPEED -lt $RPM_REF ]
        # fan at low speed
    then
        if [ $TEMP -ge $TEMP_HIGH ]
        then
            # set high speed
            fanspeed h
        fi
    else
        # fan at high speed
        if [ $TEMP -le $TEMP_LOW ]
        then
            # set low speed
            fanspeed l
        fi
    fi
fi   

WITH THIS INSTEAD

# T1 = temp where fan switches on
# T2 = temp where fan switches to high
# T3 = temp where fan switches off when it is already running
update_interval=30
T1=110
T2=120
T3=105

while [ 1 ]
do
# get the current temperature and fan status
T=`temperature g 0`
T=${T##*=}
S=`fanspeed g`

if [ $S -lt 1 ]; then
#    echo "Fan status: stopped"
    if [ $T -gt $T2 ]; then
#        echo "Fan set: high"
        fanspeed h > /dev/null
    elif [ $T -gt $T1 ]; then
#        echo "Fan set: low"
        fanspeed l > /dev/null
    fi
else
#    echo "Fan status: running"
    if [ $T -lt $T3 ]; then
#        echo "Fan set: stop"
        fanspeed s > /dev/null
    elif [ $T -lt $T2 ]; then
#        echo "Fan set: low"
        fanspeed l > /dev/null
    else
#        echo "Fan set: high"
        fanspeed h > /dev/null
    fi
fi

sleep $update_interval
done

Offline

 

#20 2011-01-11 04:52:21

bgravato
Member
Registered: 2010-11-04
Posts: 44

Re: Fan control DNS-323 revision C1 (or DNS-321?)

mfpockets wrote:

Ok so

fanspeed s did stop my fan.  I saw it took a minute from what I did understand from the script.  Where would I need to alter this?  "fanspeed s|l|h"

My script already has that changed, so it works on all A1/B1/C1

mfpockets wrote:

Or is applying the script from the OP the same as applying this one?  How do I appropriately remove the one I applied?  simply cd to the directory and then use whatever command is the unix command for del?

If you have another script installed and running it might be getting in the way...

To delete a file the command is rm file but use it very carefully... to avoid mistakes always add the option -i like this rm -i file
It will prompt before deleting.

Another safer option for disabling other scripts without deleting them is to remove the executing permissions.
You can do this similarly to what you did in step 3 but changing "+x" to "-x" like this:
chmod -x file.sh

A few basic linux commands:
ls - list files (similar to dir in old DOS system)
cd - change directory (works like cd in the old DOS)
cp - copy files
mv - move files
rm - delete files

You can get a manual page for commands by typing: man command-name
For example, to get the man page for 'cp' type: man cp
To scroll down in the page use the arrow keys/pageup/pagedown or space bar. To quit the man page press 'q'

Another trick to avoid typing by hand all the filenames: type just the first letters of the filename or directory name and press TAB. If only one completing option is available it will write the rest of it automatically, If nothing happens press TAB again, if more than one option is available it will show the available options (type more letters of the filename until it differs from the other options then you can use TAB again to complete). If pressing TAB twice doesn't do anything that it's because there's not completion options available with the letters you typed.

Offline

 

#21 2011-01-11 04:59:29

mfpockets
Member
Registered: 2011-01-10
Posts: 44

Re: Fan control DNS-323 revision C1 (or DNS-321?)

Thanks.

I'll play around a little.  To save space on the NAS they didnt include the man files. man cp returns no manual entry for cp

I have general PC knowledge but never worked with linux before.


I swapped the code from the first post with yours, only starting at the Temp variables and keeping the your original portion that specifies script dir and the part about killing the pid of the original, but still the unit turns on, this time 89 fareiheint (I readjust your his code to match your F ratings) and still the fan is on instead of off...  Do I need to turn off the fan control in the Dlink Web UI ?  or the Kill process takes care of that?

Offline

 

#22 2011-01-11 05:00:07

bgravato
Member
Registered: 2010-11-04
Posts: 44

Re: Fan control DNS-323 revision C1 (or DNS-321?)

mfpockets wrote:

should I just replace this:

# variables (temperatures are in Fahrenheit)
#
# fan will stop when temperature reaches this value
TEMP_STOP=96
# fan will spin at low speed when temperature reaches this value
TEMP_LOW=104
# fan will spin at high speed when temperature reaches this value
TEMP_HIGH=113
# this is fan's rpm (rotations per minute) reference point to determine
# wether the fan is rotating at high or low speed
RPM_REF=4000

# get current temperature and fan speed
TEMP=$(temperature g 0)
TEMP=${TEMP##*=}
SPEED=$(fanspeed g)

# check fan speed
if [ $SPEED -lt 1 ]
    # fan is stopped
then
    if [ $TEMP -ge $TEMP_HIGH ]
    then
        # set high speed
        fanspeed h
    elif [ $TEMP -ge $TEMP_LOW ]
    then
        # set low speed
        fanspeed l
    fi
else
    # fan is spinning
    if [ $TEMP -le $TEMP_STOP ]
    then
        # stop the fan
        fanspeed s
    elif [ $SPEED -lt $RPM_REF ]
        # fan at low speed
    then
        if [ $TEMP -ge $TEMP_HIGH ]
        then
            # set high speed
            fanspeed h
        fi
    else
        # fan at high speed
        if [ $TEMP -le $TEMP_LOW ]
        then
            # set low speed
            fanspeed l
        fi
    fi
fi   

WITH THIS INSTEAD

# T1 = temp where fan switches on
# T2 = temp where fan switches to high
# T3 = temp where fan switches off when it is already running
update_interval=30
T1=110
T2=120
T3=105

while [ 1 ]
do
# get the current temperature and fan status
T=`temperature g 0`
T=${T##*=}
S=`fanspeed g`

if [ $S -lt 1 ]; then
#    echo "Fan status: stopped"
    if [ $T -gt $T2 ]; then
#        echo "Fan set: high"
        fanspeed h > /dev/null
    elif [ $T -gt $T1 ]; then
#        echo "Fan set: low"
        fanspeed l > /dev/null
    fi
else
#    echo "Fan status: running"
    if [ $T -lt $T3 ]; then
#        echo "Fan set: stop"
        fanspeed s > /dev/null
    elif [ $T -lt $T2 ]; then
#        echo "Fan set: low"
        fanspeed l > /dev/null
    else
#        echo "Fan set: high"
        fanspeed h > /dev/null
    fi
fi

sleep $update_interval
done

No. It does about the same, but in a different manner, and uses the sleep mode which isn't compatible with the cron method I use for my script. My script already has the commands set for working with C1 in the same way as that script... So there's no need to change anything.

Offline

 

#23 2011-01-11 05:09:14

mfpockets
Member
Registered: 2011-01-10
Posts: 44

Re: Fan control DNS-323 revision C1 (or DNS-321?)

Ok, just swapped it back then.  Rebooting and seeing is sh is working.

When I type ps which process should I see?   Fan_control1 or is that the system one?

Offline

 

#24 2011-01-11 05:11:56

bgravato
Member
Registered: 2010-11-04
Posts: 44

Re: Fan control DNS-323 revision C1 (or DNS-321?)

mfpockets wrote:

I swapped the code from the first post with yours, only starting at the Temp variables and keeping the your original portion that specifies script dir and the part about killing the pid of the original, but still the unit turns on, this time 89 fareiheint (I readjust your his code to match your F ratings) and still the fan is on instead of off...  Do I need to turn off the fan control in the Dlink Web UI ?  or the Kill process takes care of that?

It should take care of it but they might have changed the behaviour in C1, so try changing it to manual (it should put it to full speed I think but then the script will take over in the next minute).

Copying my script to the other and mixing the two might not be such good idea... My script does pretty much the same thing as the other, but in a different manner. Mixing the two might give unexpected results.

Also the file names for the scripts matter. If you save it with a different filename that what I suggested it will fail to copy it to ramdisk and to launch it from the crontab (this is what the script in ffp/start does).

I'll try to explain this better... The script fan-cron.sh in ffp/start is run one time at boot time. It copies a file named "fan_ctrl_cron.sh" to ram and add it to the crontab list, if that file does not exist with that name it will fail and the script won't run.

As a side note (and this is somewhat irrelevant here) I forgot that ffp creates a simlink in the root dir for ffp so in the commands where I wrote "/mnt/HD_a2/ffp/..." I could have simply written "/ffp/..." omitting the "mnt/HD_a2/" which might lead to some confusion, sorry for that.

Offline

 

#25 2011-01-11 05:15:52

bgravato
Member
Registered: 2010-11-04
Posts: 44

Re: Fan control DNS-323 revision C1 (or DNS-321?)

mfpockets wrote:

Ok, just swapped it back then.  Rebooting and seeing is sh is working.

When I type ps which process should I see?   Fan_control1 or is that the system one?

You should see none.

The script is run every minute by the cron. It will be running only for a fraction of a second every minute.
It should kill fan_control1 so you should not see that one running.

To make sure my start script is working you can type: /ffp/start/fan-cron.sh and see if it produces any error message.

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2010 PunBB