🛠 Premier script Python : santé de la carte
Objectives
Write a first Python script that displays the health of the ODROID-XU4: the 8 cores of the Exynos5422 (4 Cortex-A15 up to 2.0 GHz + 4 Cortex-A7 up to 1.4 GHz, big.LITTLE) and the temperatures of the thermal sensors exposed by the mainline kernel. Python 3 is preinstalled on Armbian.
Hardware
- ODROID-XU4 running Armbian Debian/Ubuntu (kernel 6.6.x), terminal or SSH access
- No electronic components: everything goes through /sys and /proc
Complete code
#!/usr/bin/env python3
"""sante.py — inventaire CPU big.LITTLE + temperatures sur XU4."""
import glob
def lire(chemin):
try:
with open(chemin) as f:
return f.read.strip
except OSError:
return "n/a"
print("== CPUs en ligne ==")
print(lire("/sys/devices/system/cpu/online")) # attendu: 0-7
print("== Frequences max par cluster (kHz) ==")
for p in sorted(glob.glob("/sys/devices/system/cpu/cpufreq/policy*/cpuinfo_max_freq")):
print(p.split("/")[5], lire(p)) # 2000000 (A15) / 1400000 (A7)
print("== Temperatures ==")
for z in sorted(glob.glob("/sys/class/thermal/thermal_zone*")):
t = lire(z + "/type")
v = lire(z + "/temp")
if v != "n/a":
print(f"{t}: {int(v)/1000:.1f} C")
Run: python3 sante.py.
Expected output
The script displays 0-7 (the 8 cores are utilized in HMP under mainline), two frequency policies with maximums of 2000000 kHz (A15 cluster) and 1400000 kHz (A7 cluster), followed by one temperature line per sensor (cpu0 to cpu3 and gpu).
Common errors
- Running with
pythoninstead ofpython3: depending on the image,pythondoes not always exist. - Looking for
/proc/cpuinfo"MHz" per cluster: under big.LITTLE HMP, it is better to read the cpufreq policies. - Forgetting that temperatures are in milli-degrees: you must divide by 1000.
- Worrying about a missing sensor: not all thermal_zones carry the same type depending on the kernel.
Other tutorials for this board
Code examples for this board
clignotante.pyPythonbouton-gpio.pyPythoncapteur-i2c.shBashsurveillance-temperature.shBashcapteur-dht11.pyPythonservo-pwm-sysfs.shBash