MAVSDK-Python icon indicating copy to clipboard operation
MAVSDK-Python copied to clipboard

Unable to connect with drone while using the UDP of "Remote IP Address".

Open MuhammadBilal1 opened this issue 2 years ago • 14 comments

Hi, I am trying to connect with my drone using the "remote IP address" of UDP. When I connect the PX4 simulator, it works fine. await drone.connect(system_address="udp://14540")

I tried the following patterns, but none of them worked.

await drone.connect(system_address="udp://10.17.111.1:40000")
await drone.connect(system_address="udp:10.17.111.1:40000")
await drone.connect(system_address="udpout://10.17.111.1:40000//")
await drone.connect(system_address="udp://10.17.111.1")

I am using the remote host (10.17.111.1), with the following details: IP: 10.17.111.1 Port: 40000

I am connecting it while using the VPN.

Mavproxy works fine, I am getting heartbeat:

image_2023_05_17T14_29_23_906Z

Working fine with QGroundControl, I am getting everything on QGC:

image_2023_05_17T14_55_32_487Z

MuhammadBilal1 avatar May 17 '23 15:05 MuhammadBilal1

This one should work: await drone.connect(system_address="udp://10.17.111.1:40000")

Which version of MAVSDK are you using?

JonasVautherin avatar May 17 '23 15:05 JonasVautherin

This one should work: await drone.connect(system_address="udp://10.17.111.1:40000")

Which version of MAVSDK are you using?

I am using MAVSDK==1.4.4.

MuhammadBilal1 avatar May 17 '23 17:05 MuhammadBilal1

Hmm I don't remember clearly, but it could be that this doesn't work with MAVSDK v1. I am pretty sure that it works with the main branch though (which will eventually be released as MAVSDK v2)... but you have to compile mavsdk_server from source and use it with MAVSDK-Python from source, too.

JonasVautherin avatar May 17 '23 17:05 JonasVautherin

Hmm I don't remember clearly, but it could be that this doesn't work with MAVSDK v1. I am pretty sure that it works with the main branch though (which will eventually be released as MAVSDK v2)... but you have to compile mavsdk_server from source and use it with MAVSDK-Python from source, too.

I am trying to compile mavsdk_server from the main branch using the source code by following the instructions given at Build mavsdk_server from Source. But I am getting errors while building.

Environment: Ubuntu 20.04

Here is the sequence of commands I am running to build mavsdk_server from source: Method # 1: (Build from source)

sudo apt-get update
sudo apt-get install build-essential cmake git
git clone https://github.com/mavlink/MAVSDK.git
git submodule update --init --recursive
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DBUILD_MAVSDK_SERVER=ON -Bbuild/default -H.
cmake --build build/default -j8

Below is the output of the last two commands: image Screenshot from 2023-05-22 00-37-37

Method # 2 (Release Build & Local Install)

sudo apt-get update
sudo apt-get install build-essential cmake git
git clone https://github.com/mavlink/MAVSDK.git
git submodule update --init --recursive
cmake -Bbuild/default -DCMAKE_BUILD_TYPE=Release -H.
cmake --build build/default -j8
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/home/bilal/mavsdk/installation/ -Bbuild/default -H.
cmake --build build/default --target install

After following the instruction, I don't know what should I do next to start mavsdk_server! I tried to search for the mavsdk_server, but i was unable to find that.

Can you please guide me what should I do and which method should I follow to proceed?

MuhammadBilal1 avatar May 21 '23 20:05 MuhammadBilal1

Your log should find openssl in third_party/ (like the other dependencies), but it found it on the system (I cannot copy-paste the line because it is a screenshot, so you have to find it there :innocent:).

You need to understand why that is. Probably an error when it built OpenSSL, which should appear earlier in your log.

JonasVautherin avatar May 21 '23 20:05 JonasVautherin

So the Method # 1 is the correct approach? I will check the openssl issue. Below is the complete output of my terminal for the following command: cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DBUILD_MAVSDK_SERVER=ON -Bbuild/default -H. log_22May2023.txt

MuhammadBilal1 avatar May 21 '23 20:05 MuhammadBilal1

https://github.com/mavlink/MAVSDK-Python/issues/592#issuecomment-1551609565

This works with v1.4.4. I don't think you need to build the server yourself.

julianoes avatar May 21 '23 21:05 julianoes

@julianoes @JonasVautherin Can you please guide me on how I can move forward? This is very critical for us.

In the below screenshot, I am showing you the following:

  • mavproxy is connecting to the same address successfully.
  • I can ping the UDP port using netcat.
  • mavsdk installed version is 1.4.4 (although I tried on 1.4.6, but output is same)
  • I am trying to connect with the drone at my udp address, but mavsdk is waiting forever.

image_2023_05_22T11_06_57_289Z

MuhammadBilal1 avatar May 22 '23 11:05 MuhammadBilal1

You have a typo in your code. It should read udp://10.17.111.1:40000 (your code is missing //).

Then are you certain that both mavproxy and MAVSDK can connect at the same time? I have seen plenty of mavlink implementations where the UDP server (i.e. the program listening on port 40000 here) only ever answers to the first client (here it would be mavproxy, I suppose) and ignores the others. I have also seen implementations where the server answers to the last client (so it would jump between mavproxy and MAVSDK, each receiving a subset of the messages. But that is apparently not happening here, because MAVSDK would detect the drone in that case).

JonasVautherin avatar May 22 '23 11:05 JonasVautherin

Sorry, I was trying to test different combinations and sent the screenshot of different combination (where I removed the //). Sending you the updated screenshot as well. I also had experience with the scenario that multiple connections will not work as you said. Like MAVSDK & QGroundControl can't work together at the same time.

I actually, stopped other things like QGroundControl, mavproxy to test this combination. None of the other task is running. Below screenshot shows only the MAVSDK is running.

image_2023_05_22T12_15_19_844Z

MuhammadBilal1 avatar May 22 '23 12:05 MuhammadBilal1

Can you check with wireshark if heartbeats are being sent by MAVSDK to 10.17.111.1:40000?

JonasVautherin avatar May 22 '23 12:05 JonasVautherin

Can you check with wireshark if heartbeats are being sent by MAVSDK to 10.17.111.1:40000?

Not much familiar with Wireshark, but this is what I found. image_2023_05_22T15_08_32_653Z

MuhammadBilal1 avatar May 22 '23 15:05 MuhammadBilal1

Seems like MAVSDK is sending the heartbeats, then... :thinking:

JonasVautherin avatar May 22 '23 15:05 JonasVautherin

PX4 doesn't switch the remote port once it has received UDP from one place.

You could try if this change helps at all: https://github.com/PX4/PX4-Autopilot/pull/21608

julianoes avatar May 22 '23 20:05 julianoes