🛠 Surveillance thermique et fréquence sous contrainte 256 Mo
Objectives
- Read temperature, frequency, and firmware throttling flags: the BCM2835 throttles above 85 °C or in case of undervoltage.
- Build a lightweight history (the 256 MB is not waiting for a real TSDB) with cron and RRD or CSV.
- Set up an alert when the maximum frequency drops below 700 MHz.
Hardware
- Model A, ideally in a case (the point of this model: low heating in a sealed enclosure).
- Quality 5 V micro-USB power supply — undervoltage throttles the frequency as much as heat does.
- Optional: adhesive heatsink.
Complete code
#!/usr/bin/env bash
# /usr/local/bin/thermonut.sh — un point de mesure par minute
T=$(vcgencmd measure_temp | cut -d= -f2 | tr -d "'C")
F=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq)
U=$(vcgencmd get_throttled | cut -d= -f2)
echo "$(date -Is),$T,$F,$U" >> /var/log/thermonut.csv
# Bit 0 de throttled = sous-tension ; bits 16-18 = bridage fréquence atteinte
[ $(( 0x$U & 0x10000 )) -ne 0 ] && logger -p user.warning "THERMIQUE: bridage détecté"
# /etc/cron.d/thermonut (ligne unique)
* * * * * root /usr/local/bin/thermonut.sh
# Consulter
vcgencmd get_throttled && tail /var/log/thermonut.csv
Expected verification
The CSV fills up every minute; under load (yes > /dev/null &) the temperature rises and, at the 85 °C threshold, scaling_cur_freq drops below 700000 kHz while the get_throttled flag lights up. >
Common errors
- Interpreting
get_throttled=0x50000as a failure: these bits store a past event, a reboot resets them to zero. - Blaming heat when only the undervoltage bit (0x1) is active: it is the power supply or the cable.
- Storing history in RAM (/tmp): everything disappears on reboot, and the SD card does not like second-by-second writes.
- Using
bc/heavy tools for arithmetic: bash is enough, save the 256 MB.
Other tutorials for this board
Code examples for this board
led_blink.pyPythonbutton_led.pyPythonservo_sweep.pyPythondht_temp.pyPythonoled_i2c.pyPythonmcp3008_read.pyPython