import serial # Configure serial port ser = serial.Serial('/dev/ttyUSB0', 57600) # Adjust to your port and baud rate def process_message(data): # Process the received message print(f"Received message: {data}") while True: if ser.in_waiting > 0: # Read a line from the serial port line = ser.readline().decode('utf-8').strip() process_message(line)