Added a special token to avoid usage conflicts.

This commit is contained in:
YuruC3 2025-07-16 17:16:20 +02:00
parent 67874de37a
commit c5782018b8

View File

@ -10,22 +10,26 @@ 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 = float(os.getenv("TEMP_FACTOR", 19))
# 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", 1)) EPPYSLEEPY = float(os.getenv("EPPYSLEEPY", 1))
LOW_FAN_TRSHD = int(os.getenv("LOW_FAN_TRSHD", 21)) LOW_FAN_TRSHD = float(os.getenv("LOW_FAN_TRSHD", 21))
HIGH_FAN_TRSHD = int(os.getenv("HIGH_FAN_TRSHD", 40)) HIGH_FAN_TRSHD = float(os.getenv("HIGH_FAN_TRSHD", 40))
GETTMPCMND = os.getenv("GETTMPCMND", "_temp_rd") GETTMPCMND = os.getenv("GETTMPCMND", "_temp_rd")
SETFANCMND = os.getenv("SETFANCMND", "set_speed") SETFANCMND = os.getenv("SETFANCMND", "set_speed")
DEFOUTPRCNTG = int(os.getenv("DEFOUTPRCNTG", 24)) DEFOUTPRCNTG = float(os.getenv("DEFOUTPRCNTG", 24))
MDSERIALTIMEOUT = float(os.getenv("MDSERIALTIMEOUT", 1)) MDSERIALTIMEOUT = float(os.getenv("MDSERIALTIMEOUT", 1))
TEMPREADINTERVAL = float(os.getenv("TEMPREADINTERVAL", 15)) TEMPREADINTERVAL = float(os.getenv("TEMPREADINTERVAL", 15))
TEMPSETING = bool(os.getenv("TEMPSETING", True))
PROCESSTEMPWAITTIME = float(os.getenv("PROCESSTEMPWAITTIME"), 0.75)
# INFLUXDB config # INFLUXDB config
# token = "apg1gysUeCcxdcRTMmosJTenbEppmUNi9rXlANDB2oNadBdWAu2GVTDc_q_dyo0iyYsckKaOvPRm6ba2NK0y_A==" # token = "apg1gysUeCcxdcRTMmosJTenbEppmUNi9rXlANDB2oNadBdWAu2GVTDc_q_dyo0iyYsckKaOvPRm6ba2NK0y_A=="
token = os.getenv("INFLUX_TOKEN") token = os.getenv("INFLUX_TOKEN")
@ -56,6 +60,7 @@ MDserial = serial.Serial(
lastTempReading = time.time() lastTempReading = time.time()
MDtempDict = {} MDtempDict = {}
MDict = {} MDict = {}
currentSerialUsage = False
fluxSending = False fluxSending = False
currentTime = 0 currentTime = 0
lastTempReading = 0 lastTempReading = 0
@ -68,12 +73,16 @@ write_api = inflxdb_client.write_api(write_options=SYNCHRONOUS)
def getTemp(): def getTemp():
global MDict, fluxSending global MDict, fluxSending, currentSerialUsage
currentSerialUsage = True
MDserial.write(f"{GETTMPCMND}\n\r".encode()) MDserial.write(f"{GETTMPCMND}\n\r".encode())
time.sleep(1) time.sleep(1)
MDreturning = MDserial.read_until(" >").decode() MDreturning = MDserial.read_until(" >").decode()
currentSerialUsage = False
# MDict = {} # MDict = {}
# Sanitise output # Sanitise output
@ -133,6 +142,7 @@ def getTemp():
def setSpeed(inSpeeDict: dict): def setSpeed(inSpeeDict: dict):
global currentSerialUsage
bpavrg = 0 bpavrg = 0
# default # default
@ -144,16 +154,23 @@ def setSpeed(inSpeeDict: dict):
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}%")
currentSerialUsage = True
# 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}%", flush=True) print(f"setting {outfanprcntg}%", flush=True)
currentSerialUsage = False
return 0 return 0
else: else:
# Set default value # Set default value
MDserial.write((f"{SETFANCMND} {str(DEFOUTPRCNTG)} \n\r").encode()) MDserial.write((f"{SETFANCMND} {str(DEFOUTPRCNTG)} \n\r").encode())
currentSerialUsage = False
return 1 return 1
currentSerialUsage = False
# If something goes super wrong # If something goes super wrong
return -1 return -1
@ -198,14 +215,14 @@ def process_temps():
write_api.write(bucket=bucket, org=org, record=inflxdb_Data_To_Send) write_api.write(bucket=bucket, org=org, record=inflxdb_Data_To_Send)
# Clean up before another loop # Clean up before another lo#op, 0.75
inflxdb_LeData.clear() inflxdb_LeData.clear()
print("Sending data to InfluxDB", flush=True) print("Sending data to InfluxDB", flush=True)
fluxSending = False fluxSending = False
else: else:
time.sleep(0.25) time.sleep(PROCESSTEMPWAITTIME)
@ -216,7 +233,7 @@ lastTempReading = time.time()
def mainCodeHere(): def mainCodeHere():
while True: while True:
global MDict, fluxSending, currentTime, lastTempReading global MDict, fluxSending, currentTime, lastTempReading, currentSerialUsage
# 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
@ -227,7 +244,7 @@ def mainCodeHere():
getTemp() getTemp()
lastTempReading = currentTime lastTempReading = currentTime
if MDict: if MDict and TEMPSETING:
setSpeedrcode = setSpeed(MDict) setSpeedrcode = setSpeed(MDict)
# good # good
@ -247,11 +264,18 @@ def mainCodeHere():
else: else:
print("idk", flush=True) print("idk", flush=True)
exit() exit()
elif TEMPSETING == False:
print(f"Waiting to get temp", flush=True)
pass
else: else:
print(f"temperature not yet pulled.\nFalling back do default fan speed", flush=True) 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") # os.system(f"echo temperature not yet pulled.\nFalling back do default fan speed")
currentSerialUsage = True
MDserial.write((f"{SETFANCMND} {str(DEFOUTPRCNTG)} \n\r").encode()) MDserial.write((f"{SETFANCMND} {str(DEFOUTPRCNTG)} \n\r").encode())
currentSerialUsage = False
time.sleep(EPPYSLEEPY) time.sleep(EPPYSLEEPY)