How to connect to multiple vehicles with system id greater than 9

I am starting 12 vehicles using PX4-SITL’s gazebo_multiple_vehicle.sh command.
Later using 12 seperate instances of my software, I am trying to connect to these vehicles. I am connecting through local host and using the ports through 14540 to 14549.
For the vehicles with id 1 to 9 (where seperate ports 14540 through 14548) I can easily connect to the autopilots. But, for the vehicles with id [10, 11, 12], I use 14549 port, and only one of my software instances can connect, while others throwing following error:

[08:24:41|Error] bind error: Address already in use (udp_connection.cpp:86)

Can anyone help me on this issue?
Thanks in advance.

@JulianOes and @JonasVautherin do you have any suggestion on this issue?

Currently, the port 14549 is re-used for all vehicles above 9, see:

So in theory, you only need to connect to the 9 ports and should receive all vehicles. In practice there might be some bugs. I’ll try to reproduce this.

Hi Julian,

I want to highlight again that I am trying to connect through port 14549 from different processes. Only one of my processes can connect, while others throwing an error indicating “bind error: Address already in use (udp_connection.cpp:86)”.

I can connect to autopilots with id 10, 11, 12 etc. when I run only one process at a time.
But the thing I am trying to do is that, run 3 processes simultaneously and make each process connect to an autopilot with different id. One will connect to autopilot-10, other will connect to autopilot-11 etc.

In case of you haven’t found a solution :slight_smile: or anyone else need help?

To connect to multiple vehicles with system IDs greater than 9, you need to modify the gazebo_sitl_multiple_run.sh script to assign unique ports for each vehicle instance. By default, the script assigns port 14549 for all vehicles with IDs above 9, which causes the “Address already in use” error you mentioned.

To resolve this issue, you can modify the gazebo_sitl_multiple_run.sh script to assign unique ports for each vehicle instance. You can do this by adding an if-else statement in the script to assign different ports for vehicles with IDs greater than 9. For example, you can increment the port number for each additional vehicle:

if [ "$i" -lt 10 ]; then
    udp_port=$((14540+i))
else
    udp_port=$((14540+i+1))
fi

This will assign unique ports for each vehicle, allowing you to connect to all vehicles without encountering the “Address already in use” error.

After modifying the script, you can run the multi-vehicle simulation with the desired number of vehicles. Make sure to connect your software instances to the appropriate ports, starting from 14540 and incrementing for each vehicle.

Keep in mind that you might need to adjust other configurations, such as MAVLink system IDs and remote UDP ports, to ensure proper communication between the vehicles and your software instances