我写了这段代码,用来检查设备是否是RPI并输出温度。
import os
def CheckIfPi():
try:
res = os.popen('vcgencmd measure_temp').readline()
return float((res.replace("temp=","").replace("'C\n","")))
except:
return 0
def ReturnTemperature():
if CheckIfPi() > 0:
print("The temperature of the Pi is: ", CheckIfPi())
else:
print("This is not a Pi.")
ReturnTemperature()
我得到的输出:
/bin/sh: 1: vcgencmd: not found
This is not a Pi.
我没想到的输出是/bin/sh: 1: vcgencmd: not found