Created
February 19, 2021 11:00
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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