Last active
December 17, 2020 01:45
-
-
Save morriq/acd9de3112a8d991b96d79699418f891 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import sys | |
import time | |
from gpiozero import LED # doc: https://gpiozero.readthedocs.io/ | |
from systemd import journal | |
# define the GPIO to control the transistor's B pin | |
fan = LED(17) | |
def cpu_temp(): | |
with open("/sys/class/thermal/thermal_zone0/temp", 'r') as f: | |
return float(f.read())/1000 | |
# close fan at begining | |
is_close = True | |
fan.off() | |
while True: | |
temp = cpu_temp() | |
if is_close: | |
if temp > 55.0: # upper bound to turn on the fan | |
journal.send("{} {} {}".format(time.ctime(), temp, 'Fan ON')) | |
fan.on() | |
is_close = False | |
else: | |
if temp < 48.0: # lower bound to turn off the fan | |
journal.send("{} {} {}".format(time.ctime(), temp, 'Fan OFF')) | |
fan.off() | |
is_close = True | |
time.sleep(2.0) | |
journal.send("{} {}".format(time.ctime(), temp)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment