Created
July 26, 2018 04:25
-
-
Save cftang0827/1e28cc608792bd1434ad10c96c38f2fa to your computer and use it in GitHub Desktop.
A script that can measure rpi's temperature and clock speed
This file contains hidden or 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
# 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