From d81563b4513aedea5337db04ba0461ced2531eb3 Mon Sep 17 00:00:00 2001 From: Hristo Jelev Date: Thu, 23 Sep 2021 15:47:08 +0300 Subject: [PATCH] fixed memory % bug --- src/rpi-cpu2mqtt.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/rpi-cpu2mqtt.py b/src/rpi-cpu2mqtt.py index c82329f..fe3d6ca 100644 --- a/src/rpi-cpu2mqtt.py +++ b/src/rpi-cpu2mqtt.py @@ -31,10 +31,13 @@ def check_cpu_load(): return cpu_load def check_voltage(): - full_cmd = "vcgencmd measure_volts | cut -f2 -d= | sed 's/000//'" - voltage = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE).communicate()[0] - voltage = voltage.strip()[:-1] - return voltage + try: + full_cmd = "vcgencmd measure_volts | cut -f2 -d= | sed 's/000//'" + voltage = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE).communicate()[0] + voltage = voltage.strip()[:-1] + except: + voltage = 0 + return voltage def check_swap(): full_cmd = "free -t | awk 'NR == 3 {print $3/$2*100}'" @@ -45,7 +48,7 @@ def check_swap(): def check_memory(): full_cmd = "free -t | awk 'NR == 2 {print $3/$2*100}'" memory = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE).communicate()[0] - memory = round(float(memory), 1) + memory = round(float(memory.decode("utf-8").replace(",","."))) return memory def check_cpu_temp():