1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
import serial
import os
import logging
import time
import subprocess
def chg(o):
# sortie: stdout
logging.basicConfig(
filename='ctlfan.log',
level=logging.INFO,
format='%(asctime)s %(levelname)s - %(message)s',
datefmt='%d/%m/%Y %H:%M:%S',
)
oo = o
logging.info(oo)
temp=int(float(oo) +.5)
ser = serial.Serial('/dev/ttyUSB0', 9600 , timeout=1)
ser.close()
ser.open()
ser.write("?")
lecture=ser.readline()
if "s10" in lecture :
if temp > 60 :
ser.write("s11")
logging.info(oo + " S1 ON")
elif "s11" in lecture :
if temp < 50 :
ser.write("s10")
logging.info(oo + " S1 OFF")
ser.close()
return 0
from subprocess import *
def get_status_output(cmd, input=None, cwd=None, env=None):
pipe = subprocess.Popen(cmd, shell=True, cwd=cwd, env=env, stdout=PIPE, stderr=STDOUT)
output, errors = pipe.communicate(input=input)
assert not errors
return pipe.returncode, output
def main():
status, output = get_status_output('echo pswrd | sudo -S aticonfig --od-gettemperature | grep Temperature | cut -c43-46')
chg(output)
return 0
if __name__ == '__main__':
main() |
Partager