Raspberry Pi - Controlando a temperatura do Raspberry Pi: mudanças entre as edições
De Área31 Hackerspace
(Criou página com '=== Controlando a temperatura do Raspberry Pi === Por questões de segurança, adicione um script que irá verificar a temperatura a cada 5 minutos e desligar o Raspberry Pi c...') |
Sem resumo de edição |
||
Linha 11: | Linha 11: | ||
# Get the reading from the sensor and strip the non-number parts | # Get the reading from the sensor and strip the non-number parts | ||
SENSOR="$(vcgencmd measure_temp | cut -d "=" -f2 | cut -d "'" -f1)" | SENSOR="$(vcgencmd measure_temp | cut -d "=" -f2 | cut -d "'" -f1 | cut -d '.' -f1)" | ||
# -gt only deals with whole numbers, so round it. | # -gt only deals with whole numbers, so round it. | ||
TEMP="$(printf "%.0f\n" ${SENSOR})" | TEMP="$(printf "%.0f\n" ${SENSOR})" | ||
Linha 34: | Linha 34: | ||
Configure o Crontab para executar o script a cada 5 minutos: | Configure o Crontab para executar o script a cada 5 minutos: | ||
*/5 * * * * /usr/bin/tempcheck | */5 * * * * /usr/bin/tempcheck | ||
Edição das 10h06min de 22 de agosto de 2014
Controlando a temperatura do Raspberry Pi
Por questões de segurança, adicione um script que irá verificar a temperatura a cada 5 minutos e desligar o Raspberry Pi caso exceda 78ºC.
vi /usr/bin/tempcheck
#!/bin/sh # This script reads the Broadcom SoC temperature value and shuts down if it # exceeds a particular value. # 80ºC is the maximum allowed for a Raspberry Pi. # Get the reading from the sensor and strip the non-number parts SENSOR="$(vcgencmd measure_temp | cut -d "=" -f2 | cut -d "'" -f1 | cut -d '.' -f1)" # -gt only deals with whole numbers, so round it. TEMP="$(printf "%.0f\n" ${SENSOR})" # How hot will we allow the SoC to get? MAX="78" if [ "${TEMP}" -gt "${MAX}" ] ; then # This will be mailed to root if called from cron echo "${TEMP}ºC is too hot!" # Send a message to syslog /usr/bin/logger "Shutting down due to SoC temp ${TEMP}." # Halt the box /sbin/shutdown -h now else exit 0 fi
Dê permissão de execução:
chmod +x /usr/bin/tempcheck
Configure o Crontab para executar o script a cada 5 minutos:
*/5 * * * * /usr/bin/tempcheck