Skip to content

Commit

Permalink
Merge pull request #46 from MaxVRAM/non-pi-os-patch
Browse files Browse the repository at this point in the history
Replaced vcgencmd temperature with generic #45
  • Loading branch information
Sennevds authored Jul 21, 2020
2 parents c25092f + 35c1ad6 commit cda313b
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions src/system_sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import psutil
import pytz
import yaml
import csv
from pytz import timezone

try:
Expand All @@ -24,6 +25,14 @@
UTC = pytz.utc
DEFAULT_TIME_ZONE = None

# Get OS information
OS_DATA = {}
with open("/etc/os-release") as f:
reader = csv.reader(f, delimiter="=")
for row in reader:
if row:
OS_DATA[row[0]] = row[1]

mqttClient = None
SYSFILE = "/sys/devices/platform/soc/soc:firmware/get_throttled"
WAIT_TIME_SECONDS = 60
Expand Down Expand Up @@ -130,10 +139,16 @@ def get_updates():
return str(cache.get_changes().__len__())


# Temperature method depending on system distro
def get_temp():
temp = check_output(["vcgencmd", "measure_temp"]).decode("UTF-8")
return str(findall("\d+\.\d+", temp)[0])

temp = "";
if "rasp" in OS_DATA["ID"]:
reading = check_output(["vcgencmd", "measure_temp"]).decode("UTF-8")
temp = str(findall("\d+\.\d+", reading)[0])
else:
reading = check_output(["cat", "/sys/class/thermal/thermal_zone0/temp"]).decode("UTF-8")
temp = str(reading[0] + reading[1] + "." + reading[2])
return temp

def get_disk_usage(path):
return str(psutil.disk_usage(path).percent)
Expand All @@ -152,17 +167,16 @@ def get_swap_usage():


def get_wifi_strength(): # check_output(["/proc/net/wireless", "grep wlan0"])
return (
check_output(
[
"bash",
"-c",
"cat /proc/net/wireless | grep wlan0: | awk '{print int($4)}'",
]
)
.decode("utf-8")
.rstrip()
)
wifi_strength_value = check_output(
[
"bash",
"-c",
"cat /proc/net/wireless | grep wlan0: | awk '{print int($4)}'",
]
).decode("utf-8").rstrip()
if not wifi_strength_value:
wifi_strength_value = "0"
return (wifi_strength_value)


def get_rpi_power_status():
Expand Down

0 comments on commit cda313b

Please sign in to comment.