mirror of
https://github.com/clockworkpi/DevTerm.git
synced 2025-12-12 18:28:50 +01:00
add devterm_fan_daemon_cm4 script
This commit is contained in:
parent
95e50bedce
commit
24d97cc2ae
26
Code/devterm_fan_daemon_cm4/README.md
Normal file
26
Code/devterm_fan_daemon_cm4/README.md
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# Fan control daemon for devterm cm4(rpi os)
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
**Devterm is pre-installed this package, so devterm cm4 users do not need to repeat the installation steps**
|
||||||
|
|
||||||
|
```
|
||||||
|
wget -O - https://raw.githubusercontent.com/clockworkpi/apt/main/debian/KEY.gpg | sudo apt-key add -
|
||||||
|
echo "deb https://raw.githubusercontent.com/clockworkpi/apt/main/debian/ stable main" | sudo tee -a /etc/apt/sources.list.d/clockworkpi.list
|
||||||
|
|
||||||
|
sudo apt update && apt install -y devterm-fan-temp-daemon-cm4
|
||||||
|
```
|
||||||
|
|
||||||
|
## Change the threshold temperature
|
||||||
|
|
||||||
|
Edit `/usr/local/bin/temp_fan_daemon.py`
|
||||||
|
|
||||||
|
line starts with `MAX_TEMP=80`
|
||||||
|
|
||||||
|
For devterm cm4(rpi os) the recommended MAX_TEMP is in range 60-80
|
||||||
|
|
||||||
|
then restart systemd service to take effect
|
||||||
|
|
||||||
|
`sudo systemctl restart devterm-fan-temp-daemon`
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=devterm raspberry pi cm4 fan control daemon
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
ExecStart=/usr/bin/python3 /usr/local/bin/temp_fan_daemon.py
|
||||||
|
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
51
Code/devterm_fan_daemon_cm4/temp_fan_daemon.py
Normal file
51
Code/devterm_fan_daemon_cm4/temp_fan_daemon.py
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
###devterm raspberry pi fan control daemon
|
||||||
|
import os
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
def isDigit(x):
|
||||||
|
try:
|
||||||
|
float(x)
|
||||||
|
return True
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def measure_temp():
|
||||||
|
temp = os.popen("/opt/vc/bin/vcgencmd measure_temp").readline()
|
||||||
|
temp2 = temp.replace("temp=","")
|
||||||
|
temp3 = temp2.replace("'C","").strip()
|
||||||
|
#print(temp3)
|
||||||
|
if isDigit(temp3):
|
||||||
|
return float(temp3)
|
||||||
|
else:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
def init_fan_gpio():
|
||||||
|
os.popen("gpio mode 17 out")
|
||||||
|
|
||||||
|
def fan_on():
|
||||||
|
init_fan_gpio()
|
||||||
|
os.popen("gpio write 17 1")
|
||||||
|
|
||||||
|
def fan_off():
|
||||||
|
init_fan_gpio()
|
||||||
|
os.popen("gpio write 17 0")
|
||||||
|
|
||||||
|
|
||||||
|
MAX_TEMP=80
|
||||||
|
|
||||||
|
init_fan_gpio()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
temp = measure_temp()
|
||||||
|
if(temp > MAX_TEMP):
|
||||||
|
fan_on()
|
||||||
|
else:
|
||||||
|
fan_off()
|
||||||
|
|
||||||
|
time.sleep(5)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user