refindied it a bit and added mem

This commit is contained in:
wildercayden 2025-06-25 21:08:17 -04:00
parent 27e16dddc6
commit 50704497f4
2 changed files with 21 additions and 3 deletions

View File

@ -11,5 +11,6 @@ print("Server started, waiting for data...")
while True: while True:
cpu = table.getNumber("CPU Usage", -1) cpu = table.getNumber("CPU Usage", -1)
temp = table.getNumber("Temperature", -1) temp = table.getNumber("Temperature", -1)
print(f"CPU: {cpu}, Temp: {temp}") mem = table.getNumber("Memory", -1)
print(f"CPU: {cpu}, Temp: {temp} Mem:{mem}")
sleep(1) sleep(1)

View File

@ -8,8 +8,25 @@ table = NetworkTables.getTable("PiStatus")
while True: while True:
cpu = psutil.cpu_percent() cpu = psutil.cpu_percent()
temp = 52.5 # Example temperature temps = psutil.sensors_temperatures()
mem = psutil.virtual_memory()
cputemp = "Unavailable"
for label in ["coretemp", "cpu-thermal", "k10temp", "cpu_thermal"]:
if label in temps and temps[label]:
cputemp = f"{temps[label][0].current:.1f}"
break
else:
# fallback for Pi
try:
with open("/sys/class/thermal/thermal_zone0/temp") as f:
cputemp = f"{int(f.read()) / 1000:.1f}"
except:
pass
table.putNumber("CPU Usage", cpu) table.putNumber("CPU Usage", cpu)
table.putNumber("Temperature", temp) table.putNumber("Temperature", float(cputemp) if cputemp != "Unavailable" else -1)
table.putNumber("Memory", mem.used // (1024**2))
print("Sent data to laptop") print("Sent data to laptop")
time.sleep(1) time.sleep(1)