Skip to content

Instantly share code, notes, and snippets.

@dziban303
Last active May 23, 2022 00:10
Show Gist options
  • Save dziban303/a25175a462623d4f52b4c156e538b467 to your computer and use it in GitHub Desktop.
Save dziban303/a25175a462623d4f52b4c156e538b467 to your computer and use it in GitHub Desktop.
Raspberry Pi throttling checker with temperature and voltage measurements. Voltage colors will be accurate for Pi3B+/Zero 2W, maybe Zero, not Pi4
#!/bin/bash
#Flag Bits
UNDERVOLTED=0x1
CAPPED=0x2
THROTTLED=0x4
SOFT_TEMPLIMIT=0x8
HAS_UNDERVOLTED=0x10000
HAS_CAPPED=0x20000
HAS_THROTTLED=0x40000
HAS_SOFT_TEMPLIMIT=0x80000
#Text Colors
GREEN=`tput setaf 2`
RED=`tput setaf 1`
YELLOW=`tput setaf 3`
EMERG1=`tput setaf 91`
EMERG2=`tput setaf 127`
PLAID=`tput setaf 202`
BLUE=`tput setaf 27`
NC=`tput sgr0`
#Output Strings
GOOD="${GREEN}NO${NC}"
BAD="${RED}YES${NC}"
#Get Status, extract hex
STATUS=$(vcgencmd get_throttled)
STATUS=${STATUS#*=}
echo -n "Status: "
(($STATUS!=0)) && echo "${RED}${STATUS}${NC}" || echo "${GREEN}${STATUS}${NC}"
echo "Undervolted:"
echo -n " Now: "
((($STATUS&UNDERVOLTED)!=0)) && echo "${BAD}" || echo "${GOOD}"
echo -n " Run: "
((($STATUS&HAS_UNDERVOLTED)!=0)) && echo "${BAD}" || echo "${GOOD}"
echo "Throttled:"
echo -n " Now: "
((($STATUS&THROTTLED)!=0)) && echo "${BAD}" || echo "${GOOD}"
echo -n " Run: "
((($STATUS&HAS_THROTTLED)!=0)) && echo "${BAD}" || echo "${GOOD}"
echo "Frequency Capped:"
echo -n " Now: "
((($STATUS&CAPPED)!=0)) && echo "${BAD}" || echo "${GOOD}"
echo -n " Run: "
((($STATUS&HAS_CAPPED)!=0)) && echo "${BAD}" || echo "${GOOD}"
echo "Softlimit:"
echo -n " Now: "
((($STATUS&SOFT_TEMPLIMIT)!=0)) && echo "${BAD}" || echo "${GOOD}"
echo -n " Run: "
((($STATUS&HAS_SOFT_TEMPLIMIT)!=0)) && echo "${BAD}" || echo "${GOOD}"
#Temps
tempc=$(vcgencmd measure_temp | cut -c 6-8 | cut -d '.' -f1)
echo -n "Temperature: "
if [[ "$tempc" -lt "60" ]]; then
echo "$GREEN$tempc$NC°C"
elif [[ "$tempc" -lt "70" ]]; then
echo "$YELLOW$tempc$NC°C"
elif [[ "$tempc" -lt "80" ]]; then
echo "$RED$tempc$NC°C"
else [[ "$tempc" -gt "81" ]];
if [[ "$tempc" -lt "100" ]]; then
echo -e "\t$EMERG1 WARNING!$EMERG2 $tempc$RED°C$NC"
fi
echo -e "\t$EMERG1 Put the kettle on! You're over 100°C: $EMERG2$tempc°C to be precise."
fi
#Voltage
volt=$(vcgencmd measure_volts | cut -c 6-11)
echo -n "Voltage: "
if [[ "$volt" < "1.26" ]]; then
echo "$BLUE$volt$NC V ($BLUE Undervolted $NC)"
elif [[ "$volt" < "1.36" ]]; then
echo "$GREEN$volt$NC V"
elif [[ "$volt" < "1.46" ]]; then
echo "$YELLOW$volt$NC V"
else [[ "$volt" > "1.7" ]];
if [[ "$volt" < "1.8" ]]; then
echo -e "\t$RED WARNING!$EMERG2 $volt$REDV$NC V"
fi
echo -e "\t$EMERG1 Put the kettle on! You're over 1.8V: $EMERG2$volt V to be precise."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment