import socket, time import subprocess RPI_IP = "10.55.0.1" RPI_PORT = 9000 INTERVAL = 2.0 def get_temp(): out = subprocess.check_output(["sensors", "-u"]).decode() # AMD Ryzen — Tctl is the control temp the firmware uses for line in out.splitlines(): if "tctl" in line.lower() and "input" in line.lower(): return float(line.split(":")[1].strip()) # fallback to thermal_zone0 with open("/sys/class/thermal/thermal_zone0/temp") as f: return int(f.read().strip()) / 1000.0 # Auto-reconnect loop while True: try: with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.connect((RPI_IP, RPI_PORT)) print(f"Connected to {RPI_IP}:{RPI_PORT}") while True: s.sendall(f"{get_temp():.1f}\n".encode()) time.sleep(INTERVAL) except (OSError, ConnectionResetError) as e: print(f"Connection lost: {e} — retrying in 5s") time.sleep(5)