# Connection only works after opening QGC

**URL:** <https://discuss.px4.io/t/connection-only-works-after-opening-qgc/19085>\
**Category:** MAVSDK\
**Created:** [October 16, 2020, 7:54am UTC](https://discuss.px4.io/t/connection-only-works-after-opening-qgc/19085 "2020-10-16T07:54:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lappie](https://discuss.px4.io/user_avatar/discuss.px4.io/lappie/32/7228_2.png) [@lappie](https://discuss.px4.io/u/lappie)\
**Post date:** [October 16, 2020, 7:54am UTC](https://discuss.px4.io/t/connection-only-works-after-opening-qgc/19085/1 "2020-10-16T07:54:58Z")

</div>

I’m trying to get the default MAVSDK take\_off\_and\_land c++ example running. I have a Herelink connected on the same WiFi network, that is connected to my drone. The connection fails every time, unless I first connect and disconnect QGC. Then it works.

Step by step:

I’m running the default example:

```auto
./takeoff_and_land udp://:14552

```

Results in:

```auto
[09:14:30|Info] MAVSDK version: v0.29.0 (mavsdk_impl.cpp:27)
[09:14:30|Debug] New: System ID: 0 Comp ID: 0 (mavsdk_impl.cpp:404)
Waiting to discover system...
No system found, exiting.

```

Here is the weird thing. Now I open QGC, and create a comlink to udp://\<my\_ip\>:14552, and that works. Now I disconnect QGC and run the same command again.

```auto
./takeoff_and_land udp://:14552

```

Now it works. How is this possible? What does QGC do that it manages to establish a connection.

---

<div class="post-metadata">

**Author:** ![Mateus\_Soares](https://discuss.px4.io/user_avatar/discuss.px4.io/mateus_soares/32/11641_2.png) [@Mateus\_Soares](https://discuss.px4.io/u/Mateus_Soares)\
**Post date:** [October 12, 2022, 2:12am UTC](https://discuss.px4.io/t/connection-only-works-after-opening-qgc/19085/2 "2022-10-12T02:12:45Z")

</div>

I’m having a similar problem when trying to use MAVSDK to connect to a pixhawk. Were you able to solve this? Or do you have any tips? Thanks

---

<div class="post-metadata">

**Author:** ![Mateus\_Soares](https://discuss.px4.io/user_avatar/discuss.px4.io/mateus_soares/32/11641_2.png) [@Mateus\_Soares](https://discuss.px4.io/u/Mateus_Soares)\
**Post date:** [October 13, 2022, 3:26am UTC](https://discuss.px4.io/t/connection-only-works-after-opening-qgc/19085/3 "2022-10-13T03:26:34Z")

</div>

I solved my problem by running the [mavlink\_shell.py script](https://github.com/PX4/PX4-Autopilot/blob/main/Tools/mavlink_shell.py) and closing the shell, instead of opening and closing QGC(QGroundControl). So in a way the problem remains, but now you only have to run a python script, which is much more doable than having to run QGC.

The answer to what does this script does in order to enable connection after it is closed is, for certain, inside the script itself; you just have to study it, understand it and replicate in your own code.

Hope it helps!

---

<div class="post-metadata">

**Author:** ![heilmao](https://discuss.px4.io/user_avatar/discuss.px4.io/heilmao/32/12278_2.png) [@heilmao](https://discuss.px4.io/u/heilmao)\
**Post date:** [January 28, 2023, 12:04pm UTC](https://discuss.px4.io/t/connection-only-works-after-opening-qgc/19085/4 "2023-01-28T12:04:35Z")

</div>

Hi both, I am having the same problem as you! I am using MAVSDK v1.4 (I find this by seeing which git branch I have checked out). I have tested this by using a Raspberry Pi4B+ connected by both the TX,RX pinouts to the TELEM2 port on the Orange Cube as well as via usb connection.

I have also determined that connecting the flight controller to QGroundControl through any machine, then disconnecting the Orange Cube (ensuring it still has power) and then reconnecting the usb cable to the RPi 4B+ will actually allow the autopilot connection when running any MAVSDK example script.

This means that the issue must come from the OrangeCube side (i.e. PX4 firmware) or that QGroundControl is initialising something which MAVSDK is not. I tried an earlier version of PX4 firmware and it did not have this problem. Perhaps there is a setting which QGroundControl changes when initialising a connection to the flight controller?

Hopefully someone can help with this issue!

---

<div class="post-metadata">

**Author:** ![heilmao](https://discuss.px4.io/user_avatar/discuss.px4.io/heilmao/32/12278_2.png) [@heilmao](https://discuss.px4.io/u/heilmao)\
**Post date:** [January 30, 2023, 9:31am UTC](https://discuss.px4.io/t/connection-only-works-after-opening-qgc/19085/5 "2023-01-30T09:31:08Z")

</div>

Turns out the issue was relating to the versions of PX4 \> 1.3 requiring a heartbeat message to be sent to the flight controller before transmitting telemetry back.

See [MAVSDK Only Connects to PX4 Autopilot AFTER QGroundControl is Launched! · Issue #1967 · mavlink/MAVSDK · GitHub](https://github.com/mavlink/MAVSDK/issues/1967) for the solution!
