Skip to content

Commit

Permalink
Merge pull request #42 from JeffCurless/41-oddity-with-fan-speed-afte…
Browse files Browse the repository at this point in the history
…r-reboot

Force fan to off setting.
  • Loading branch information
JeffCurless authored Jan 22, 2023
2 parents 4fda6fa + b777239 commit c3520a3
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 13 deletions.
80 changes: 74 additions & 6 deletions argon-status.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import sys
import os
import subprocess
import time
import math
sys.path.append( "/etc/argon/" )
from argonsysinfo import *

from argonconfig import *
from version import *
import argparse

#
Expand Down Expand Up @@ -174,6 +176,9 @@ def show_hddutilization():
printTable(lst, title = 'Storage Utilization:' )
#
def show_all():
"""
Display all options that we care about
"""
show_storage()
show_raid()
show_hddTemperature()
Expand All @@ -184,15 +189,24 @@ def show_all():
show_memory()

def show_memory():
"""
Display currnent memory utilization
"""
memory = argonsysinfo_getram()
printTable({"Total":memory[1],"Free":memory[0]},title="Memory:")

#
def print_version():
print( 'Currently running version 2023.01.15-01')
"""
Display the version of we are currently running
"""
print( 'Currently running version: ' + ARGON_VERSION )

#
def setup_arguments():
"""
Setup all of the arguments that we recoginize.
"""
parser = argparse.ArgumentParser()
parser.add_argument( '-v', '--version', action='store_true', help='Display the version of the argon scripts.')
parser.add_argument( '-a', '--all', action='store_true', help='Display full status of the Argon EON.')
Expand All @@ -206,14 +220,64 @@ def setup_arguments():
parser.add_argument( '-t', '--temp', action='store_true', help='Display information about the current temperature.')
parser.add_argument( '-u', '--hdduse', action='store_true', help='Display disk utilization.')
parser.add_argument( '--hddtemp', action='store_true', help='Display the temperature of the storage devices.')
parser.add_argument( '--cooling', action='store_true', help='Display cooling information about the EON.')
return parser

#
def show_config():
"""
Create a table of the HDD and CPU temperatures, and then add in all of the marked fan
speeds for the given temps. We also highlight the thing that is forcing the current fanspeed.
"""
hddtemplst = loadHDDFanConfig()
cputemplst = loadCPUFanConfig()

actualcpu = argonsysinfo_getcputemp()
actualhdd = argonsysinfo_getmaxhddtemp()
fanspeed = argonsysinfo_getCurrentFanSpeed()
keys = {}
hdd = {'Temperature':'HDD fanspeed'}
cpu = {'Temperature':'CPU fanspeed'}
for i in hddtemplst.keys():
keys.__setitem__( i, '' )

for i in cputemplst.keys():
keys.__setitem__( i, '' )

for i in sorted(keys.keys()):
if i in hddtemplst.keys():
if float(actualhdd) >= float(i) and (int(hddtemplst[i]) == int(fanspeed)):
hdd.__setitem__( i, '<' + hddtemplst[i] + '>' )
else:
hdd.__setitem__(i,hddtemplst[i] )
else:
hdd.__setitem__( i, '' )
if i in cputemplst.keys():
if (float(actualcpu) >= float(i)) and (int(cputemplst[i]) == int(fanspeed)):
cpu.__setitem__( i, "<" + cputemplst[i] + ">" )
else:
cpu.__setitem__( i, cputemplst[i] )
else:
cpu.__setitem__( i, '' )

start = time.clock_gettime_ns(time.CLOCK_MONOTONIC)
usage1= argonsysinfo_diskusage()
lst = []
lst.append( hdd )
lst.append( cpu )
printTable( lst, title="Temperature Settings Table:" )
#
def check_permission():
"""
Determine if the user can properly execute the script. Must have sudo or be root
"""
if not ('SUDO_UID' in os.environ ) and os.geteuid() != 0:
return False
return True

#
def main():
"""
Process all command line options here. This is where we modify the default settings based on the evironment
variable AGON_STATUS_DEFAULT. If there are any flags that cannot be used together, filter them out here.
"""
parser = setup_arguments()
if len(sys.argv) > 1:
args = parser.parse_args()
Expand Down Expand Up @@ -249,7 +313,11 @@ def main():
show_hddutilization()
if args.all:
show_all()
if args.cooling:
show_cpuTemperature()
show_hddTemperature()
show_fanspeed()
show_config()

if __name__ == "__main__":
setup_arguments()
main()
2 changes: 2 additions & 0 deletions argoneon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ sudo curl -L $ARGONDOWNLOADSERVER/argonconfig.py -o $INSTALLATIONFOLDER/argoncon
sudo chmod 755 $INSTALLATIONFOLDER/argonconfig.py
sudo curl -L $ARGONDOWNLOADSERVER/argonlogging.py -o $INSTALLATIONFOLDER/argonlogging.py --silent
sudo chmod 755 $INSTALLATIONFOLDER/argonlogging.py
sudo curl -L $ARGONDOWNLOADSERVER/version.py -o $INSTALLATIONFOLDER/version.py --silent
sudo chmod 755 $INSTALLATIONFOLDER/version.py

# RTC Setup
basename="argoneon"
Expand Down
26 changes: 22 additions & 4 deletions argononed.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from argonsysinfo import *
from argonlogging import *
from argonconfig import *
from version import *

# Initialize I2C Bus
import smbus
Expand Down Expand Up @@ -144,10 +145,9 @@ def setFanSpeed (overrideSpeed : int = None, instantaneous : bool = True):
# Pause 30s before speed reduction to prevent fluctuations
time.sleep(30)


# Make sure the value is in 0-100 range
newspeed = max([min([100,newspeed]),0])
if prevspeed != newspeed:
if overrideSpeed is not None or (prevspeed != newspeed):
try:
if newspeed > 0:
# Spin up to prevent issues on older units
Expand All @@ -157,10 +157,16 @@ def setFanSpeed (overrideSpeed : int = None, instantaneous : bool = True):
logging.debug( "writing to fan port, speed " + str(newspeed))
argonsysinfo_recordCurrentFanSpeed( newspeed )
except IOError:
logError( "Error trying o update fan speed.")
return prevspeed
return newspeed

def temp_check():
"""
Main thread for processing the temperature check functonality. We just try and set the fan speed once
a minute. However we do want to start with the fan *OFF*.
"""
setFanOff()
while True:
setFanSpeed (instantaneous = False)
time.sleep(60)
Expand Down Expand Up @@ -242,6 +248,7 @@ def display_loop(readq):
cpuusagelist = argonsysinfo_listcpuusage()
curlist = cpuusagelist
except:
logError( "Error processing information for CPU display")
curlist = []
if len(curlist) > 0:
oled_loadbg("bgcpu")
Expand Down Expand Up @@ -271,6 +278,7 @@ def display_loop(readq):
curlist.append({"title": curdev, "value": argonsysinfo_kbstr(tmpobj[curdev]['total']), "usage": int(tmpobj[curdev]['percent']) })
#curlist = argonsysinfo_liststoragetotal()
except:
logError( "Error processing information for STORAGE display")
curlist = []
if len(curlist) > 0:
oled_loadbg("bgstorage")
Expand Down Expand Up @@ -310,6 +318,7 @@ def display_loop(readq):
timespan = (stoptime - prevTime)/1000000000
prevTime = stoptime
except:
logError( "Error processing data for BANDWIDTH display")
curlist = []
if len(curlist) > 0:

