add system temperature measurement
This commit is contained in:
@@ -8,6 +8,8 @@ import requests
|
|||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
import streamlit as st
|
import streamlit as st
|
||||||
|
|
||||||
|
from auracast.utils.read_temp import read_case_temp, read_cpu_temp
|
||||||
|
|
||||||
from auracast import auracast_config
|
from auracast import auracast_config
|
||||||
from auracast.utils.frontend_auth import (
|
from auracast.utils.frontend_auth import (
|
||||||
is_pw_disabled,
|
is_pw_disabled,
|
||||||
@@ -868,6 +870,20 @@ if is_started or is_stopped:
|
|||||||
############################
|
############################
|
||||||
with st.expander("System control", expanded=False):
|
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")
|
st.subheader("Change password")
|
||||||
if is_pw_disabled():
|
if is_pw_disabled():
|
||||||
st.info("Frontend password protection is disabled via DISABLE_FRONTEND_PW.")
|
st.info("Frontend password protection is disabled via DISABLE_FRONTEND_PW.")
|
||||||
|
|||||||
18
src/auracast/utils/read_temp.py
Normal file
18
src/auracast/utils/read_temp.py
Normal 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")
|
||||||
@@ -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")
|
|
||||||
Reference in New Issue
Block a user