Skip to content

Instantly share code, notes, and snippets.

@elmcrest
Created February 19, 2021 11:00
Show Gist options
  • Save elmcrest/c6ed5da14e970024b577ee53dd1a29ca to your computer and use it in GitHub Desktop.
Save elmcrest/c6ed5da14e970024b577ee53dd1a29ca to your computer and use it in GitHub Desktop.
simple script to wrap raspberry pi health wrap, tested on ubuntu 20.04 on a model 3 B.
#!/usr/bin/env python3
import subprocess
HEALTH_CHECK = 'sudo vcgencmd get_throttled'
MESSAGES = {
0: 'Under-voltage!',
1: 'ARM frequency capped!',
2: 'Currently throttled!',
3: 'Soft temperature limit active',
16: 'Under-voltage has occurred since last reboot.',
17: 'Throttling has occurred since last reboot.',
18: 'ARM frequency capped has occurred since last reboot.',
19: 'Soft temperature limit has occurred'
}
print("Checking...")
output = subprocess.check_output(HEALTH_CHECK, shell=True)
decoded = bin(int(output.decode("utf-8").split('=')[1], 0))
warnings = 0
code_len = len(decoded)
for idx, el in enumerate(decoded):
if decoded[code_len-idx-1] == "1":
print(f"WARNING: {MESSAGES[idx]}\n")
warning = 1
if warnings == 0:
print("Looking good!")
else:
print("Houston, we may have a problem!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment