#!/usr/bin/python2.7 -u
import RPi.GPIO as GPIO
import time
import subprocess
import sys
fanstatus = "Off"
# Use GPIO 18
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(18,GPIO.OUT)
# Infinite Loop
while True:
# Get the RasPi's CPU Temp
temp = subprocess.Popen(["/usr/local/bin/cputemp","temp"], stdout=subprocess.PIPE).communicate()[0].replace("C\n","")
# Default to verbose
service = False
# Start to cool at 43C
if float(temp) > 43.0 and fanstatus == "Off":
fanstatus = "On"
GPIO.output(18,GPIO.HIGH)
# Cool until we reach 38C
if float(temp) < 38.0 and fanstatus == "On":
fanstatus = "Off"
GPIO.output(18,GPIO.LOW)
# Be silent if we are starting at boot
for arg in sys.argv:
if arg == "service":
service = True
if service == False:
# Get the current date
date = subprocess.Popen(["/bin/date"], stdout=subprocess.PIPE).communicate()[0].replace("\n","")
sys.stdout.write('\rTemp: '+temp+'C, Fan: '+fanstatus+' (at '+date+') \b\b\b\b\b\b')
# Sleep for a bit so we aren't a cpu hog
time.sleep(6)
Comments