Automagic fan control for the Jetson Nano is here!

I’ve created the Automagic fan control for the jetson nano.

Gone are the sleepless nights of 100% fan speed!
Gone are the worryingly high temperatures because you forgot to turn on the fan.

Here’s your solution:
[url]https://github.com/Pyrestone/jetson-fan-ctl[/url]

Sleep well, my children!

8 Likes

That’s very cool.

FYI, if you wanted a utility that could monitor many aspects of your system via python, you could install the psutil module.

Then you could read the temp without having to run an external command.

This is on my current laptop, but the same would apply for the nano (Just no system76 object).

>>> import psutil
>>> psutil.sensors_temperatures()['system76'][0][1]
39.0
$ cat /sys/class/thermal/thermal_zone0/temp 
39000
>>> psutil.sensors_fans()
{'system76': [sfan(label='CPU fan', current=2164), sfan(label='GPU fan', current=2286)]}

There’s alot of cool information this module can access for you without having to spawn subprocess commands.

I tried this and now my Jetson no longer boots up. SSH into the system to reverse it.

@vondalej, you have to make sure to have the & symbol after the line with python.
The rc.local script is run during the boot process and must terminate normally before the boot process continues. The & tells bash to run the script in a separate process, so it doesn’t wait for the script to finish.

@defied thanks for the suggestion, but i wanted to have minimal dependencies for installation, so i did it this way using the built-in subprocess module.

Suggestions:

  1. Use systemd on Ubuntu instead of init.d scripts (a .service unit file).

  2. Don’t use the subprocess module to cat a file. Python has an open keyword for this and you can somefile.seek(0) if you need to seek to the beginning of the file again.

@mdegans thanks for the suggestion, I will test this. It’s kinda weird though because I’m not quite sure whether these are real files. The cat solution works for now.

Additionally, I looked into creating services, but idk if i have time to implement that. If you want to, you’re free to create a pull request.

Re: procfs, they aren’t real files but they can be treated like them. It’s like /dev or /run

Re: pull request. Will do Monday to add systemd functionality.

Ok. Thanks!
Maybe we can also create an installer script, so users don’t have to manually do that.

I was just thinking about that. Good idea. Will do.

@mdegans I had a bit of time this evening, and have implemented your suggestions.
Turns out systemd is actually pretty simple.

If you find anything else, please let me know.

installed via the install script. I edited the .json file and did the restart script. I don’t notice any increase in fan speed once it hits the max temp.

@vondalej, please create an issue at the repo, and provide some information on your system.
Namely, please provide the outputs to the following commands:

  1. sudo cat /etc/rc.local
  2. sudo cat /etc/automagic-fan/config.json
  3. sudo service automagic-fan status
  4. cat /sys/devices/virtual/thermal/thermal_zone0/temp
  5. cat /sys/devices/pwm-fan/target_pwm

I’m noticing the rc.local file isn’t matching what your manual install said…

#!/bin/bash
sleep 10
sudo /usr/bin/jetson_clocks
sudo sh -c ‘echo 255 > /sys/devices/pwm-fan/target_pwm’

{
“FAN_OFF_TEMP”:20,
“FAN_MAX_TEMP”:30,
“UPDATE_INTERVAL”:2
}

automagic-fan.service - Automagic fan control
Loaded: loaded (/lib/systemd/system/automagic-fan.service; enabled; vendor pr
Active: active (running) since Mon 2019-06-10 04:34:05 EDT; 3h 11min ago
Main PID: 7298 (python3)
Tasks: 1 (limit: 4181)
CGroup: /system.slice/automagic-fan.service
└─7298 /usr/bin/python3 /usr/bin/automagic-fan/fanctl.py
Jun 10 07:45:32 Jetson-Nano sudo[26001]: pam_unix(sudo:session): session closed
Jun 10 07:45:34 Jetson-Nano sudo[26004]: root : TTY=unknown ; PWD=/ ; USER=r
Jun 10 07:45:34 Jetson-Nano sudo[26004]: pam_unix(sudo:session): session opened
Jun 10 07:45:34 Jetson-Nano sudo[26004]: pam_unix(sudo:session): session closed
Jun 10 07:45:36 Jetson-Nano sudo[26007]: root : TTY=unknown ; PWD=/ ; USER=r
Jun 10 07:45:36 Jetson-Nano sudo[26007]: pam_unix(sudo:session): session opened
Jun 10 07:45:36 Jetson-Nano sudo[26007]: pam_unix(sudo:session): session closed
Jun 10 07:45:38 Jetson-Nano sudo[26010]: root : TTY=unknown ; PWD=/ ; USER=r
Jun 10 07:45:38 Jetson-Nano sudo[26010]: pam_unix(sudo:session): session opened
Jun 10 07:45:38 Jetson-Nano sudo[26010]: pam_unix(sudo:session): session closed
lines 1-18/18 (END)

35500

123

I have since changed the installation, using services instead of the rc.local script, which is no longer used. A clean install now no longer requires changes in rc.local.

The service seems to be running fine, although the sudo logs look a little weird. Are you on the newest version?

Your rc.local looks fine to me and shouldn’t cause this behavior. The only thing that might be is that the old process is still running, or the process didn’t update the parameters yet.

Can you try rebooting to see if that fixes it?

Otherwise, run htop to see if there is another copy of fanctl.py running somewhere.
You can install it with sudo apt install htop

I’ve rebooted a couple times and haven’t seen a change. I know what the fan sounds like at 255. I moved the parameters to make max at 30. I’m not seeing any difference in fan speed. I’ll check htop when I get home tonight to look for a duplicate process.

Using cat /sys/devices/pwm-fan/target_pwm i’m seeing the fan speed gradually go up. I just assumed it would max out when it hit the max temp. What is the increase amount and time?

It looks like its maxed out at 178. It must not have taken the update to max out at 30 and its still working with 50.

It should be at 255 at max temp. It does this reliably on both of my machines with your settings.

Can you try cloning the newest version from github, running ./uninstall.sh, ./install.sh, setting the configuration and restarting the service?

Now that I know its at least increasing fan speed, I’m satisfied. I can’t get my machine much over 35 with the things I do.

Okay. I still don’t quite know what went wrong there.
If there’s anything I can help you with, please let me know.

Very good project but having python3 running in the background to support the service daemon takes up a lot of memory. I have rewritten the project in C++ and reduced the size considerably. The C++ version can be found at GitHub - hooperbill/fan-daemon: Jetson Nano fan control daemon

Would love any feedback and many thanks to Pyrestone for a great fan controller.

1 Like