您的位置:首页 > 其它

树莓派-获取CPU和GPU温度

2015-02-04 17:32 387 查看
CPU的温度可以从一个系统临时文件中读取:/sys/class/thermal/thermal_zone0/temp

GPU温度也可以从一个文件中读取:/opt/vc/bin/vcgencmd measure_temp

import commands

def get_cpu_temp():
tempFile = open( "/sys/class/thermal/thermal_zone0/temp" )
cpu_temp = tempFile.read()
tempFile.close()
return float(cpu_temp)/1000

def get_gpu_temp():
gpu_temp = commands.getoutput( '/opt/vc/bin/vcgencmd measure_temp' ).replace( 'temp=', '' ).replace( '\'C', '' )
return  float(gpu_temp)

def main():
print "CPU temp: ", str(get_cpu_temp())
print "GPU temp: ", str(get_gpu_temp())

if __name__ == '__main__':
main()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: