I'm trying to make an install script for the Deskpi Fan case.
While also knowing pretty much nothing about python.
(this is an import from the thread that was in the wrong https://forum.libreelec.tv/thread/25435-trying-to-make-an-install-script-for-deskpi-pro-case/?postID=167915#post167915 thread)
I'm having a hard time with this code:
import serial
import time
import subprocess
ser=serial.Serial("/dev/ttyUSB0", 9600, timeout=30)
try: while True: if ser.isOpen(): cpu_temp=subprocess.getoutput("/opt/vc/bin/vcgencmd measure_temp" | "sed -e "s/temp=//" -e "s/\..*'/ /") cpu_temp=int(cpu_temp.split('.')[0])
if cpu_temp < 40:
ser.write(b'pwm_000')
elif cpu_temp > 40 and cpu_temp < 50:
ser.write(b'pwm_025')
elif cpu_temp > 50 and cpu_temp < 65:
ser.write(b'pwm_050')
elif cpu_temp > 65 and cpu_temp < 75:
ser.write(b'pwm_075')
elif cpu_temp > 75:
ser.write(b'pwm_100')
except KeyboardInterrupt:
ser.write(b'pwm_000')
ser.close()
Display More
I'm pretty sure it's a formatting issue, but I can't seem to figure this part out:
try:
while True:
if ser.isOpen():
cpu_temp=subprocess.getoutput("/opt/vc/bin/vcgencmd measure_temp" | "sed -e "s/temp=//" -e "s/\..*'/ /")
cpu_temp=int(cpu_temp.split(.)[0])
I keep getting errors, regardless of my changes. I get "unsupported operand type(s) for "|:" 'str' and 'str' " or just "syntax errors".
I also tried:
cpu_temp=subprocess.getoutput("/opt/vc/bin/vcgencmd.measure_temp") | "grep" "sed -e s/temp=// -e s/\..*'/ /"
cpu_temp=float(int(cpu_temp.split('.')[0])
Looks like the error I was getting was because I was trying to take a LITERAL(real number) into an Integer.
You can't do that, so you have to turn it into a FLOAT.
Adding "float(" in-front of the other code I had(int(cpu_tempt.split....) "fixed" it.
But now I'm getting an error here:
Honestly I can barely read this, it's a little advanced for me. Can someone please point me in the right direction?
Anything will help.
Thanks in advance!