MAVSDK-Java
MAVSDK-Java copied to clipboard
Multiple systems on the network
MAVSDK-Java Version: 2.0.1
MavSDK-Server Version: 2.0.0
I am running into an issue when there are multiple Systems detected on a network. My implementation looks like the following:
val mavSdkPort = mavSdkServer.run("udp://$ipAddress:$port")
val system = System(ipAddress, mavSdkPort)
Where ipAddress = "0.0.0.0"
and port
is the port of the system I am trying to connect to.
If only 1 system is on the network, I am able to connect perfectly fine. If 2 systems are on the network, I am connected to both Systems with no way to discern between the two. Logcat looks like the following:
Mavsdk MAVSDK version: v2.1.0
MAVSDK-Server Running mavsdk_server with connection url: udp://0.0.0.0:14550
Mavsdk Waiting to discover system on udp://0.0.0.0:14550...
Mavsdk New system on: 192.168.4.223:43620 (with system ID: 1) // Simulator
Mavsdk New system ID: 1 Comp ID: 1
Mavsdk Component Autopilot (1) added.
Mavsdk Component Gimbal (154) added.
Mavsdk New system on: 10.X.X.X:14550 (with system ID: 1) // System I am attempting to connect to
If I change ipAddress
(mentioned above) to the IP of the desired system, MavSDK Server never finishes booting up. What can I do differently?
The problem is that MAVSDK-Java expects exactly one system on the port it listens to (here udp://:14550). It is the same with all the language bindings (e.g. MAVSDK-Swift, MAVSDK-Python). What you have to do is demultiplex the MAVLink stream, and send it to different instances of mavsdk_server.
Say you have two drones, both broadcasting on udp://:14550. You can run a mavlink-router that listens on 14550 and forwards to 14551 and 14552. Then you can run on mavsdk_server with mavSdkServer.run("udp://:14551")
and the other with mavSdkServer.run("udp://:14552")
.
Does that make sense?