Fixed main docker image so that it actually works
This commit is contained in:
parent
2ee9a26abd
commit
627cc9bc24
@ -8,7 +8,8 @@ services:
|
|||||||
# - MD1200BAUD=
|
# - MD1200BAUD=
|
||||||
- SERIALADAPTER=/dev/ttyUSB0
|
- SERIALADAPTER=/dev/ttyUSB0
|
||||||
- TEMP_FACTOR=17
|
- TEMP_FACTOR=17
|
||||||
# - EPPYSLEEPY=
|
- EPPYSLEEPY=0.25
|
||||||
|
- MDSERIALTIMEOUT=0.75
|
||||||
# - LOW_FAN_TRSHD=
|
# - LOW_FAN_TRSHD=
|
||||||
# - HIGH_FAN_TRSHD=
|
# - HIGH_FAN_TRSHD=
|
||||||
devices:
|
devices:
|
||||||
|
@ -7,9 +7,9 @@ MD1200BAUD = int(os.getenv("MD1200BAUD", 38400))
|
|||||||
# used if you want to run it on multiple JBODs
|
# used if you want to run it on multiple JBODs
|
||||||
SERIALADAPTER = os.getenv("SERIALADAPTER", "/dev/ttyUSB0")
|
SERIALADAPTER = os.getenv("SERIALADAPTER", "/dev/ttyUSB0")
|
||||||
# Factor that defines how aggressive the temperature curve is
|
# Factor that defines how aggressive the temperature curve is
|
||||||
TEMP_FACTOR = int(os.getenv("TEMP_FACTOR", 19))
|
TEMP_FACTOR = int(os.getenv("TEMP_FACTOR", 16))
|
||||||
# time between sending command to get temp and storing it. It's there to allow JBOD to answer
|
# time between sending command to get temp and storing it. It's there to allow JBOD to answer
|
||||||
EPPYSLEEPY = float(os.getenv("EPPYSLEEPY", 0.25))
|
EPPYSLEEPY = float(os.getenv("EPPYSLEEPY", 1))
|
||||||
|
|
||||||
LOW_FAN_TRSHD = int(os.getenv("LOW_FAN_TRSHD", 21))
|
LOW_FAN_TRSHD = int(os.getenv("LOW_FAN_TRSHD", 21))
|
||||||
HIGH_FAN_TRSHD = int(os.getenv("HIGH_FAN_TRSHD", 40))
|
HIGH_FAN_TRSHD = int(os.getenv("HIGH_FAN_TRSHD", 40))
|
||||||
@ -19,7 +19,11 @@ SETFANCMND = os.getenv("SETFANCMND", "set_speed")
|
|||||||
|
|
||||||
DEFOUTPRCNTG = int(os.getenv("DEFOUTPRCNTG", 24))
|
DEFOUTPRCNTG = int(os.getenv("DEFOUTPRCNTG", 24))
|
||||||
|
|
||||||
|
MDSERIALTIMEOUT = float(os.getenv("MDSERIALTIMEOUT", 1))
|
||||||
|
|
||||||
|
TEMPREADINTERVAL = int(os.getenv("TEMPREADINTERVAL", 15))
|
||||||
|
|
||||||
|
GETTEMPTIMESLEEP = int(os.getenv("GETTEMPTIMESLEEP", 1))
|
||||||
|
|
||||||
# init
|
# init
|
||||||
MDserial = serial.Serial(
|
MDserial = serial.Serial(
|
||||||
@ -28,18 +32,25 @@ MDserial = serial.Serial(
|
|||||||
parity=serial.PARITY_NONE,\
|
parity=serial.PARITY_NONE,\
|
||||||
stopbits=serial.STOPBITS_ONE,\
|
stopbits=serial.STOPBITS_ONE,\
|
||||||
bytesize=serial.EIGHTBITS,\
|
bytesize=serial.EIGHTBITS,\
|
||||||
timeout=1)
|
timeout=MDSERIALTIMEOUT)
|
||||||
|
|
||||||
|
lastTempReading = time.time()
|
||||||
|
MDtempDict = {}
|
||||||
|
|
||||||
|
|
||||||
|
def getTemp():
|
||||||
|
|
||||||
|
MDserial.write(f"{GETTMPCMND}\n\r".encode())
|
||||||
|
time.sleep(GETTEMPTIMESLEEP)
|
||||||
|
MDreturning = MDserial.read_until(" >").decode(errors="ignore")
|
||||||
|
|
||||||
def getTemp(inpMDreturning):
|
|
||||||
MDict = {}
|
MDict = {}
|
||||||
|
|
||||||
# Sanitise output
|
# Sanitise output
|
||||||
MDsanit = inpMDreturning.splitlines()
|
MDsanit = MDreturning.splitlines()
|
||||||
|
|
||||||
#if there is smth do smth
|
#if there is smth do smth
|
||||||
if inpMDreturning:
|
if MDreturning:
|
||||||
|
|
||||||
for line in MDsanit:
|
for line in MDsanit:
|
||||||
|
|
||||||
@ -61,10 +72,27 @@ def getTemp(inpMDreturning):
|
|||||||
MDict["exp0"] = int(line[12:14])
|
MDict["exp0"] = int(line[12:14])
|
||||||
case "EXP1":
|
case "EXP1":
|
||||||
MDict["exp1"] = int(line[12:14])
|
MDict["exp1"] = int(line[12:14])
|
||||||
case "AVG":
|
# case "AVG":
|
||||||
MDict["avg"] = int(line[12:14])
|
# MDict["avg"] = int(line[12:14])
|
||||||
|
# MDict["avg"] = int(line.strip().split("=")[1].strip().replace("c", ""))
|
||||||
|
# try:
|
||||||
|
# # Extract number from e.g. ' AVG = 40c'
|
||||||
|
# temp = int(line.strip().split("=")[1].strip().replace("c", ""))
|
||||||
|
# MDict["avg"] = temp
|
||||||
|
# except Exception as e:
|
||||||
|
# # print(f"[WARN] Failed to parse AVG line: {line} ({e})", flush=True)
|
||||||
|
# pass
|
||||||
case _:
|
case _:
|
||||||
|
# try to catch the AVG line like: " AVG = 40c"
|
||||||
|
stripped = line.strip()
|
||||||
|
if stripped.startswith("AVG"):
|
||||||
|
try:
|
||||||
|
temp = int(stripped.split("=")[1].strip().replace("c", ""))
|
||||||
|
MDict["avg"] = temp
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Could not parse AVG line: {line} ({e})", flush=True)
|
||||||
continue
|
continue
|
||||||
|
# continue
|
||||||
return MDict
|
return MDict
|
||||||
|
|
||||||
|
|
||||||
@ -75,15 +103,15 @@ def setSpeed(inSpeeDict: dict):
|
|||||||
outfanprcntg = 0
|
outfanprcntg = 0
|
||||||
|
|
||||||
# get backplanbe average
|
# get backplanbe average
|
||||||
if inSpeeDict["bp1"] and inSpeeDict["bp2"]:
|
if "bp1" in inSpeeDict and "bp2" in inSpeeDict:
|
||||||
bpavrg = (inSpeeDict["bp1"] + inSpeeDict["bp2"]) /2
|
bpavrg = (inSpeeDict["bp1"] + inSpeeDict["bp2"]) /2
|
||||||
outfanprcntg = int((bpavrg / (HIGH_FAN_TRSHD - LOW_FAN_TRSHD)) * TEMP_FACTOR)
|
outfanprcntg = int((bpavrg / (HIGH_FAN_TRSHD - LOW_FAN_TRSHD)) * TEMP_FACTOR)
|
||||||
os.system(f"echo setting {outfanprcntg}%")
|
# os.system(f"echo setting {outfanprcntg}%")
|
||||||
|
|
||||||
# Set fan speed
|
# Set fan speed
|
||||||
if outfanprcntg >= 20:
|
if outfanprcntg >= 20:
|
||||||
MDserial.write((f"{SETFANCMND} {str(outfanprcntg)} \n\r").encode())
|
MDserial.write((f"{SETFANCMND} {str(outfanprcntg)} \n\r").encode())
|
||||||
print(f"setting {outfanprcntg}%")
|
print(f"setting {outfanprcntg}%", flush=True)
|
||||||
return 0
|
return 0
|
||||||
else:
|
else:
|
||||||
# Set default value
|
# Set default value
|
||||||
@ -105,35 +133,57 @@ def setSpeed(inSpeeDict: dict):
|
|||||||
# # MDserial.open()
|
# # MDserial.open()
|
||||||
# print("Port allready opened.\nTry closing it first")
|
# print("Port allready opened.\nTry closing it first")
|
||||||
|
|
||||||
|
# Init
|
||||||
|
MDtempDict = getTemp()
|
||||||
|
lastTempReading = time.time()
|
||||||
|
try:
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
# https://stackoverflow.com/questions/52578122/not-able-to-send-the-enter-command-on-pyserial
|
# https://stackoverflow.com/questions/52578122/not-able-to-send-the-enter-command-on-pyserial
|
||||||
|
|
||||||
# get temperature data, wait for MD1200 to answer and store
|
# get temperature data, wait for MD1200 to answer and store
|
||||||
MDserial.write(f"{GETTMPCMND}\n\r".encode())
|
|
||||||
time.sleep(EPPYSLEEPY)
|
|
||||||
MDreturning = MDserial.read_until(" >").decode()
|
|
||||||
|
|
||||||
MDtempDict = getTemp(MDreturning)
|
currentTime = time.time()
|
||||||
|
|
||||||
|
if currentTime - lastTempReading >= TEMPREADINTERVAL:
|
||||||
|
MDtempDict = getTemp()
|
||||||
|
lastTempReading = currentTime
|
||||||
|
|
||||||
|
if MDtempDict:
|
||||||
setSpeedrcode = setSpeed(MDtempDict)
|
setSpeedrcode = setSpeed(MDtempDict)
|
||||||
|
|
||||||
# good
|
# good
|
||||||
if setSpeedrcode == 0:
|
if setSpeedrcode == 0:
|
||||||
continue
|
pass
|
||||||
# print("Were mint")
|
# print("Were mint", flush=True)
|
||||||
# time.sleep(EPPYSLEEPY)
|
# time.sleep(EPPYSLEEPY)
|
||||||
# not good
|
# not good
|
||||||
elif setSpeedrcode == 1:
|
elif setSpeedrcode == 1:
|
||||||
print("Ambigous temperature readings.\nFalling back to safe values.")
|
print("Ambigous temperature readings.\nFalling back to safe values.", flush=True)
|
||||||
# time.sleep(EPPYSLEEPY)
|
# time.sleep(EPPYSLEEPY)
|
||||||
# very not good
|
# very not good
|
||||||
elif setSpeedrcode == -1:
|
elif setSpeedrcode == -1:
|
||||||
print("o nyo")
|
print("o nyo", flush=True)
|
||||||
exit()
|
exit()
|
||||||
# very very very not good
|
# very very very not good
|
||||||
else:
|
else:
|
||||||
print("idk")
|
print("idk", flush=True)
|
||||||
|
exit()
|
||||||
|
else:
|
||||||
|
print(f"temperature not yet pulled.\nFalling back do default fan speed", flush=True)
|
||||||
|
# os.system(f"echo temperature not yet pulled.\nFalling back do default fan speed")
|
||||||
|
MDserial.write((f"{SETFANCMND} {str(DEFOUTPRCNTG)} \n\r").encode())
|
||||||
|
|
||||||
|
time.sleep(EPPYSLEEPY)
|
||||||
|
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("\n[INFO] KeyboardInterrupt detected. Exiting gracefully...")
|
||||||
|
MDserial.close()
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
|
finally:
|
||||||
|
print("closing port")
|
||||||
|
MDserial.close()
|
||||||
|
|
||||||
print("closing port")
|
print("closing port")
|
||||||
MDserial.close()
|
MDserial.close()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user