Created
January 28, 2015 13:25
-
-
Save victorchee/52b8c727b0650d8808ae to your computer and use it in GitHub Desktop.
树莓派获取当前CPU和GPU温度。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 import commands | |
2 | |
3 def get_cpu_temperature(): | |
4 temperatureFile = open("/sys/class/thermal/thermal_zone0/temp") | |
5 cpu_temperature = temperatureFile.read() | |
6 temperatureFile.close() | |
7 return float(cpu_temperature)/1000 | |
8 | |
9 def get_gpu_temperature(): | |
10 gpu_temperature = commands.getoutput('/opt/vc/bin/vcgencmd measure_temp').replace('temp=', '').replace('\'C', '') | |
11 return float(gpu_temperature) | |
12 | |
13 if __name__ == '__main__': | |
14 print "CPU temperature: ", str(get_cpu_temperature()) | |
15 print "GPU temperature: ", str(get_gpu_temperature()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment