终端命令1:
1 2 |
pi@raspberrypi2:~ $ cat /sys/class/thermal/thermal_zone0/temp 39704 |
终端命令2:
1 2 |
pi@raspberrypi2:~ $ vcgencmd measure_temp temp=45.1'C |
python 函数1:
1 2 3 4 5 6 |
def getCPUtemperature(): res = os.popen('vcgencmd measure_temp').readline() return res.replace("temp=","").replace("'C\n","") CPU_temp = getCPUtemperature() print('CPU Temperture = ' + CPU_temp) |
python 函数2:
1 2 |
def getCPUtemperature_2(): return os.popen('/opt/vc/bin/vcgencmd measure_temp').read()[5:9] |
python 函数3:
1 2 3 4 5 |
def getCPUtemperature_3(): with open("/sys/class/thermal/thermal_zone0/temp") as tempFile: res = tempFile.read() res=str(float(res)/1000) return res |