Temperature controlled cooling fan (usb powered) on R7000

Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Contributions Upload
Goto page 1, 2  Next
Author Message
jase80
DD-WRT Novice


Joined: 20 Jan 2018
Posts: 5

PostPosted: Sun Jan 21, 2018 3:19    Post subject: Temperature controlled cooling fan (usb powered) on R7000 Reply with quote
I’m mainly typing this up for my own reference, but since I’d never keep it filed anywhere logical I figured it’d be best to throw it to the web and let google look after it.

I decided my R7000 was getting to hot running constantly at 70C, so I purchased a cheap USB powered laptop cooler to sit it on. Works a treat, easily dropping temp by >10C. Then I decided I wanted it to be temperature controlled.

Apparently you’re supposed to be able to issue commands like
Code:
echo on > /sys/bus/usb/devices/usb1/power/level 
or /sys/bus/usb/devices/usbX/power/autosuspend_delay_ms

depending on kernel version and control the power to specific USB ports. However, the /power sub-directory doesn’t appear to exist under any of the usb devices for my installation.

After spending hours trying many variants on that theme, I realised the port powered on and off when enabling/disabling “Core USB Support” in the web GUI under Services > USB, so I looked up the USB related nvramoptions and found “usb_enable”. Sadly, using nvram set usb_enable 1 wouldn’t immediately apply the change, even when followed by a nvram commit. I couldn’t find any way to get it to apply on demand like you can in the GUI. So that lead ran dry.

Eventually I came across the gpio approach as a possibility. As most of us know it’s the way we kill most of the LEDs to stop the router blinding us at night. I tried playing around with every gpio number that wasn’t already listed as identified, but none seemed to do anything.

Then I remembered 0 is a number too.
Fortunately gpio 0 is power to the usb, so using gpio enable 0 and gpio disable 0 I can power on and off the fan. It’s a bit ham-fisted as it takes out both ports, so you can’t have anything useful plugged in the other one, but since I don’t it works for me.
If anyone knows a way to target just one of the ports then please let us know!
Here’s the script I made, there’s probably a more elegant way of doing this, so let me know that too…

Code:

# TURN FAN ON (I.E. USB POWER) WHEN ROUTER IS HOT
usbgpiopin=0

#Temperature above which to turn on fan (650 = 65C)
hightemp=650

#Turn fan back off when temperature gets below (600 = 60C)
lowtemp=600

gpio disable usbgpiopin           #get it to a known state before we start

while [ 0 ];do
  temp=$(cat /proc/dmu/temperature)             #Get temperature

  if [ $temp -gt $hightemp ];then               #power on if greater than high temp
    gpio enable usbgpiopin
    echo $(date) "FAN ON" >> /tmp/var/log/messages
    while [ $temp -gt $lowtemp ];do
        sleep 10
        temp=$(cat /proc/dmu/temperature)       #Get temperature
    done
    gpio disable usbgpiopin                     #power off now we're less than low temp
    echo $(date) "FAN OFF" >> /tmp/var/log/messages
  fi
 sleep 10   #wait 10s before checking temps again
done



Last edited by jase80 on Sun Jan 21, 2018 18:40; edited 1 time in total
Sponsor
Xeon2k8
DD-WRT Guru


Joined: 11 Feb 2016
Posts: 1285

PostPosted: Sun Jan 21, 2018 12:58    Post subject: Re: Temperature controlled cooling fan (usb powered) on R700 Reply with quote
jase80 wrote:

I decided my R7000 was getting to hot running constantly at 70C,

You decided haha... So funny. Indeed you did it because you were bored (and because you have no clue about thermal specs on these chips architecture), it has no use at all.

_________________
R6400v2 (boardID:30) - Kong 36480 running since 03/09/18 - (AP - DNSMasq - AdBlocking - QoS)
R7800 - BS 31924 running since 05/26/17 - (AP - OpenVPN Client - DNSMasq - AdBlocking - QoS)
R7000 - BS 30771 running since 12/16/16 - (AP - NAS - FTP - SMB - OpenVPN Server - Transmission - DDNS - DNSMasq - AdBlocking - QoS)
R6250 - BS 29193 running since 03/20/16 - (AP - NAS - FTP - SMB - DNSMasq - AdBlocking)


