import serial
import sys
import time

PORT = "/dev/ttyACM0"
BAUD = 38400

def send_command(command):
    try:
        with serial.Serial(PORT, BAUD, timeout=2) as ser:
            time.sleep(2) # Warte auf ESP-Reset
            ser.write((command + "\n").encode())
            # Lies die Antwort vom ESP
            response = ser.readline().decode().strip()
            print(response)
    except Exception as e:
        print(f"ERROR: {e}")

if __name__ == "__main__":
    if len(sys.argv) > 1:
        send_command(sys.argv[1])