Closed RishabhBhat2021 closed 2 years ago
This type of issues usually end up happening due to the local setup of the SITL, mavproxy, or the UDP forwarding code, and don't have much to do with the library itself.
I've left it open just in case someone else could help you or if you've progressed to find an actual issue with the library.
Have you managed to resolve it?
I came up with one solution, whose idea I got by looking at the QGC ‘s source code In QGC, they were listening to the 14550 port for any connection. And when any vehicle (SITL) starts sending messages, they dynamically get the local port of the UDP Packets they are receiving and assign the remote port for the packet to use that port
Similarly, I was able to resolve it by assigning the remotePort while we recieve the UDP Packets from the SITL
private var remotePort = 14556 // remotePort is 14556 by default
....
....
val service: ExecutorService = Executors.newSingleThreadExecutor()
service.execute {
try {
val packet =
DatagramPacket(ByteArray(bufferSize), bufferSize)
while (!datagramSocket.isClosed) {
datagramSocket.receive(packet)
appOut.write(packet.data, packet.offset, packet.length)
// Check for the port of the incoming packet
if (packet.port != remotePort) {
// Change the remoteAddress to use the local port of the sitl
remoteAddress = InetSocketAddress(ipAddress, packet.port)
remotePort = packet.port
Timber.d("Connected to: ${packet.address}, remote port: ${packet.port}")
}
appOut.flush()
}
} catch (e: IOException) {
e.printStackTrace()
} finally { ... }
}
....
....
I’m not sure whether this is the best approach, but the code works and I was able to successfully send the messages to the SITL
@RishabhBhat2021 Happy to hear you've got it working.
Thank you for posting this, others who experience the same problem may find this information useful :)
Question:
Hi, first of all, great work on easing the process of building custom mavlink based applications for newbies like me! I’m trying to create an Android application written in Kotlin which allows the user to perform some basic workflows such as uploading missions to a mavlink vehicle. And I plan to use Dronefleet to achieve the same.
Is there any way in MAVProxy to use custom local ports rather than using random local ports? Like we use 14550 as the remote port, just like that use like 14540 or 14556 something for the local port
My setup
I have remote ArduPilot SITL set up with command
output add <phone_ip_address>:14550
ArduPilot Version is
AP: ArduCopter V4.3.0-dev (ebe2205b)
Just to validate the SITL setup, I tried running QGC Android application and was able to connect to SITL successfully, and QGC was able to send commands as well
The SITL is running on my laptop and the GCS app is an Android app, and both are connected via remote MAVLink over my local network. My laptop is running Ubuntu 20.04 and Android device is a phone, Samsung Galaxy M51: API level 30 (Android 11)
Issue
I can receive messages from the SITL on my android app, but not able to send GCS heartbeat (and any other message) to the SITL
I’m able to send / receive messages with PX4 SITL setup on my app, but can’t figure out with ArduPilot SITL. I can only receive messages from the ArduPilot SITL but the SITL doesn’t recieve my messages
Code snippet to create UDP streams and send message to the vehicle
Messages recieved on the Android Device from the Setup