from pymavlink import mavutil
import time

# The ELRS Backpack listens for injected data on port 14555
# We target the Backpack's IP (10.0.0.1)
# Prerequisites: Your PC must be connected to the ExpressLRS TX WiFi hotspot.

connection_string = 'udpout:10.0.0.1:14555'

print(f"Connecting to ELRS Backpack at {connection_string}...")
master = mavutil.mavlink_connection(connection_string, source_system=255)

def send_test_message(text):
    print(f"Sending: {text}")
    # MAV_SEVERITY_INFO = 6
    master.mav.statustext_send(mavutil.mavlink.MAV_SEVERITY_INFO, text.encode())

try:
    print("Press Ctrl+C to stop.")
    while True:
        send_test_message("HUD TEST OK")
        time.sleep(5)  # Send every 5 seconds
except KeyboardInterrupt:
    print("Test stopped.")
