From 9518085938eb5e69967cb2652fb107192ed555c6 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 21 Jul 2020 20:24:47 -0500 Subject: [PATCH] Add temperature control feature, as the board doesn't do it automatically for any fan but the cpu fan --- README.md | 1 + __pycache__/run_cmd.cpython-37.pyc | Bin 1476 -> 1795 bytes pwm.py | 56 ++++++++++++++++++++++------- run_cmd.py | 10 +++++- 4 files changed, 54 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 45b2a22..08482f7 100644 --- a/README.md +++ b/README.md @@ -14,3 +14,4 @@ This is a script to control 4-pin PWM fans on ASRock Rack motherboards with IPMI optional arguments: -h, --help show this help message and exit -i, --info Read fan information + -a, --auto Service to control fans based on temperature diff --git a/__pycache__/run_cmd.cpython-37.pyc b/__pycache__/run_cmd.cpython-37.pyc index e83be714c0ab3140d845e0393d49e9543032e2e5..d77b967094b151767f93955438b3adfd6d7f5242 100644 GIT binary patch delta 459 zcmYjNOG*Pl5bf&ep6N_JMo|-W;Z7JO5XnZwg`d3}UC1a%ObwEtnW1}v5He<=TLsMp z;t?bs!Lhf?XVSo9gy__=a9bYDu5 zIXaIlbWorq73iWzDp6sM)I}fjq#nWv3kvUN=Kyl@0lNSTqi_BQYm?OZ0$3j%$*p0_ z=Gl@2K{z6qeWH|g0KtY`J9OqKo_NLvZ0x+T3!Xv7Q!$nUc!SItI4D;bx&&{9Wnv&G zS{;X;iMl4%rtj1aI(@$%b(8om(zVS1^a5q{hx314(rVZ0^;RPkr`V3dd>Y**+n4Qb z(n|wZ+r8)|OUsrjL{rf*ad#?j;wG9v>Q(YW|2NTg^x8iIn`v_@>`Xmp2h6CrfFnX06Y!~g&Q delta 157 zcmZqXJHpN9#LLUY00i31Z1Huh6Zs^Jbb!1Rh7`sehA74qrWEEDhA5^KmK0VX&78uP z!VaWaQaDmLfi!ChV=#jz*T#%!Mn;y+M;NUb83iZ*XKG=T+T6l?j*(Graxkm5iYD7F suHw?9f};H7)Z*eIkab0ZAc74<$btyf$!FQrcsPJe4kiv>4o(gh0REyM_5c6? diff --git a/pwm.py b/pwm.py index 2a75147..697e3a3 100755 --- a/pwm.py +++ b/pwm.py @@ -3,6 +3,10 @@ import run_cmd import argparse import time MAXFAN = 6 +MINSPEED = 35 +MAXSPEED = 100 +MINTEMP = 30 +MAXTEMP = 65 parser = argparse.ArgumentParser(description='Read information about and control fans on ASRock boards with IPMI.', prog='asrock-pwm-ipmi') parser.add_argument('fanplusspeed', nargs='*', metavar='FAN:SPEED', @@ -11,28 +15,56 @@ parser.add_argument('fanplusspeed', nargs='*', metavar='FAN:SPEED', # help='Speed to set FAN to') parser.add_argument('-i', '--info', action="store_true", default=False, help='Read fan information') - +parser.add_argument('-a', '--auto', action="store_true", default=False, + help='Service to control fans based on temperature') args = parser.parse_args() #print(args.info) #print(args) #print(args.fanplusspeed) fanChanged = False + +def iterateFans(info): + for fanopt in info: + if str(fanopt.split(":"))[2:-2] == fanopt or int(fanopt.split(":")[0]) < 1 or int(fanopt.split(":")[0]) > MAXFAN: + print("Improper format!") + continue + fan, speed = fanopt.split(":") + run_cmd.setSpeed(int(fan), int(speed)) + fanChanged = True + if int(speed) == 0: + print("Set speed of FAN" + fan + " to Auto.") + else: + print("Set speed of FAN" + fan + " to " + speed + "%.") + + +while args.auto is True: + temp = run_cmd.getTemp() + speeds = [] + if temp < MINTEMP: + for i in range(2, 7): + speeds.append(str(i) + ":1") + #speeds = "2:1 3:1 4:1 5:1 6:1" + elif temp > MAXTEMP: + for i in range(2, 7): + speeds.append(str(i) + ":100") + #speeds = "2:100 3:100 4:100 5:100 6:100" + else: + base = temp - MINTEMP + max = MAXTEMP - MINTEMP + scaled = base / max + speed = int(scaled * (MAXSPEED - MINSPEED) + MINSPEED) + for i in range(2, 7): + speeds.append(str(i) + ":" + str(speed)) + iterateFans(speeds) + #print(speeds) + time.sleep(1) + if args.info is False and args.fanplusspeed == []: print("Nothing to do! See --help for usage.") quit if args.fanplusspeed != []: - for fanopt in args.fanplusspeed: - if str(fanopt.split(":"))[2:-2] == fanopt or int(fanopt.split(":")[0]) < 1 or int(fanopt.split(":")[0]) > MAXFAN: - print("Improper format!") - continue - fan, speed = fanopt.split(":") - run_cmd.setSpeed(int(fan), int(speed)) - fanChanged = True - if int(speed) == 0: - print("Set speed of FAN" + fan + " to Auto.") - else: - print("Set speed of FAN" + fan + " to " + speed + "%.") + iterateFans(args.fanplusspeed) if args.info is True: if fanChanged is True: print("\nWaiting for fans to adjust...") diff --git a/run_cmd.py b/run_cmd.py index 9f55939..677f254 100644 --- a/run_cmd.py +++ b/run_cmd.py @@ -1,5 +1,6 @@ #!/usr/bin/python3 import subprocess as sp +import json def setSpeed(fan, setspeed): speeds, speedsRaw = getAllSpeeds() @@ -32,7 +33,7 @@ def getFanInfo(): sensorinfo, err = cmdoutput.communicate() #print(sensorinfo.splitlines()) faninfo = [] - speeds, speedsRaw= getAllSpeeds() + speeds, speedsRaw = getAllSpeeds() for line in sensorinfo.splitlines(): if "FAN" in str(line): faninfo.append(str(line)) @@ -46,3 +47,10 @@ def getFanInfo(): faninfo[index] += "%" #print(faninfo[index]) return faninfo + +def getTemp(): + cmdoutput = sp.Popen(["sensors", "-Aj", "zenpower-*"], stdout=sp.PIPE) + sensorjson, err = cmdoutput.communicate() + sensordata = json.loads(sensorjson) + temp = sensordata["zenpower-pci-00c3"]["Tdie"]["temp1_input"] + return temp