From f23929f0a2c95acc374be3862b0bca3cc20a6fde Mon Sep 17 00:00:00 2001 From: Masoko Date: Thu, 24 Oct 2024 21:28:28 +0300 Subject: [PATCH] Feature/rpi power status (#147) * rpi power status --- src/rpi-cpu2mqtt.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/rpi-cpu2mqtt.py b/src/rpi-cpu2mqtt.py index dedf7fe..8c565e9 100644 --- a/src/rpi-cpu2mqtt.py +++ b/src/rpi-cpu2mqtt.py @@ -94,18 +94,17 @@ def check_memory(): def check_rpi_power_status(): - full_cmd = "vcgencmd get_throttled | awk -F= '{print $2}'" - power_status = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE).communicate()[0] - - if power_status: - if power_status == "0x0": - power_status = "OK" + try: + full_cmd = "vcgencmd get_throttled | cut -d= -f2" + throttled = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE).communicate()[0] + throttled = throttled.decode('utf-8').strip() + + if throttled == "0x0": + return "OK" else: - power_status = "KO" - else: - power_status = "NA" - - return power_status + return "KO" + except Exception as e: + return "Error: " + str(e) def check_cpu_temp():