Last edited by Xeon2k8 on Sun Jan 21, 2018 14:47; edited 1 time in total
thunderhead
DD-WRT User


Joined: 11 Nov 2017
Posts: 150

PostPosted: Sun Jan 21, 2018 14:44    Post subject: Reply with quote
Neat post but doubtful that anyone will repeat your project since 70C is within range of many reported temps for this CPU.
jase80
DD-WRT Novice


Joined: 20 Jan 2018
Posts: 5

PostPosted: Sun Jan 21, 2018 18:44    Post subject: Reply with quote
It's usually a good sign you're doing something useless when you don't find anything about it in your web searches...

I did note that 70C is well within operating range, however with 43C days coming here and 70C showing when I thought the thing was under base load I embarked on my little learning exercise.

If nothing else I've learnt more about hot this thing operates!
FurryNutz
DD-WRT User


Joined: 31 Oct 2010
Posts: 228

PostPosted: Sun Jan 21, 2018 19:10    Post subject: Reply with quote
Interesting and I presume is something neat. However I have found that just keeping a laptop cooler running 24/7 is simple and keeps the router cooler at all times. Rather then relying upon a temp to be reached and trigger additional cooling, I find it more simple to just have the fan running all the time. Most routers are designed well and work with the design and cooling them selves as long as placement is good and good air flow is available. However over the years working with electronics and routers, I've found that having additional external air flow doesn't hurt either. Heat eventually has a impact on electronics and slowly degrades components. Having additional cooling is good too.

I just have a laptop cooler which came with variable fan speed and keep it on all the time.
jase80
DD-WRT Novice


Joined: 20 Jan 2018
Posts: 5

PostPosted: Mon Jan 22, 2018 5:03    Post subject: Reply with quote
FurryNutz wrote:
Interesting and I presume is something neat. However I have found that just keeping a laptop cooler running 24/7 is simple and keeps the router cooler at all times.


You're not wrong! The noise bothered me and I let myself go down this rabbit hole... Specifically I don't want the fan resonating away overnight if it doesn't need to be. And yeah, maybe it isn't even needed on hot days under high load.

Hopefully the fact I've documented the gpio 0 thing will be useful to someone for something in the future as it's not something I could find elsewhere.

Doesn't need to be triggered by temperature, and it doesn't need to be a fan that's powered on and off by the USB.
tedm
DD-WRT User


Joined: 13 Mar 2009
Posts: 472

PostPosted: Mon Jan 22, 2018 6:08    Post subject: Reply with quote
Well seems to me you could have accomplished the same thing by buying a temperature controlled fan with an external thermistor and mounting the thermistor on the CPU but each to his own!!! Smile
jase80
DD-WRT Novice


Joined: 20 Jan 2018
Posts: 5

PostPosted: Mon Jan 22, 2018 7:59    Post subject: Reply with quote
d0ug wrote:
There are a lot of examples online of people going overkill on cooling that just is not needed. Raspberry Pis are good example. You see multiple examples of people heatsinking the hell out of them when it just is not needed.


So what I'm hearing is I should control a cooling system for the router (which doesn't need cooling) with an overclocked raspberry pi that in turn needs a cooling system...

tedm wrote:
Well seems to me you could have accomplished the same thing by buying a temperature controlled fan with an external thermistor and mounting the thermistor on the CPU but each to his own!!! Smile


Yeah, I just plugged in a fan and wrote a script. Didn't have to touch a screw. :p
jwh7
DD-WRT Guru


Joined: 25 Oct 2013
Posts: 2660
Location: Indy

PostPosted: Tue Jul 09, 2019 16:00    Post subject: Reply with quote
jase80 wrote:
So what I'm hearing is I should control a cooling system for the router (which doesn't need cooling) with an overclocked raspberry pi that in turn needs a cooling system...
Lol, nicely done. Wink

What I read is...now that you've dropped the temp more than 10degC, you need to overclock and get the temp back up to spec! Razz

_________________
# NAT/SFE/CTF: limited speed w/ DD # Repeater issues # DD-WRT info: FAQ, Builds, Types, Modes, Changes, Demo #
OPNsense x64 5050e ITX|DD: DIR-810L, 2*EA6900@1GHz, R6300v1, RT-N66U@663, WNDR4000@533, E1500@353,
WRT54G{Lv1.1,Sv6}@250
|FreshTomato: F7D8302@532|OpenWRT: F9K1119v1, RT-ACRH13, R6220, WNDR3700v4
MuzzleVelocity
DD-WRT User


Joined: 23 Apr 2010
Posts: 104

PostPosted: Wed Jul 10, 2019 18:50    Post subject: Reply with quote
so how often and for how long does the fan cycle on/off now?

its a cool idea for a project (no pun intended) if for nothing else then to learn something.

besides, regardless of what the thermal specs of that one chip say, the heat is going to affect other components on the board also. capacitors in particular can have a lifetime directly affected by temperature.
amnesico
DD-WRT Novice


Joined: 16 Dec 2011
Posts: 3

PostPosted: Wed Sep 18, 2019 20:10    Post subject: Reply with quote
I can't understand why so much criticism for something that's actually useful.

The critics should know, for example, that an AC68U (BCM4708A0), witch has a Tj Max of 130ºC, becomes unstable above 90ºC. Many reports of this at SNB... What's causing it? CPU? The neighboring components?

@jase80
I have no suggestion to improve your code, and for that reason, I just want to thank you for sharing your findings. I am using your script.
dahosepipe
DD-WRT Novice


Joined: 24 Mar 2015
Posts: 33

PostPosted: Thu Sep 19, 2019 5:47    Post subject: Reply with quote
Very cool! Love your ingenuity.
tcabez
DD-WRT Novice


Joined: 11 Apr 2020
Posts: 6

PostPosted: Wed Sep 16, 2020 18:22    Post subject: Reply with quote
Thank you very much! I was hovering mid 70's C, and I was able to hook up a 5v usb laptop fan because of this and I'm at 40's C now.

Edit:

I'm running 2020 builds on my R7000. So this still works today.
mwchang
DD-WRT Guru


Joined: 26 Mar 2013
Posts: 986
Location: Hung Hom, Hong Kong

PostPosted: Sun Sep 20, 2020 20:30    Post subject: Re: Temperature controlled cooling fan (usb powered) on R700 Reply with quote
jase80 wrote:

Code:

# TURN FAN ON (I.E. USB POWER) WHEN ROUTER IS HOT
usbgpiopin=0

#Temperature above which to turn on fan (650 = 65C)
hightemp=650

#Turn fan back off when temperature gets below (600 = 60C)
lowtemp=600

gpio disable usbgpiopin           #get it to a known state before we start

while [ 0 ];do
  temp=$(cat /proc/dmu/temperature)             #Get temperature

  if [ $temp -gt $hightemp ];then               #power on if greater than high temp
    gpio enable usbgpiopin
    echo $(date) "FAN ON" >> /tmp/var/log/messages
    while [ $temp -gt $lowtemp ];do
        sleep 10
        temp=$(cat /proc/dmu/temperature)       #Get temperature
    done
    gpio disable usbgpiopin                     #power off now we're less than low temp
    echo $(date) "FAN OFF" >> /tmp/var/log/messages
  fi
 sleep 10   #wait 10s before checking temps again
done


There are never too many scripts! Submit your work to:

https://wiki.dd-wrt.com/wiki/index.php/Useful_Scripts

Maybe kernel-panic69 could help you out on that. Smile
https://forum.dd-wrt.com/phpBB2/profile_sec.php?mode=viewprofile&u=430080


_________________
Router: Asus RT-N18U (rev. A1)

May the Force and farces be with you! Live long and prosper!

Facebook: https://www.facebook.com/changmanwai
Website: https://sites.google.com/site/changmw
SETI@Home profile: http://setiathome.berkeley.edu/view_profile.php?userid=211832
the-joker
DD-WRT Developer/Maintainer


