diff --git a/classes/StargateMilkyWay/stargate.py b/classes/StargateMilkyWay/stargate.py index 0d41b5e..f492d93 100644 --- a/classes/StargateMilkyWay/stargate.py +++ b/classes/StargateMilkyWay/stargate.py @@ -27,6 +27,7 @@ def __init__(self, app): self.electronics = app.electronics self.base_path = app.base_path self.net_tools = app.net_tools + self.temperature = app.temperature self.sw_updater = self.app.sw_updater self.schedule = app.schedule self.galaxy = app.galaxy diff --git a/classes/temperature.py b/classes/temperature.py new file mode 100644 index 0000000..2f1295a --- /dev/null +++ b/classes/temperature.py @@ -0,0 +1,28 @@ +import os +import subprocess + +class Temperature: + + def __init__(self, log): + self.log = log + + @staticmethod + def get_temperature(): + """ + A little helper that returns the output of the temperature command + By default the command is available on Raspberry Pi OS (Lite) + Command: `vcgencmd measure_temp | cut -d "=" -f2` + + :return: returns the output as seen if run in a shell. + """ + try: + result = subprocess.run( + 'vcgencmd measure_temp | cut -d "=" -f2', + shell=True, + capture_output=True, + text=True, + check=True + ) + return result.stdout.strip() + except subprocess.CalledProcessError as e: + return f"Error getting temperature: {e}" diff --git a/classes/web_server.py b/classes/web_server.py index 86b7fc6..cd152d3 100644 --- a/classes/web_server.py +++ b/classes/web_server.py @@ -85,6 +85,7 @@ def do_GET(self): # pylint: disable=invalid-name "dialer_mode": self.stargate.dialer.type, "hardware_mode": self.stargate.electronics.name, "audio_volume": self.stargate.audio.volume, + "temperature": self.stargate.temperature.get_temperature(), "galaxy": self.stargate.galaxy } diff --git a/main.py b/main.py index 401f1c9..08fe86b 100644 --- a/main.py +++ b/main.py @@ -35,6 +35,7 @@ from stargate import Stargate from electronics import Electronics from network_tools import NetworkTools +from temperature import Temperature class GateApplication: @@ -104,6 +105,11 @@ def rollbar_except_hook(exc_type, exc_value, traceback): ### We'll use NetworkTools and Schedule throughout the app, initialize them here. self.net_tools = NetworkTools(self.log) + + ### Temperature + self.temperature = Temperature(self.log) + + ### Schedule self.schedule = schedule # Alias the class here so it can be used in other areas with a clear interface ### Check for new software updates ### diff --git a/web/info.htm b/web/info.htm index f119c40..8f6ce22 100644 --- a/web/info.htm +++ b/web/info.htm @@ -376,6 +376,7 @@ $('#dialerMode').html(data.dialer_mode) $('#hardwareMode').html(data.hardware_mode) $('#volumeAsPercent').html(data.audio_volume) + $('#temperature').text(data.temperature) $('#stats_dialing_failures').html(data.stats_dialing_failures) $('#stats_established_fan_count').html(data.stats_established_fan_count) @@ -558,6 +559,7 @@