mavlink / MAVSDK-Java

MAVSDK client for Java.
71 stars 41 forks source link

mavsdkserver stop method is not working in the last release #96

Closed jjcetraro closed 1 year ago

jjcetraro commented 2 years ago

I was testing the android-client example, and the mavsdkServer.stop() call in the onPause of the MapsActivity works fine. I mean, I am testing with a sim_vehicle, and I can see on the console that when I connect to the vehicle I see "New connection on serial port 0" on the console, and when I leave the MapsActivity, I see "Closed connection on serial port 0".

This example is using:

I tried to update to the last version (1.1.1), and the connection to the sim_vehicle works fine, but with this last version what is not working is the stop method. When I leave tha activity, I don't see the "Closed connection on serial port 0" on the console, and I have to close the app to see this message. I am using the same code, the only thing I did was to update the version of the mavsdk and the mavsdk-server.

  1. Is this a known bug?
  2. Are you working to solve it in the following release?

Thanks!

JonasVautherin commented 2 years ago

Destroying the activity is not enough.

I did not mean destroying the activity, but mavsdk_server. But now I realize that MAVSDK-Java does not expose destroy() :confused:. That should probably be added.

julianoes commented 2 years ago

That should probably be added.

Aha!

jjcetraro commented 2 years ago

Destroying the activity is not enough.

I did not mean destroying the activity, but mavsdk_server. But now I realize that MAVSDK-Java does not expose destroy() 😕. That should probably be added.

Adding that method would be great! Can you do that @JonasVautherin ?

JonasVautherin commented 2 years ago

Yeah I'll try to do that this week :+1:

JonasVautherin commented 1 year ago

I have published mavsdk-server:1.2.1 to the Maven repository, it should be available in a few hours and expose the MavsdkServer.destroy() function.

Please try it and let me know :+1:

jjcetraro commented 1 year ago

Hi @JonasVautherin ! thanks for your support.

I tried to use this new version of the mavsdk-server, but it doesn't work. If I take sample app, and I change the gradle to use this new version of the mavsdk-server, it compiles but when you start it, it never shows the main activity. Did you test it with an android device?

JonasVautherin commented 1 year ago

Did you test it with an android device?

I did not, I just exposed the destroy() function.

it compiles but when you start it, it never shows the main activity

My guess is that it blocks at the MavsdkServer.run() function. Could you check that?

jjcetraro commented 1 year ago

Hi @JonasVautherin !

You were right, the problem was I was executing the run method in the ui thread. Now is working! 😃

Thanks for your support, and also thanks to all the people that collaborated to solve this issue!

julianoes commented 1 year ago

Yay, solved at last!

divyanshupundir commented 1 year ago

Great!

@jjcetraro would you mind updating the README on how to use the new method? I think you can use the MavsdkEventQueue to run the run() and destroy() methods.

I had designed the plugins in a way that the connections to the gRPC server happen on the MavsdkEventQueue. Otherwise, using the plugins would give a connection error and crash.

Running the run() method as the first function on the MavsdkEventQueue blocks these operations until it is safe to make these connections.

jjcetraro commented 1 year ago

Hi @divyanshu1234 !

Sure, I will update the README, and also I will update the android sample to use this last version of the mavsdk-server (right now it is using the 0.7.0)