Skip to content

Instantly share code, notes, and snippets.

@aallan
Last active March 17, 2024 04:42
Show Gist options
  • Star 47 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save aallan/0b03f5dcc65756dde6045c6e96c26459 to your computer and use it in GitHub Desktop.
Save aallan/0b03f5dcc65756dde6045c6e96c26459 to your computer and use it in GitHub Desktop.
Script to parse the output of the 'vcgencmd get_throttled' command on a Raspberry Pi
#!/bin/bash
# https://retropie.org.uk/forum/topic/2295/runcommand-warning-if-voltage-temperature-throttling
#Flag Bits
UNDERVOLTED=0x1
CAPPED=0x2
THROTTLED=0x4
HAS_UNDERVOLTED=0x10000
HAS_CAPPED=0x20000
HAS_THROTTLED=0x40000
#Text Colors
GREEN=`tput setaf 2`
RED=`tput setaf 1`
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}"
@JsBergbau
Copy link

Improved version implementing softlimit on the B+, source mschlenstedt/Loxberry#952

#!/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`
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}"

@spikopath
Copy link

Thank you so much for this :)

@nigeljohnson73
Copy link

This errors for me on my Raspberry Pi Zero WH running 20190926 of Rasbian:

pi@gstation1:~ $ sh status.sh
Status: status.sh: 28: status.sh: 0x0!=0: not found
0x0
Undervolted:
   Now: status.sh: 32: status.sh: Syntax error: word unexpected (expecting ")")
pi@gstation1:~ $ 

What am I missing?

@JsBergbau
Copy link

You have to run bash status.sh

@mcmellow
Copy link

mcmellow commented Nov 9, 2020

Thanks very much for this script.

@rauhmaru
Copy link

Awesome! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment