Skip to content

Instantly share code, notes, and snippets.

@cftang0827
Created July 26, 2018 04:25
Show Gist options
  • Save cftang0827/1e28cc608792bd1434ad10c96c38f2fa to your computer and use it in GitHub Desktop.
Save cftang0827/1e28cc608792bd1434ad10c96c38f2fa to your computer and use it in GitHub Desktop.
A script that can measure rpi's temperature and clock speed
# coding=UTF-8
'''
Python rpi monitor program
Call vcgencmd in shell and get the temp info and cpu clock info
20180314
'''
import subprocess as sub
import time
import sys
def main():
while True:
process_temp = sub.Popen(['vcgencmd', 'measure_temp'], stdout=sub.PIPE)
process_clock = sub.Popen(['vcgencmd', 'measure_clock', 'arm'], stdout=sub.PIPE)
stdout_temp = process_temp.communicate()[0]
stdout_clock = process_clock.communicate()[0]
st_temp = str(stdout_temp)
st_clock = str(stdout_clock)
temp = float(st_temp.split('=')[1].split('\'')[0])
clock = float(st_clock.split('=')[1].strip().split('\\')[0])
print('The temperature of system = {} C'.format(temp), flush=True)
print('The CPU clock = {} GHz'.format((clock)/1000000000), flush=True)
sys.stdout.flush()
time.sleep(2)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment