bpi-cm5-cpu-thermal-throttling-monitor-7.ino
Python script reading thermal sensors of the Amlogic A311D2 SoC and alerting in case of overheating.
Uses the 'psutil' module and direct access to thermal sysfs files. The BPI-CM5 requires good passive or active cooling. This script checks CPU frequency to detect throttling. Run with sudo for full sensor access.
bpi-cm5-cpu-thermal-throttling-monitor-7.ino
#!/usr/bin/env python3
import os
import time
import subprocess
# Path to thermal zones for Amlogic A311D2 (adjust if needed based on kernel version)
# Usually /sys/class/thermal/thermal_zone*/temp
TEMP_PATH = "/sys/class/thermal/thermal_zone0/temp"
def get_cpu_temp():
try:
with open(TEMP_PATH, 'r') as f:
return int(f.read().strip()) / 1000.0
except Exception:
return -1
def get_cpu_freq():
try:
result = subprocess.run(["grep", "cpu MHz", "/proc/cpuinfo"], capture_output=True, text=True)
lines = result.stdout.split('\n')
freqs = [float(line.split(':')[1].strip()) for line in lines if 'cpu MHz' in line]
return max(freqs) if freqs else 0
except Exception:
return 0
print("Monitoring BPI-CM5 A311D2 Thermal Status...")
while True:
temp = get_cpu_temp()
freq = get_cpu_freq()
status = "NORMAL"
if temp > 80.0:
status = "CRITICAL - THROTTLING LIKELY"
elif temp > 70.0:
status = "WARNING"
print(f"Temp: {temp:.1f} C | Max Freq: {freq:.0f} MHz | Status: {status}")
time.sleep(5)