-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpu-temp.py
36 lines (30 loc) · 1.01 KB
/
cpu-temp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python
""" Measure and report temperature of Raspberry Pi"""
from __future__ import print_function
import os
import sys
import time
PROG_VER = '1.5'
PROG_NAME = os.path.basename(__file__)
SLEEP_SECONDS = 5 # seconds between readings
def measure_temp():
""" Read vcgencmd file and get temperature reading into variable"""
temp_reading = os.popen("vcgencmd measure_temp").readline()
return float(temp_reading.replace("temp=", "").replace("'C\n", ""))
def report_temp():
""" print cpu temperature then sleep"""
while True:
print("CPU at %s'C Wait %i sec ..." %
(measure_temp(), SLEEP_SECONDS))
time.sleep(SLEEP_SECONDS)
print('{} ver {}'.format(PROG_NAME, PROG_VER))
print("Measuring RPI CPU Temperature Every %i seconds" % SLEEP_SECONDS)
print("Press cntrl-c to Exit")
try:
report_temp()
except KeyboardInterrupt:
print("")
print("User Exited with Control-C")
print('{} ver {}'.format(PROG_NAME, PROG_VER))
print('Bye ...')
sys.exit(0)