add system temperature measurement

This commit is contained in:
2025-11-20 14:29:54 +01:00
parent 7c0d5405fc
commit 580d08c002
3 changed files with 34 additions and 8 deletions

View File

@@ -8,6 +8,8 @@ import requests
from dotenv import load_dotenv
import streamlit as st
from auracast.utils.read_temp import read_case_temp, read_cpu_temp
from auracast import auracast_config
from auracast.utils.frontend_auth import (
is_pw_disabled,
@@ -868,6 +870,20 @@ if is_started or is_stopped:
############################
with st.expander("System control", expanded=False):
st.subheader("System temperatures")
temp_col1, temp_col2, temp_col3 = st.columns([1, 1, 1])
with temp_col1:
refresh_temps = st.button("Refresh")
try:
case_temp = read_case_temp()
cpu_temp = read_cpu_temp()
with temp_col2:
st.write(f"CPU: {cpu_temp} °C")
with temp_col3:
st.write(f"Case: {case_temp} °C")
except Exception as e:
st.warning(f"Could not read temperatures: {e}")
st.subheader("Change password")
if is_pw_disabled():
st.info("Frontend password protection is disabled via DISABLE_FRONTEND_PW.")

View File

@@ -0,0 +1,18 @@
from smbus2 import SMBus
def read_case_temp():
addr = 0x48 # change if your scan shows different
with SMBus(1) as bus:
msb, lsb = bus.read_i2c_block_data(addr, 0x00, 2)
raw = ((msb << 8) | lsb) >> 4
if raw & 0x800: # sign bit for 12-bit
raw -= 1 << 12
return round(raw * 0.0625, 2)
def read_cpu_temp():
with open("/sys/class/thermal/thermal_zone0/temp", "r") as f:
return round(int(f.read()) / 1000, 2)
if __name__ == "__main__":
print("Case temperature: ", read_case_temp(), "°C")
print("CPU temperature: ", read_cpu_temp(), "°C")

View File

@@ -1,8 +0,0 @@
from smbus2 import SMBus
addr = 0x48 # change if your scan shows different
with SMBus(1) as bus:
msb, lsb = bus.read_i2c_block_data(addr, 0x00, 2)
raw = ((msb << 8) | lsb) >> 4
if raw & 0x800: # sign bit for 12-bit
raw -= 1 << 12
print(f"{raw * 0.0625:.2f} °C")