I made a piece of code for taking the cpu temp for my rpi and if it's more than 60 C to send a signal on GPIO port 7 and if it's not more than 60 C to not send the signal on the port but I get this error:
File "tempgate.py", line 17
def FanController(CPU_temp) :
^
SyntaxError: invalid syntax
The file is:
#Module import and variables
import getinfo
import RPi.GPIO as GPIO
import time
import atexit
import datetime
CPU_temp = getinfo.getCPUtemperature
#Start info
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
print("[LOG] [" + st + "] Program has started")
#Setup and definitions
try:
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
def FanController(CPU_temp) :
CPU_temp = int(float(CPU_temp))
print(CPU_temp)
if(int(CPU_temp) > int(60)) :
GPIO.setup(7, GPIO.OUT)
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
print("[LOG] [" + st + "] Fan is now on")
time.sleep(5)
else :
GPIO.setup(7, GPIO.IN)
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
print("[LOG] [" + st + "] Fan is now off")
time.sleep(5)
#main app
while True :
CPU_temp = getinfo.getCPUtemperature()
print("[LOG] [" + st + "] Cpu CPU_temp is: " + CPU_temp)
FanController(CPU_temp)
GPIO.cleanup()
atexit.register(GPIO.cleanup())