Connect RaspberryPi to QGC via udp

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?

Hi @jpsilva2000, welcome to the Blue Robotics forum :slight_smile:

I’ll preface this by saying that while Blue Robotics does sometimes contribute to QGroundControl, we’re not the primary maintainers of it, so don’t always have a strong grasp of how it operates.

As I understand it the vehicle connection process in QGC involves some back and forth between QGC and the vehicle, whereby QGC requests parameters and other details so it knows how to represent the vehicle.

From some poking around in the code, that does seem to be the case, so presumably your “vehicle” code needs to at least provide meaningful responses to those requests from QGroundControl (even if those responses are just not-acknowledges or something) before it can consider the vehicle to be connected - a heartbeat alone is insufficient.

The logical next steps from here (assuming you haven’t solved this already) would be to check QGC’s application logs, as well as to get your vehicle code to receive and log the messages that QGC is sending to it :slight_smile: