Hi, I’m trying to connect the RaspberryPi 3B to QGC (running on my PC) via UDP.
At the moment I’ve managed to connect to MissionPlanner using this script with pymvlink:
import time
from pymavlink import mavutil
Create the connection
master = mavutil.mavlink_connection(‘udpin:0.0.0.0:14550’, source_system=42, source_component=158)
master.wait_heartbeat()
def send_heartbeat():
“”“Sends a heartbeat message with predefined parameters.”“”
try:
# Create a MAVLink heartbeat message
msg = master.mav.heartbeat_encode(
mavutil.mavlink.MAV_TYPE_GENERIC, # Type of MAV (Ground Control Station)
mavutil.mavlink.MAV_AUTOPILOT_GENERIC,
0,
0,
mavutil.mavlink.MAV_STATE_STANDBY
)
# Send the heartbeat message
master.mav.send(msg)
except Exception as e:
print(f"Error sending heartbeat: {e}")
Send heartbeat messages and receive messages
while True:
try:
# Send heartbeat every second
send_heartbeat()
except mavutil.mavlink.MAVLinkException as e:
print(f"MAVLink communication error: {e}")
except Exception as e:
print(f"Unexpected error: {e}")
time.sleep(1) # Send heartbeat every second
With MissionPlanner it works and appears as connected, however with QGC, although it responds to heartbeats, it doesn’t appear as connected. Does anyone know why? Shouldn’t the code work for both ground control stations?