Skip to content

Instantly share code, notes, and snippets.

@morriq
Last active December 17, 2020 01:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morriq/acd9de3112a8d991b96d79699418f891 to your computer and use it in GitHub Desktop.
Save morriq/acd9de3112a8d991b96d79699418f891 to your computer and use it in GitHub Desktop.
#!/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