简体   繁体   中英

Check from Python script Raspberry´s power status

Is there an equivalent to the yellow lightning on screen, or the red PWR LED blinking, that can be used from a Python script to know if there are power issues with a Raspberry?

Thanks!

With help from @MarkSetchell (thanks!), this works. I´ve tested it on a RPI 3B+ with some power supply issues:

import subprocess

pt = subprocess.Popen(['/opt/vc/bin/vcgencmd', 'get_throttled'],stdout=subprocess.PIPE,stderr=subprocess.PIPE)
(res,err) = pt.communicate()
res = res.decode().split("=")[1]
res = res.rstrip("\n")
print ("Current Power Issues?    = ",(int(res,0) & 0x01) == 0x01)
print ("Any Power issues before? = ",(int(res,0) & 0x50000) == 0x50000)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM