Simple fan speed control for the Firebox X750e



  • Most of the time my newly commissioned X750e is doing very little, and so can get by without much cooling, but of course now and again I do actually use it and want to up the cooling. I therefore wrote the following very simple pair of scripts to provide automatic fan speed control.

    The first script is a demon which should be located at /usr/local/sbin/fanctrld.sh with execute permissions. This relies on WGXepc having been installed in /usr/local/bin.

    If the CPU temperature is above the defined set temperature of 60 degC the green LED on the front of the box will flash. Once it's at or below that temperature the LED will show solid green.

    #!/bin/sh
    # Regulate the CPU temperature to the set temperature. The green
    # front panel LED will flash green if the fan speed is being raised
    # to control the temperature and will be set green once the desired
    # temperature is achieved.
    
    # Target temperature
    target=60
    
    # Initial fan setting
    fan=20
    
    # Loop, adjusting the fan speed
    while true
    do
            mb_temp=`mbmon -I -T1 -c1 | cut -d '.' -f 1`
            cpu_temp=`mbmon -I -T2 -c1 | cut -d '.' -f 1`
    
            difference=$(($cpu_temp-$target))
    
            # Indicate if the temperature is too high or low
            if [ $difference -gt 0 ]
            then /usr/local/bin/WGXepc -l green_flash > /dev/null
            else
            /usr/local/bin/WGXepc -l green > /dev/null
            fi
            fan=$(($fan+$difference))
    
            # Limit max fan control to 255
            if [ $fan -gt 255 ]
            then fan=255
            fi
    
            # Limit min fan control to 0
            if [ $fan -lt 5 ]
            then fan=5
            fi
    
            # Adjust the fan speed
            /usr/local/bin/WGXepc -f `printf "%x\n" $fan` > /dev/null
    
            # Display the temperatures and fan setting
            # echo CPU:$cpu_temp MB:$mb_temp fan:$fan
    
            # Sleep allowing for heat-soak
            sleep 5
    done
    

    And then there's the startup script in /usr/local/etc/rc.d/fanctrl.sh.

    #!/bin/sh
    
    rc_start() {
            if [ `pgrep -f fanctrld.sh` ];then
                    pkill -f fanctrld.sh
                    sleep 1
            fi
            /usr/local/sbin/fanctrld.sh &
    }
    
    rc_stop() {
            if [ `pgrep -f fanctrld.sh` ];then
                    pkill -f fanctrld.sh
                    sleep 1
            fi
    }
    
    case $1 in
            start)
                    rc_start
                    ;;
            stop)
                    rc_stop
                    /usr/local/bin/WGXepc -f ff > /dev/null
                    ;;
            restart)
                    rc_stop
                    rc_start
                    ;;
    esac
    

    I hope somebody finds this of use.

    Steve



  • After some experimentation I found that the Pentium 5 M, which is good for 100 degC, is easy to cool to 64 degC at under max fan speed and at Gbps load. I've therefore modified the daemon script to attempt to maintain that. I've also put in a check for bogus temperatures as if mbmon fails I don't want to cook my CPU!

    #!/bin/sh
    # Regulate the CPU temperature to the set temperature. The green
    # front panel LED will flash green if the fan speed is being raised
    # to control the temperature and will be set green once the desired
    # temperature is achieved.
    
    # Target temperature
    target=64
    min_temp=40
    gain=5
    delay=2
    
    # Initial fan setting
    fan=20
    
    # Loop, adjusting the fan speed
    while true
    do
    	#mb_temp=`mbmon -I -T1 -c1 | cut -d '.' -f 1`
    	cpu_temp=`mbmon -I -T2 -c1 | cut -d '.' -f 1`
    
    	# Drop out if the temperature looks bogus to prevent overheating
    	if [ $cpu_temp -lt $min_temp ]
    	then
    		/usr/local/bin/WGXepc -f ff > /dev/null
    		/usr/local/bin/WGXepc -l red_flash > /dev/null
    		break
    	fi
    
    	difference=$(($cpu_temp-$target))
    
    	# Indicate if the temperature is too high or low
    	if [ $difference -gt 0 ]
    	then /usr/local/bin/WGXepc -l green_flash > /dev/null
    	else
    	/usr/local/bin/WGXepc -l green > /dev/null
    	fi
    	fan=$(($fan+($gain*$difference)))
    
    	# Limit max fan control to 255
    	if [ $fan -gt 255 ]
    	then fan=255
    	fi
    
    	# Limit min fan control to 0
    	if [ $fan -lt 5 ]
    	then fan=5
    	fi
    
    	# Adjust the fan speed
    	/usr/local/bin/WGXepc -f `printf "%x\n" $fan` > /dev/null
    
    	# Display the temperatures and fan setting
    	#echo CPU:$cpu_temp MB:$mb_temp fan:$fan
    
    	# Sleep allowing for heat-soak
    	sleep $delay
    done
    

    Steve


  • Netgate Administrator

    @Steve:

    I've also put in a check for bogus temperatures as if mbmon fails I don't want to cook my CPU!

    Good job. Did you read the other similar thread?
    http://forum.pfsense.org/index.php/topic,63240.0.html

    It seems as though mbmon will eventually fail or the SuperIO chip eventually locks into some odd mode. I added an option to WGXepc to read the temperature directly (mbmon reads every sensor value every time) but it didn't help.

    Fortunately it fails to 127°C so the fans just go to max.

    I'll be interested in your results from this. It could be just a bad SuperIO chip or thermistor in Bigramon's box.

    Steve



  • Hi Steve,

    Your new WGXepc is reading temperature just fine using

    WGXepc -t | sed '1,2d'
    

    I'll let you know if it goes wrong!

    Steve



  • This has been working reliably for some time, so having just updated to 2.1 and re-applied this fix I though I might as well post a complete set of files.

    Rename the attachment to lose the .png suffix and decompress. You'll find the following files. Copy them to the directory shown. Ensure that the sh files and WGXepc are executable.

    | Filename | Target Directory |
    | fanctrl.sh | /usr/local/etc/rc.d |
    | fanctrld.sh | /usr/local/sbin |
    | functions.inc.php | /usr/local/www/includes |
    | system_information.widget.php | /usr/local/www/widgets/widgets |
    | WGXepc | /usr/local/bin |

    Start the fan control thus, or simply reboot:

    # /usr/local/etc/rc.d/fanctrl.sh
    

    You should hear the fans slow considerably. The daemon will try to maintain the set temperature of 64 degC. After some experimentation I found this to work well.

    Credit is due here to stephenw10 for the WGXepc utility. Note that he's produced a couple of versions, and you need this one as it reports temperature.

    The php scripts will read the CPU temperature and display it on the dashboard as the attached image.

    Steve

    ![Screen Shot 2013-09-22 at 16.36.26.png](/public/imported_attachments/1/Screen Shot 2013-09-22 at 16.36.26.png)
    ![Screen Shot 2013-09-22 at 16.36.26.png_thumb](/public/imported_attachments/1/Screen Shot 2013-09-22 at 16.36.26.png_thumb)
    WatchGuardX750e.zip.png



  • Thanks Steve!  Working great here.  :)



  • Should running WGXepc -f display the current fan speed that is set by the script? I had been running the fans around 60 and figured this would be a better way to control the cooling. When I started the fan control the fans shot up in speed and seemed to stay there. Temps were running around 50ish with the fans on 60. They weren't much lower after starting the script and never seemed to adjust down.

    Its quite possible I did something wrong.



  • Everything except instructions on how to make the files executable are on this page in case it got confusing…

    It wont hurt to try it again.  Id install the filemanager package and use that to verify files...

    https://forum.pfsense.org/index.php/topic,66129.msg366219.html#msg366219

    https://doc.pfsense.org/index.php/PfSense_on_Watchguard_Firebox#Controlling_hardware_with_WGXepc

    You should barely be able to hear the fans.



  • @chpalmer:

    Everything except instructions on how to make the files executable are on this page in case it got confusing…

    It wont hurt to try it again.  Id install the filemanager package and use that to verify files...

    https://forum.pfsense.org/index.php/topic,66129.msg366219.html#msg366219

    https://doc.pfsense.org/index.php/PfSense_on_Watchguard_Firebox#Controlling_hardware_with_WGXepc

    You should barely be able to hear the fans.

    With the temperature at 50 the fans will be reduced to the minimum speed if everything was installed correctly. Did you make the scripts executable?

    Steve



  • @Steve:

    @chpalmer:

    Everything except instructions on how to make the files executable are on this page in case it got confusing…

    It wont hurt to try it again.  Id install the filemanager package and use that to verify files...

    https://forum.pfsense.org/index.php/topic,66129.msg366219.html#msg366219

    https://doc.pfsense.org/index.php/PfSense_on_Watchguard_Firebox#Controlling_hardware_with_WGXepc

    You should barely be able to hear the fans.

    With the temperature at 50 the fans will be reduced to the minimum speed if everything was installed correctly. Did you make the scripts executable?

    Steve

    Chmod +x on both .sh files and WGXepc. I tried chmod 0755 as well.

    I guess I should first start by saying I'm trying this on a Firebox X550e. I assume the hardware is similar enough for this to work. The box has only been up and running for a couple of days now and I had WGXepc working and controlling the fans manually until I saw this thread today and figured I'd try it.

    I installed the files again and this time when I ran /usr/local/etc/rc.d/fanctrl.sh it didnt change the manual fan speed of 55 I had previously set. The first time I tried this the fans shot up to ff and stayed there. They are now running at 55 without any change, at least according to WGXepc -f. I assumed, which might be the problem, that running that command after fanctrl.sh would show you the current fan speed. I have not noticed a drop in fan speed sound since running fanctrl.sh.

    I have not tried a reboot as of yet.



  • If you pull up the widget does it show the temperature or something else?

    edit=  Ill say that I tried to make it work with the copy of WGXepc that I had which I thought was the same and found it was wrong.

    Use the copy that comes in Steves zip file.



  • @chpalmer:

    If you pull up the widget does it show the temperature or something else?

    edit=  Ill say that I tried to make it work with the copy of WGXepc that I had which I thought was the same and found it was wrong.

    Use the copy that comes in Steves zip file.

    It shows the temperature.

    I tried the version I had installed as well and it said that WGXepc could accept multiple values or something along those lines. I figured that might be the problem so I used the one in the zip file before my first post just to make sure.



  • Are you still using commands in shellcmd or other to set fan speeds manually?



  • @chpalmer:

    Are you still using commands in shellcmd or other to set fan speeds manually?

    Nothing in shellcmd currently. I set it manually at the command line after first trying the fanctrl.sh command and the fan shot up to ff. But its only been set at the command line.

    I did try setting it back to ff manually and running fanctrl.sh with no noticeable drop in speed. I didnt look to see if there was a "reset to factory" for the fan speed.


  • Netgate Administrator

    Try running WGXepc -t to read the temperature.
    If you look at the thread I linked earlier you'll see that the SuperIO chip (which has the sensor) has a habit of erroneously reporting 125C after some time. If you haven't rebooted that box for while it could just be reporting wrong.

    Steve



  • @stephenw10:

    Try running WGXepc -t to read the temperature.
    If you look at the thread I linked earlier you'll see that the SuperIO chip (which has the sensor) has a habit of erroneously reporting 125C after some time. If you haven't rebooted that box for while it could just be reporting wrong.

    Steve

    I checked that earlier and it was the same as the gui/widget and mbmon. Firewall has only been up 3 days but I'll give it a reboot and see what happens.



  • Reboot did the trick, thanks for the help. Probably should have tried that first.



  • Just spotted the error. In my post I had the following instruction to start the fan control:

    # /usr/local/etc/rc.d/fanctrl.sh
    

    This is wrong. It should be:

    # /usr/local/etc/rc.d/fanctrl.sh start
    

    You can stop the daemon, and return the fans to full speed with the following:

    # /usr/local/etc/rc.d/fanctrl.sh stop
    

    Sorry about that.

    Steve



  • I actually tried this

    # /usr/local/etc/rc.d/fanctrl.sh stop
    

    but didnt notice a change which makes sense because it sets the fans back to full speed where they already where.

    Thanks for putting this together, I like it better than manually setting the fan speed.


  • Netgate Administrator

    Any idea what speed the fans average out at when the script is running?
    I guess it would be very dependent on ambient temperature and cpu load but it would be interesting to hear any anecdotal evidence.

    Steve



  • Mine's sat at the minimum as per the constants at the top of the /usr/local/sbin/fanctrld.sh script

    target=64
    min_temp=40
    gain=5
    delay=2
    min_fan=15
    

    thus:

    [2.1-RELEASE][root@pfsense]/root(8): /usr/local/bin/WGXepc -f
    Found Firebox X-E
    Fanspeed is f
    

    It does rise during activity.

    I'm nervous about setting min_fan any lower as I don't really want to stop the fans altogether.

    Steve



  • I should explain that min_fan setting. There are three fans in the box, two of which primarily cool the CPU, but both those and the third fan also exhaust warm air drawing cooler air over all the other components. I therefore thought it best to keep some airflow even when the CPU was below the target temperature on 64 degC. It doesn't take much airflow to provide noticeable cooling.

    Steve


  • Netgate Administrator

    Ah interesting, F is really quite slow.
    Does your script use decimal conversion, F=15?

    Steve



  • The lines that write the value do the conversion thus:

    # Adjust the fan speed
    /usr/local/bin/WGXepc -f `printf "%x\n" $fan` > /dev/null
    

    The machine isn't under much load most of the time, but even when doing big downloads it still runs quite cool. Accessing the web interface, most notably the RRD Graphs causes a speed up of the fans.

    Steve


  • Netgate Administrator

    Ah. I managed to mangle my hex and decimal values a few times when writing the WGXepc program (I'm no programmer!) with 'interesting' results.  ::)

    I was also concerned about cooling the rest of the box, the PSU seemed to run particularly hot. I measured it using a pyrometer since I'm pretty sure parts of it could kill you. The cooling provisions on the box in general don't seem that great especially if it's in a rack, I'd like to see some vents in the front panel to allow cool air in. I have my boxes set to fan speed 32, none have stopped working yet. It really is a shame they didn't spend the extra pennies required to put in a SuperIO chip that had auto fan control.

    Steve



  • Hi Steve,

    I installed your scripts and the modified toll from Steve with the temperatue option.
    After reboot I noticed that the fans slow down but after some time the temperature reads 35 C and the fans are up at speed FF.

    The fans are always running at this speed. I noticed no change here. What is wrong? I also tried the corrected call with the start option

    Matthias



  • OK, found the error by myself. The min temperature is set to 40. Mine its 35. So the if-statement is not correct. I set the min temp to 30, now it is running!

    Maybe it is a good idea to refactor the if statement…

    Matthias



  • Hi Matthias,

    I saw your first post emailed to my phone and thought that looked like the script had taken the safety bailout. This is there to protect from erroneous temperature readings I'd been warned of, and too high a fan speed in the safe response to that.

    Interesting that your box is running so cool. I've never seen mine below 50 degC. By the time its booted to the point the script starts the CPU is normally up to that kind of temperature.

    Steve



  • Hi Steve,

    my box is in a network cabinet. There is not much space at the back for the air to come out (approx. 5 cm to the rear of the cabinet.
    I am wondering myself why it is so cool! Now with your script it runs with speed f at temp 40 C.
    It is ok, I think.

    Bye
    Matthias


  • Netgate Administrator

    What CPUs are you running? Is the cpu sensor touching the bottom 9f the CPU? I can't actually remember if it has a spring loaded sensor or not.  :-\

    Steve



  • Intel(R) Pentium(R) M processor 2.13GHz

    I don't have PowerD enabled though. That could well explain it. I should probably enable that as I'm sure the CPU will "wake up" to a higher power state quite quickly on demand.

    The temperature diode is part of the CPU die, not an external sensor.

    Steve


  • Netgate Administrator

    Ah, in which case the diode values can vary between CPU models so the real temperature may be different.
    I seem to remember reading that they are actually an offset from the CPU maximum temperature so you have allow for that. No idea if mbmon is doing that. I don't think it is because I just read out the register in WGXepc. If you read the docs for the superio chip there is quite a bit about configuring it for the correct sensor type.

    Steve



  • Hi,

    I am using an Intel(R) Pentium(R) M processor 1.70GHz with PowerD enabled.

    Matthias



  • That explains it then. I'm being power mad again! :D

    An interesting comparison for anybody trying to build a lower power router then. I went for the more powerful option as I wanted to be future proofed should my broadband speed increase again, and also as I didn't know if I'd want to be using squid etc when I started.

    Steve



  • @Steve:

    This has been working reliably for some time, so having just updated to 2.1 and re-applied this fix I though I might as well post a complete set of files.

    Rename the attachment to lose the .png suffix and decompress. You'll find the following files. Copy them to the directory shown. Ensure that the sh files and WGXepc are executable.

    | Filename | Target Directory |
    | fanctrl.sh | /usr/local/etc/rc.d |
    | fanctrld.sh | /usr/local/sbin |
    | functions.inc.php | /usr/local/www/includes |
    | system_information.widget.php | /usr/local/www/widgets/widgets |
    | WGXepc | /usr/local/bin |

    Start the fan control thus, or simply reboot:

    # /usr/local/etc/rc.d/fanctrl.sh
    

    You should hear the fans slow considerably. The daemon will try to maintain the set temperature of 64 degC. After some experimentation I found this to work well.

    Credit is due here to stephenw10 for the WGXepc utility. Note that he's produced a couple of versions, and you need this one as it reports temperature.

    The php scripts will read the CPU temperature and display it on the dashboard as the attached image.

    Steve

    For us n00bs… :) can you tell us how to copy these files to the pfSense file system? how do you change the permissions?

    I guess I'm kind of looking for a step by step on how to do this. I just recently got a 1250e and it works great, but I'd like to quiet it down a bit and change the red LED.

    Thanks.


  • Netgate Administrator

    One way of doing it is explained here:
    https://doc.pfsense.org/index.php/PfSense_on_Watchguard_Firebox#Controlling_hardware_with_WGXepc
    I've just noticed though that my Google site still has version 0.8 which doesn't read the temperature. I'll get that updated. (Edit: done)

    You can also use SCP to move files onto the pfSense box. I use WinSCP for that.

    Steve



  • @stephenw10:

    One way of doing it is explained here:
    https://doc.pfsense.org/index.php/PfSense_on_Watchguard_Firebox#Controlling_hardware_with_WGXepc
    I've just noticed though that my Google site still has version 0.8 which doesn't read the temperature. I'll get that updated. (Edit: done)

    You can also use SCP to move files onto the pfSense box. I use WinSCP for that.

    Steve

    Got it. I think it's working…  I can see the temperature now being displayed in the status screen.

    When I run WGXepc -f it shows me a value of bb... is that the lowest it'll go?
    Thanks again for your help.

    My temperature shows 45 deg. C.


  • Netgate Administrator

    BB is the lowest speed you can run the fans where the speed sensors work. The fans can run much slower though.  The value is a two digit hexidecimal number so anything between 00 and FF. I wouldn't go below, say, 16 though.
    If you're using the script it should be going lower than bb anyway.

    Steve



  • @stephenw10:

    BB is the lowest speed you can run the fans where the speed sensors work. The fans can run much slower though.  The value is a two digit hexidecimal number so anything between 00 and FF. I wouldn't go below, say, 16 though.
    If you're using the script it should be going lower than bb anyway.

    Steve

    when I ran

    /usr/local/etc/rc.d/fanctrl.sh
    

    it didn't really slow down, and when I checked the fan speed by running WGXepc -f, it just said bb, so I manually set it to 20. Temp is not going above 50 C, but it would be nice to have it automatically control the fan instead of me manually configuring it.

    Any other thoughts as to why it's not working?

    Thanks again for your help.