Joined: 31 Jul 2021
Posts: 744
Location: All over YOUR webs

PostPosted: Wed Sep 01, 2021 10:00    Post subject: Reply with quote
This script as was posted above doesn't work on my router and contains a few issues mainly the usage of variables is wrong and gpio pin is router/usbport dependent.

The main issue is that the USBGPIOPIN is different, you can find out what your gpiopin is exactly by running nvram show | grep gpio and modding the USBGPIOPIN value accordingly.

Here is the modded script which contains formatting to run directly in terminal (ssh)

For Asus RT-AC68U connected to USB 2.0 port.
If you connect to USB 3.0 port will be a different gpio pin.

The script below has messages / formatting to be used on an active terminal session and spits outs the output nicely formatted, if you dont need this functionality just comment out the messages block.

Ive not included syslog messages, too much spam IMO but easily added if you want to.

Code:
#!/bin/sh
#set -o pipefail
set +x

# License MIT https://mit-license.org/

USBGPIOPIN=9
#Temperature above which to turn on fan (650 = 65°C)
HIGHTEMP=612
#Turn fan off when temperature gets below (500 = 50°C)
LOWTEMP=512
FIVED=50

DEC () {
  echo "+-------------------------------------+"
}
# Set it to a known state before we start
gpio disable $USBGPIOPIN
#TEMP=$(cat /proc/dmu/temperature) #Get temperature

WAIT() {
  sleep 10
}

# add comma separator to temperature values
CLEAN() {
  sed -r 's/([0-9]{2})/\1./g' | sed 's/^,//'
}

MESSAGE() {
  clear
  DEC
  echo "  tempCTL  |     Temperature:" "$TEMP" "C" | CLEAN
  DEC
  #echo "" > nohup.out
  echo "FAN ON  @: "$HIGHTEMP 'C' | CLEAN
  echo "FAN OFF @: "$LOWTEMP 'C' | CLEAN
  PLUSF
  DEC
}

PLUSF() {
  # On starting script dont start fans
  # unless we are at 5 degrees over $LOWTEMP
  MINTON=$((LOWTEMP + FIVED))
  echo MIN START:  "$MINTON" C != "$TEMP" C | CLEAN
}

while true
  do
    TEMP=$(cat /proc/dmu/temperature)
    if [ "$TEMP" -gt "$HIGHTEMP" ] || [ "$TEMP" -gt "$MINTON" ]
      then
        gpio enable $USBGPIOPIN
        MESSAGE
        echo "$(date +"%b %d %X"): Triggering FAN ON"
        while [ "$TEMP" -gt "$LOWTEMP" ]
          do
            WAIT
            TEMP=$(cat /proc/dmu/temperature)
          done
      else
        gpio disable $USBGPIOPIN
       MESSAGE
        echo "$(date +"%b %d %X"): Triggering FAN OFF"
    fi
    TEMP=$(cat /proc/dmu/temperature)
    echo "$TEMP" "C" | CLEAN
   WAIT
  done


There are some caveats, CPU usage by script when the USB is activated FAN ON is around 8%, while OFF its 0.1%, I've no idea how to fix this in script if its a script issue, makes no sense to me.

The DD-WRT status show 60% to 80% usage, Ive no idea why it takes that many CPU cycles for essentially waiting. Maybe the infinite loop is flawed, IDK.

_________________
Saving your retinas from the burn!🔥
DD-WRT Inspired themes for routers
DD-WRT Inspired themes for the phpBB Forum
DD-WRT Inspired themes for the SVN Trac & FTP site
Join in for a chat @ #style_it_themes_public:matrix.org or #style_it_themes:discord

DD-WRT UI Themes Bug Reporting and Discussion thread

Router: ANus RT-AC68U E1 (recognized as C1)


Last edited by the-joker on Fri Apr 15, 2022 9:08; edited 1 time in total
Goto page 1, 2  Next Display posts from previous:    Page 1 of 2
Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Contributions Upload All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum