mirror of
https://github.com/JonasunderscoreJones/PI-server-rack.git
synced 2025-10-23 09:39:18 +02:00
start of v0.2
This commit is contained in:
parent
03ae07d762
commit
9e84f79584
5 changed files with 75 additions and 441 deletions
|
@ -1,57 +1,29 @@
|
|||
import RPi.GPIO as GPIO
|
||||
import subprocess
|
||||
import time
|
||||
# Purpose
|
||||
# - transmit the following to RPI4 using binary:
|
||||
# - CPU temps (low <30°; medium 30°<x<45°; high 45°<x<60°; panic >60°)
|
||||
|
||||
# GPIO setup
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setwarnings(False)
|
||||
# - receive the following from Arduino using binary:
|
||||
# - used current of RPI 4
|
||||
# - used current of RPI 1.2
|
||||
# - uptime
|
||||
# - cpu usage (core #0 - #3)
|
||||
# - cpu frequency
|
||||
# - cpu temps (RPI 4)
|
||||
# - ram usage
|
||||
# - am capacity
|
||||
# - swap usuage
|
||||
# - disk usage
|
||||
# - disk capacity
|
||||
# - disk used
|
||||
# - mc server motd
|
||||
# - mc sever version
|
||||
# - mc server version brand
|
||||
# - mc server players max
|
||||
# - mc server players online
|
||||
# - mc server plugins
|
||||
# - mc server player_list
|
||||
# - amount of connected devices
|
||||
# - fan speed 180mm fan
|
||||
# - fan speed 40mm fan
|
||||
|
||||
# Powering Status Pin to indicate that control program is up
|
||||
GPIO.setup(4, GPIO.OUT)
|
||||
GPIO.output(4, True)
|
||||
|
||||
# setting up communication pins for binary fanmode transmission
|
||||
GPIO.setup(17, GPIO.OUT)
|
||||
GPIO.setup(18, GPIO.OUT)
|
||||
|
||||
# define default variables -> fan speed will be at max. if someting goes wrong with getting cpu temps
|
||||
thermal = -99
|
||||
fanmode = 100
|
||||
i = 0
|
||||
|
||||
# function to get cpu temperature on linux and macOS and decide on fan speed.
|
||||
def temp(thermal, fanmode):
|
||||
thermal = int(round(float(subprocess.check_output("cat /sys/class/thermal/thermal_zone0/temp", shell=True).rstrip())/1000,2))
|
||||
if thermal <= 20:
|
||||
fanmode = 0
|
||||
elif 20 < thermal <= 40:
|
||||
fanmode = 25
|
||||
elif 40 < thermal <= 60:
|
||||
fanmode = 50
|
||||
elif 60 < fanmode <= 70:
|
||||
fanmode = 75
|
||||
elif 70 < fanmode:
|
||||
fanmode = 100
|
||||
return thermal, fanmode
|
||||
|
||||
# main loop
|
||||
while True:
|
||||
# get cpu temp
|
||||
thermal, fanmode = temp(thermal, fanmode)
|
||||
if fanmode == 0 or fanmode == 25:
|
||||
GPIO.output(17, False)
|
||||
GPIO.output(18, True)
|
||||
elif fanmode == 50:
|
||||
GPIO.output(17, True)
|
||||
GPIO.output(18, False)
|
||||
elif fanmode == 75:
|
||||
GPIO.output(17, True)
|
||||
GPIO.output(18, True)
|
||||
else:
|
||||
GPIO.output(17, False)
|
||||
GPIO.output(18, False)
|
||||
# cpu temp will be updated every 5 seconds
|
||||
time.sleep(5)
|
||||
i += 1
|
||||
# log cpu temp and fan speed
|
||||
print("----- Run Nr.:", i, "\nCpu temperature measured: ", str(thermal) + "°C", "- Fanspeed: ", str(fanmode) + "%")
|
||||
# - Display the above listed stats using small display with buttons for modes
|
Loading…
Add table
Add a link
Reference in a new issue