Pixhawk 4 mini via USB not sending parameters untill connected to a ground station

I have this issue when I try to run python scripts and getting parameters from pixhawk. After connecting the pix via USB, the data stream will only be active after I connect the pixhawk to a ground station like QGC or MP. So I have to do this every time that I connect the pix to my PC. Plug the USB, open QGC, connect, and then close QGC. Is there any way to solve this issue? The pixhawk is not even sending a heartbeat until connected to the GS.

Thank you!

Solved: I wanted to run the scripts on a machine without having to install QGC or MP in it. The pix needs to stablish a connection on the USB port you are using. This is what QGC or MP were doing for me, openning the conection for the pixhawk to communicate through the port. Without this step, the pixhawk data stream won’t be available from your port. So I ran a basic mavproxy connection command on the linux terminal for it to open a stream data route (mavproxy.py --master=/dev/ttywhatever). After this, I tryed to run the scripts on a different terminal, leaving the mavproxy connection terminal open, but this led to them running intermitently (sometimes good sometimes won’t run), due to the fact that the USB port was being requested by both mavproxy and script. I finally had to close the mavproxy terminal and my script worked with no failure.

For anyone experiencing MAVLink connection issues and the flight controller only works after opening and closing QGroundControl (QGC), it’s because the flight controller isn’t “awake” or initialized.

QGC sends a MAVLink heartbeat when it starts, which wakes up the flight controller and starts communication. To fix this in your script, just send a heartbeat before trying to communicate:

connection.mav.heartbeat_send(
    mavutil.mavlink.MAV_TYPE_ONBOARD_CONTROLLER,  # System type
    mavutil.mavlink.MAV_AUTOPILOT_PX4,           # Autopilot type (PX4)
    0, 0, 0                                      # Custom mode, status, version
)
time.sleep(1)  # Wait a moment for the controller to respond

This makes the flight controller ready to communicate, and you won’t need to open QGC anymore. After sending the heartbeat, you can continue with your commands.