diff --git a/cpu_mqtt.py b/cpu_mqtt.py index efd31b2..9072599 100644 --- a/cpu_mqtt.py +++ b/cpu_mqtt.py @@ -6,63 +6,70 @@ from __future__ import division import subprocess, time, socket, os import paho.mqtt.client as paho +import config #get device host name - used in mqtt topic hostname = socket.gethostname() #mqtt server configuration -mqtt_host = "192.168.0.13" -mqtt_user = "homeassistant" -mqtt_password = "xyMaSokO123" -mqtt_port = "1883" -mqtt_topic_prefix = "masoko" +mqtt_host = config.mqtt_host +mqtt_user = config.mqtt_user +mqtt_password = config.mqtt_password +mqtt_port = config.mqtt_port +mqtt_topic_prefix = config.mqtt_topic_prefix def check_used_space(path): - st = os.statvfs(path) - free_space = st.f_bavail * st.f_frsize - total_space = st.f_blocks * st.f_frsize - used_space = int(100 - ((free_space / total_space) * 100)) - return used_space + st = os.statvfs(path) + free_space = st.f_bavail * st.f_frsize + total_space = st.f_blocks * st.f_frsize + used_space = int(100 - ((free_space / total_space) * 100)) + return used_space def check_cpu_load(): - #bash command to get cpu load from uptime command - p = subprocess.Popen("uptime", shell=True, stdout=subprocess.PIPE).communicate()[0] - cpu_load = p.split("average:")[1].split(",")[0].replace(' ', '') - return cpu_load + #bash command to get cpu load from uptime command + p = subprocess.Popen("uptime", shell=True, stdout=subprocess.PIPE).communicate()[0] + cpu_load = p.split("average:")[1].split(",")[0].replace(' ', '') + return cpu_load + +def check_voltage(): + full_cmd = "vcgencmd measure_volts | cut -f2 -d= | sed 's/000//'" + return subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE).communicate()[0] def check_cpu_temp(): - #bash command to get rpi cpu temp - full_cmd = "/opt/vc/bin/vcgencmd measure_temp" - p = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE).communicate()[0] - cpu_temp = p.replace('\n', ' ').replace('\r', '').split("=")[1].split("'")[0] - return cpu_temp + full_cmd = "/opt/vc/bin/vcgencmd measure_temp" + p = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE).communicate()[0] + cpu_temp = p.replace('\n', ' ').replace('\r', '').split("=")[1].split("'")[0] + return cpu_temp + +def check_sys_clock_speed(): + full_cmd = "awk '{printf (\"%0.0f\",$1/1000); }'