Hardware Connection fix

This commit is contained in:
2026-09-20 13:01:36 +02:00
parent b6cb5bb6a1
commit a649865643
4 changed files with 54 additions and 25 deletions
+13 -3
View File
@@ -25,10 +25,14 @@ HEADER_FMT = "<B B H I" # ID, Ver, Len, Timestamp
TLV_FMT = "<B H"
class ESP32Communication(Thread):
def __init__(self, host=cfg.esp32_ip, port=cfg.esp32_port):
def __init__(self, host=None, port=None, ip=None):
super().__init__(daemon=True)
if ip is not None:
host = ip
host = cfg.esp32_ip if host is None else host
port = cfg.esp32_port if port is None else port
self.addr = (host, port)
# UDP Socket - Zero Lag
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
@@ -126,4 +130,10 @@ class ESP32Communication(Thread):
def stop(self):
self.running.clear()
self.sock.close()
try:
self.sock.close()
except Exception:
pass
def close(self):
self.stop()