OpenCorsairLink in a jail to control fans?

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
I have had another look at this and was finally able to compile the official project (https://github.com/audiohacked/OpenCorsairLink) on a stock FreeBSD 12 install which I will do a bit more to document in the next little while and will also update the script to use the latest updates to @Kevin Horton 's script.

The key to compiling was to install gmake, gcc and git, then clone the project and adjust the Makefile top section to look like this:
Code:
CC = gcc

# CFLAGS ?=
CFLAGS += -std=c99
# CFLAGS += -pedantic-errors
CFLAGS += -I/usr/include -g
# CFLAGS += -D_XOPEN_SOURCE=500

LDFLAGS += -lm -lusb -L/usr/lib
LDLIBS += -usb -lrt

# pkg-config for libusb-1.0
CFLAGS += $(shell pkg-config --cflags libusb-1.0)
LDFLAGS += $(shell pkg-config --libs libusb-1.0)

PREFIX ?= /usr/local


Then gmake and presto!
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
Also, I have noticed that the official version does the reporting a bit differently, so the grep to find fan speeds by name will need a tweak with a grep -A2 (the line + 2 more) and a second grep to get the RPM value for fans... will need to add that as part of my options to Kevin's script, which I have now forked and will make a pull request when done to make this a "standard, but optional" component of that script.
 

Mannekino

Patron
Joined
Nov 14, 2012
Messages
332
I haven't used the script yet, I've only set the fan speed manually and keeping an eye on it myself. Will you be providing the binaries and script here when you finish everything? So far it's working well, very happy with the results. Noise levels have decreased because I got rid of my hellish PCI exhaust fan for my SAS controller and replaced it with a 40 mm PWM fan also connected to the Commander Pro.

The temperature of the heat sink of my SAS controller finally settled on 34 °C stable.
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
The temperature of the heat sink of my SAS controller finally settled on 34 °C stable
Great result. Well done for persisting until the end.

Will you be providing the binaries and script here when you finish everything?
I'll see about the binaries... to help people out, I will probably post again here.

I have forked Kevin's script on git and will request a merge, but my fork will exist in any case, so I'll post a link to both here also.
 

Sightblinder

Dabbler
Joined
Jul 17, 2012
Messages
15
A bit of background. I am looking into replacing my old Freenas server with complete new hardware. I am going with a bigger case this time to build for the future. I am considering getting 6 Corsair ML120 or LL120 fans with a commander pro to control them. I am new to Corsair but understand that you need(?) the ICUE software to control the fans and RGB but ICUE isn't compatible with Unix/Freenas.

Do I understand it correctly that this OpenCorsairLink script some of you have produced for Freenas is working to control fan speeds through the Commander pro (but not the RGB?).
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
Do I understand it correctly that this OpenCorsairLink script some of you have produced for Freenas is working to control fan speeds through the Commander pro (but not the RGB?).
The compiled version of the binary available currently in the thread is a version from over a year ago and has fan control working fine. The current project version which can be compiled from the source with the tips I gave is more or less complete and may work to control LEDs too (I am not interested in testing that).
 

Sightblinder

Dabbler
Joined
Jul 17, 2012
Messages
15
Thank you. As someone said, fan control is more important than the LED functions. Nice to have but not crucial.
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
OK, so I have a working version that I will soon be putting in production for my new version of the script to go with the new/official OpenCorsairLink version (compile instructions above in the thread).

I forked @Kevin Horton 's repository and created a new script called MASTER_PID_fan_control.pl based on Kevin/Stux's original script together with a lot of updates from @treefrob and some new/"borrowed" code to make a monstrosity of a script that can handle SuperMicro boards, Asrock or basically anything else via OpenCorsairLink paired with an appropriate Corsair Fan Controller.


This version of the script is not tested on Asrock or Supermicro by me, since I have neither of those board types available to me.

I attempted to leave all of the code I pulled across in a working state and made my additions fit to it, so I expect it to work with few bugs if any.

It should also add the possibility for folks with the other fan controller/board types to get logging to influxdb as part of the deal, so maybe that's interesting for some to switch to my version or for Rob or Kevin to pull across to theirs.
 

Mannekino

Patron
Joined
Nov 14, 2012
Messages
332
Hi @sretalla I've been using the compiled binary since earlier this year when we talked about it. I'm interested in taking it a step further and I would like to have the possibility to have the fans be dynamically controlled based on the temperature. I did experience quite a increase in both the HDD temperatures as well as the heatsink of my HBA (where I stuck a sensor on from the Commander Pro) this summer and I had to manually adjust the fan speed using the binary.

I think those fan control scripts that are popular on this forum don't work for me because of my specific Supermicro X9SCM-F board I've tried this in the past.

Will I be able to achieve what I want with your newest set of scripts you think? If so, I will try to deep dive into it.
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
I have it working well for me in a few boxes. You can manipulate the script as needed for your requirements.

I'm here to help you get it going and to work on any mods you see as useful.

I haven't yet implemented anything to use the builtin temperature sensors as a cue for fan speed changes, but I think that wouldn't be too hard.

Maybe if you're a bit more specific about how you see it working, I can have a bash at something...

I guess you're thinking about a third (or even fourth +) zone to control different fans based on the sensors.
 
Last edited:

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
Just to give a little idea about how the script can work, here's a snapshot of the grafana page I have which uses the influxdb output from my version of the script.

1605132665908.png


Those higher lines on the disktemps graph are NVME drives in that box, so don't have any relationship to the fans, but you can see clearly when there's load on one of them there.
 

Chaza218

Cadet
Joined
Dec 15, 2020
Messages
1
Hi - Stumbled across this

Apologies in advance am very new to Linux/TrueNAS. Windows Sysadmin by day but linux novice by night....

I have tried to setup OCL and run into issues. Looking at the github page (https://github.com/sretalla/nas_fan_control) was also quite confusing. I am unsure how to actually install it? Can anyone assist?

Thanks in advance :)
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
I am unsure how to actually install it? Can anyone assist?
You need a compiled version of OCL (so would be a file called OpenCorsairLink.elf, or something similar). Instructions on how to compile that earlier in this thread (EDIT: and in the post following this one in a zip file).

Then you put that together with the main script from that git repo (MASTER_PID_fan_control.pl ) and pick one of the the config files (like https://github.com/sretalla/nas_fan_control/blob/master/4d_config.ini )

You need to put them somewhere on your server, either in /root/ or in /mnt/tank/scripts or something like that.

Then you edit that master script to point at your chosen config file, the OpenCorsairLink.elf and which fans you want to control for what. (this will take a while to read through the script and find the right bits to change... once the script is running, you can't interactively change the parameters in there, interactive/live changes while the server is running are only in the config file)

it may help you to run OpenCorsairLink.elf manually in order to test first: ./OpenCorsairLink.elf --device 0 --fan channel=0,mode=0,pwm=100 (vary the channel up to 5 to get to each fan) You can also run it with no switches to get a status: ./OpenCorsairLink.elf --device 0

Then you run the script manually to convince yourself it works.

Once you're happy, you set up a post init script with a really long timeout (I use 999999999) and there you go.

EDIT: I now use tmux instead to allow controlling/restarting it at any time after startup without the need to reboot and avoids losing the script if middlewared restarts.
tmux new-session -d -s fanscript '/mnt/tank/scripts/MASTER_PID_fan_controller.pl'
 
Last edited:

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
OK, so github is horrible at being a place to store binaries, so I'll post a link to the project and then the binaries for simplification of the process for anyone arriving here:

The attached binary file has two executables as compiled from the project source (one for linux and one for FreeeBSD, both in clearly marked directories, but with the same name of OpenCorsairLink.elf)
 

Attachments

  • bin.zip
    161.8 KB · Views: 271

Ixian

Patron
Joined
May 11, 2015
Messages
218
Sretalla, just wanted to say thanks, I forked your script, and ended up incorporating a bunch of other changes (including modifying it for a Proxmox kernel vs. FreeBSD), and added some new stuff for the AsRock Rack X570D4U, which has different IPMI raw commands than older AsRock boards.

If you have one of those boards my fork is: https://github.com/Ixian/nas_fan_control

Though again I will note I modfied it for Linux; that said it should be pretty simple to change back for BSD (Perl & program paths, etc.). The major change was getting it to work with the X570D4U board.

If anyone is browsing through it and spots areas to improve by all means please do, I did a quick&dirty job on this but it works. It could be better.
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
I forked your script,
Great to see it's being used.

I looked at your repo... no changes committed to the MASTER_PID_fan_control.pl file as far as I can see... I am interested to see the changes for monitoring CPU in Linux as TrueNAS SCALE will require it.
 

Ixian

Patron
Joined
May 11, 2015
Messages
218
Great to see it's being used.

I looked at your repo... no changes committed to the MASTER_PID_fan_control.pl file as far as I can see... I am interested to see the changes for monitoring CPU in Linux as TrueNAS SCALE will require it.

Oops, I didn't update the Master file, left changes in my own. I went ahead and synced the updates to the Master file.

In particular:

There's no simple equivalent to Camcontrol on Linux vs. FreeBSD, so drive detection broke. The easy solution is to just manually put the drives in a val which is what I did (get_hd_list). This should really just be stuck in the config ini file. There are of course other ways to get the list of drives and filter out non-ssds, etc. on Linux if that functionality is needed.

get_cpu_temp_sysctl was broken because sysctl doesn't return useful data on Linux for cpu temps. The working, but incomplete, solution in my code gives two options:

The first one I tried just modified the sub to cat the output of coretemp and average them up. This doesn't have any external dependencies but only works for Intel CPUs

The second, I created a new sub called get_cpu_temp_sensors. This requires lm-sensors to be installed and configured, and for the user to pick the correct sensor/output for the tempurature. This works with AMD cpus as well and is also quick & accurate.

If I am not mistaken TrueNAS scale uses lm-sensors so that may be a good option going forward. As usual, better to have this in a config file.

Finally I added hddtemp based drive temp detection, because hddtemp is more accurate in my opinion and also faster than parsing Smartctl. It does require hddtemp to be installed but the other way requires Smartctl so 6 of 1, half dozen other in my view. I don't know if TrueNAS Scale will have hddtemp or if you'll need to install it.
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
There's no simple equivalent to Camcontrol on Linux vs. FreeBSD, so drive detection broke. The easy solution is to just manually put the drives in a val which is what I did (get_hd_list). This should really just be stuck in the config ini file. There are of course other ways to get the list of drives and filter out non-ssds, etc. on Linux if that functionality is needed.
I think for listing disks we should use sfdisk -l to get the data, then parse it to find the right disks like we do with the camcontrol output in FreeBSD.

I might have a bit of a play with that and see what I can come up with.

I like the idea of optional lm-sensors with the Intel default being a starting point if not.

lm-sensors seems to be there (although un-initialized on my test build with no intervention from me)

I had the feeling that hddtemp was just using smartctl in the background anyway and just presents the last known answer when queried, but maybe that warrants some investigation.
 
Last edited:

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
I had the feeling that hddtemp was just using smartctl in the background anyway and just presents the last known answer when queried, but maybe that warrants some investigation.
I had a look and confirm that it doesn't use smartctl, but gets SMART values from SATA/SCSI API calls directly to the disks.

Based on that, I guess we could leave code there for smartctl, but add the optional hddtemp function to use instead if desired/available. I like the elegance of cross-platform compatibility (even if the very first line of the script will directly prevent it being used without modification on both CORE and SCALE), but I see the draw to using "more efficient" code (if that's true... subject to confirmation).
 
Last edited:

Ixian

Patron
Joined
May 11, 2015
Messages
218
For the first line, couldn't we just use #!/usr/bin/env perl -w for cross-platform compatibility?

The problem I ran in to with parsing sfdisk -l is there's no way to easily filter out ssd/nvme devices from the output. Example: I have 2 WD Red SSDs (SATA) that run +/-10c on average from my spinning disks. The only way to tell that what kind of drives looking at the sfdisk output is by size/serial number, which you'd need to know and thus won't work for scripting purposes . You don't want those kinds of devices monitored the way this script is written as they will really throw off the averaging. SSDs are also generally much less temperature sensitive and may not be covered by the fans cooling the spinning disks anyway.

Even camcontrol on my Freenas box had problems parsing those devices out (and that at least will identify ssd/nvme) until I modified the regex. Since disks are something that don't change all that often it seems a lot simpler to just tell users to specify which ones they want to monitor for fan control purposes vs. trying to have a script figure it out. Easier to just put it in a conf file (which needs to be cleaned up anyway and have other stuff added to it).

Agree on the hddtemp thing. Maybe something simple, like if the path to hddtemp is defined (again, something for the config file) then use it, otherwise default to smartctl.
 
Last edited:
Top