Expand Down Expand Up @@ -343,6 +352,7 @@ def display_loop(readq):
tmpobj = argonsysinfo_listraid()
curlist = tmpobj['raidlist']
except:
logError( "Error processing display of RAID information.")
curlist = []
if len(curlist) > 0:
oled_loadbg("bgraid")
Expand Down Expand Up @@ -385,6 +395,7 @@ def display_loop(readq):
oled_writetextaligned(tmpraminfo[1], stdleftoffset, 40, oledscreenwidth-stdleftoffset, 1, fontwdReg)
needsUpdate = True
except:
logError( "Error processing information for RAM display")
needsUpdate = False
# Next page due to error/no data
screenjogflag = 1
Expand Down Expand Up @@ -460,6 +471,7 @@ def display_loop(readq):

needsUpdate = True
except:
logError( "Error processing temerature information for TEMP display" )
needsUpdate = False
# Next page due to error/no data
screenjogflag = 1
Expand All @@ -469,6 +481,7 @@ def display_loop(readq):
if len(curlist) == 0:
curlist = argonsysinfo_getipList()
except:
logError( "Error processing information for IP display")
curlist = []

if len(curlist) > 0:
Expand Down Expand Up @@ -508,6 +521,7 @@ def display_loop(readq):

needsUpdate = True
except:
logError( "Error processing information of TIME display" )
needsUpdate = False
# Next page due to error/no data
screenjogflag = 1
Expand Down Expand Up @@ -570,17 +584,21 @@ def display_defaultimg():
cmd = sys.argv[1].upper()
if cmd == "SHUTDOWN":
# Signal poweroff
logInfo( "SHUTDOWN requested via shutdown of command of argononed service")
setFanOff()
bus.write_byte(ADDR_FAN,0xFF)

elif cmd == "FANOFF":
# Turn off fan
setFanOff()
logInfo( "FANOFF requested via fanoff command of the argononed service")
if OLED_ENABLED == True:
display_defaultimg()

elif cmd == "SERVICE":
# Starts the power button and temperature monitor threads
try:
logInfo( "argononed service version " + ARGON_VERSION + " starting.")
ipcq = Queue()
t1 = Thread(target = shutdown_check, args =(ipcq, ))

Expand All @@ -597,5 +615,5 @@ def display_defaultimg():
GPIO.cleanup()

elif cmd == "VERSION":
print( "Version: 2023.01.15")
print( "Version: " + ARGON_VERSION )

17 changes: 14 additions & 3 deletions argonsysinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@

fanspeed = Path('/tmp/fanspeed.txt')

def checkPermission():
"""
Determine if the user can properly execute the script. Must have sudo or be root
"""
if not ('SUDO_UID' in os.environ ) and os.geteuid() != 0:
return False
return True

#
def argonsysinfo_getCurrentFanSpeed():
""" Get the current fanspeed of the system, by reading a file we have stored the speed in.
Expand Down Expand Up @@ -189,15 +197,15 @@ def argonsysinfo_gethddtemp():
if curdev[0:2] == "sd" or curdev[0:2] == "hd":
# command = os.popen(hddtempcmd+" -d sat -A /dev/"+curdev+" | grep 194 | awk '{print $10}' 2>&1")
def getSmart(smartCmd):
if not checkPermission() and not smartCmd.startswith("sudo"):
smartCmd = "sudo " + smartCmd
try:
command = os.popen(smartCmd)
smartctlOutRaw = command.read()
except Exception as e:
print (e)
finally:
command.close()
if 'Permission denied' in smartctlOutRaw and not smartCmd.startswith('sudo'):
return getSmart(f"sudo {smartCmd}")
if 'scsi error unsupported scsi opcode' in smartctlOutRaw:
return None

Expand Down Expand Up @@ -416,7 +424,10 @@ def argonsysinfo_getraiddetail(devname):
spare = 0
resync = ""
hddlist =[]
command = os.popen('mdadm -D /dev/'+devname)
if not checkPermission():
command = os.popen('sudo mdadm -D /dev/'+devname)
else:
command = os.popen('mdadm -D /dev/'+devname)
tmp = command.read()
command.close()
alllines = tmp.split("\n")
Expand Down
6 changes: 6 additions & 0 deletions version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#
# Version number
#

ARGON_VERSION = "2023.01.16"

0 comments on commit c3520a3

Please sign in to comment.