ETimeOut after connected to Drone

Hi! :slightly_smiling_face:

I am trying to connect a Simple Android App with an PX4 SITL Simulator.
I already run the MAVSDK Java Example App and got a connection thanks to this Topic.
But the App is always throwing an Error when i am trying to subscribe to any Method (after 130 Seconds).

My current setup is a Windows 11 Laptop with Android Studio that run an Emulator and WSL - Ubuntu running the PX4 firmware with SITL.

Anyone got ideas would i am doing wrong? :sweat_smile:

Thanks!

The Code:

  private void runMavsdkServer() {
    MavsdkEventQueue.executor().execute(() -> {

      int p = 50051;
      String connectionIP = "172.22.128.74";

      String connectionString = "udp://" + connectionIP + ":18570";

      Runnable r = new Runnable() {
        public void run() {
          mavsdkServer.run(connectionString, p);
          log("Connected! - " + connectionString + " - [" + p + "]");
        }
      };

      new Thread(r).start();

    /*  try {
        Thread.sleep(5000);
        log("Sleep (5sec) Done!");
      } catch (InterruptedException e) {
        throw new RuntimeException(e);
      } */

      LocalTime time = LocalTime.now();
      
      drone = new System(connectionIP, p);

      log("Drone: " + drone);

      drone.getTelemetry().getPosition().subscribe(new Subscriber<Telemetry.Position>() {

           public void onSubscribe(Subscription s) {
              log("POS - onSubscribe");
           }

           public void onNext(Telemetry.Position position) {
              log("POS - Position: " + position.toString());
           }

           public void onError(Throwable t) {
              log("POS - Error: " + t.getMessage() + " | " + t.getCause() + " | " + t.getStackTrace());

              log("Seconds between start and timeout: " + time.until(LocalTime.now(), ChronoUnit.SECONDS));
           }

           public void onComplete() {
              log("POS - Complete");
           }
         }
      );

      isMavsdkServerRunning = true;
      runOnUiThread(() -> buttonRunDestroyMavsdkServer.setText(R.string.destroy_mavsdk_server));
    });
  }

The Output:

There are two things:

  1. When creating a System(), you want to connect it to your mavsdkServer instance. So if mavsdkServer runs on the same device, the address is localhost.
  2. The way you run mavsdkServer, it will connect to a remote drone with IP 172.22.128.74, listening on 18570. Is that what you want to do? Typically PX4 sends MAVLink to 14540, and you want mavsdkServer to listen to that. So the address in this case looks more like udp://:14540.

Did you have a look at the examples? Maybe they can help, too.

Hi Jonas!

I am actually working with the Android Example from MAVSDK-Java/examples, but this doesnā€™t work for me.
The Problem is that otherwise, I donā€™t get a connection with the drone. I already tried localhost, but that gives me just an empty System.

Basically, it is a remote drone because itā€™s running on another device (WSL ubuntu) with its own IP.
And I have no idea why, but Port 14540 also doesnā€™t workā€¦ I only get a positive connection result with this piece of code. But like I said, after 130 seconds, the timeout error is coming.

My goal is just to run the Mavsdk-Server on the phone, send actions and receive data (like Telemetry).

So do I still need to have the localhost as the host address in the System?
And the ip where the drone runs should be the ip for the mavsdk-server, right?

Sorry but I do not really get how this is working :sweat_smile:

Edit: I changed the ip address of the drone back to localhost and now i get the drone but the timeout is instant. (And still only working with port 18570)

Maybe letā€™s try a simpler setup: can you try the Android example on your phone (the default one, which will listen on 14540), and also note the IP of your phone as <ip-of-phone>, and run:

docker run --rm -it jonasvautherin/px4-gazebo-headless:1.13.2 <ip-of-phone>

This will run PX4 in a docker container (see here) and it should send MAVLink to <ip-of-phone>. Just run it instead of whatever SITL you are running now on your WSL.

Letā€™s see if that works :+1:

Hi,

I downloaded the MAVSDK-Java android example app again and run it on two devices.
On the virtual device from Android Studio, it didnā€™t work (where I am working withā€¦).
Then I plugged my physical device in and it worked!

But Iā€™m still a little bit confused now, how to get the connection between devices and drones.

Appreciate the help :slight_smile:

Yes, because itā€™s running in an emulator, and it has its own network. I think you have to do some manipulations from your host to expose it (or maybe it just works, but it has an IP like 10.0.2.2). Check online for documentation about networking with the Android emulator :wink:

Not sure I get that. You said it works with the app running on your phone, right?

Yeah, I tried already with the virtual phone IP (10.0.2.16), but as you said it is properly a networking problem.

Sorry, that was a little bit unspecificā€¦ I mean, when we are not in a simulation. As an Example: I got my phone where I am running the mavsdk server and a drone with a Raspberry Pi and px4 on it.

How do I connect these? Because it is no running on localhost anymore, so ā€œudp://:14540ā€ doesnā€™t work right?

Or what other options do I have?

udp://:14540 just tells mavsdk_server to listen for MAVLink messages coming on UDP port 14540. They can come from anywhere on the network (including your RPi).

You just need to tell your RPi to send MAVLink to <ip-where-mavsdk-runs>:14540. For instance, using mavlink-router.

Does that make sense?

PS: for the emulator, IIRC there is some telnet command to enable something, maybe have a look there (maybe Iā€™m completely off, itā€™s a vague souvenir :wink:)

1 Like

Yeah it does!

Already looked a little bit into mavlink router and now its working with the WSL too!

Thank you very much :slight_smile:

1 Like