2 Jan 2022, 15:04

@pitch64 j'ai essayer d'intégrer les lignes mais cela ne fonctionne pas 😧 j'ai le message "command no found" à chaque ligne
est-ce que je l'ai mal intégré dans le code ?

#!/usr/bin/env python3
# Author: Edoardo Paolo Scalafiotti
import os
from time import sleep
import signal
import sys
import RPi.GPIO as GPIO
pin = 18 # The pin ID, edit here to change it
maxTMP = 55 # The maximum temperature in Celsius after which we trigger the fan
def setup():
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(pin, GPIO.OUT)
    GPIO.setwarnings(False)
    return()
def getCPUtemperature():
    temp = os.popen("cat /sys/class/thermal/thermal_zone0/temp").readline()
    temp = temp[0:2]
    val = float(temp)
    temp =(res.replace("temp=","").replace("'C\n",""))
    print("temp is {0}".format(temp)) #Uncomment here for testing
    return temp
def fanON():
    setPin(True)
    return()
def fanOFF():
    setPin(False)
    return()
def getTEMP():
    CPU_temp = float(getCPUtemperature())
    if CPU_temp>maxTMP:
        fanON()
    if CPU_temp<maxTMP-5:
        fanOFF()
    return()
def setPin(mode): # A little redundant function but useful if you want to add logging
    GPIO.output(pin, mode)
    return()
try:
    setup() 
    while True:
        sleep(5) # Read the temperature every 5 sec, increase or decrease this limit if you want
        getTEMP()
except: 
        GPIO.cleanup() # resets all GPIO ports used by this program