A quick and dirty terminal application that continuously prints the six second rolling average tempurate and fan speed of a RaspberryPi 5.
Created
October 23, 2024 03:16
-
-
Save James-Ansley/b05b38a6e12fb6f20182a99088d29024 to your computer and use it in GitHub Desktop.
A quick Pi5 Temperature monitor
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
import time | |
import statistics | |
from collections import deque | |
TEMP_PATH = "/sys/devices/virtual/thermal/thermal_zone0/temp" | |
FAN_PATH = "/sys/class/thermal/cooling_device0/cur_state" | |
def main(): | |
temp = deque(maxlen=3) | |
while True: | |
temp.append(get_temp()) | |
av_temp = statistics.mean(temp) | |
print(f"Temp: {av_temp:.1f}C; Fan: {get_fan_speed()}", end="\r") | |
time.sleep(2) | |
def get_temp() -> int: | |
with open(TEMP_PATH, "r") as f: | |
data = f.read() | |
return int(data) // 1000 | |
def get_fan_speed() -> str: | |
with open(FAN_PATH, "r") as f: | |
return f.read().strip() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment