diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..f5a3e99 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,16 @@ +# EditorConfig is awesome: http://EditorConfig.org + +# top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +charset = utf-8 +end_of_line = lf +indent_style = space +indent_size = 4 +insert_final_newline = true +trim_trailing_whitespace = true +[LICENSE] +indent_style = none +indent_size = none diff --git a/src/rpi-cpu2mqtt.py b/src/rpi-cpu2mqtt.py index 06387e8..c5b4bec 100644 --- a/src/rpi-cpu2mqtt.py +++ b/src/rpi-cpu2mqtt.py @@ -19,21 +19,21 @@ import update hostname = socket.gethostname() def check_wifi_signal(format): - try: + try: full_cmd = "ls /sys/class/ieee80211/*/device/net/" interface = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE).communicate()[0].strip().decode("utf-8") full_cmd = "/sbin/iwconfig {} | grep -i quality".format(interface) wifi_signal = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE).communicate()[0] - + if format == 'dbm': wifi_signal = wifi_signal.decode("utf-8").strip().split(' ')[4].split('=')[1] else: wifi_signal = wifi_signal.decode("utf-8").strip().split(' ')[1].split('=')[1].split('/')[0] wifi_signal = round((int(wifi_signal) / 70)* 100) - + except Exception: wifi_signal = 0 - + return wifi_signal @@ -42,7 +42,7 @@ def check_used_space(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 @@ -52,7 +52,7 @@ def check_cpu_load(): cpu_load = str(p).split("average:")[1].split(", ")[0].replace(' ', '').replace(',', '.') cpu_load = float(cpu_load) / int(cores) * 100 cpu_load = round(float(cpu_load), 1) - + return cpu_load @@ -63,7 +63,7 @@ def check_voltage(): voltage = voltage.strip()[:-1] except Exception: voltage = 0 - + return voltage.decode('utf8') @@ -71,7 +71,7 @@ def check_swap(): full_cmd = "free -t |grep -i swap | awk 'NR == 1 {print $3/$2*100}'" swap = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE).communicate()[0] swap = round(float(swap.decode("utf-8").replace(",", ".")), 1) - + return swap @@ -79,7 +79,7 @@ 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.decode("utf-8").replace(",", "."))) - + return memory @@ -90,19 +90,19 @@ def check_cpu_temp(): cpu_temp = p.decode("utf-8").strip() except Exception: cpu_temp = 0 - + return cpu_temp def check_sys_clock_speed(): full_cmd = "awk '{printf (\"%0.0f\",$1/1000); }'