One link multiple vehicle doubt

Context:

I have a companion computer connected to my flight controller through dronekit sending battery_status with custom values. If I connect the flight controller with MP I can see this message being received as vehicle 255, ok, so far so good.

Then I decided to add another device in another end, to see if I could extract these custom messages. Instead of doing this, it extracts the original battery_status from the flight controller. After debugging I realized this happens because when creating a vehicle object to connect to a link, it automatically targets vehicle 1, the flight controller by default.

I searched for a solution for this and found a github discussion about adding the option of connection multiple vehicle from the same link within dronekit. There is a branch from dronekit and pymavlink that offers a answer, but this branch was never merged back to master and I found that strange. After some digging within github I found the branch was closed because by that time pymavlink had a way to accomplish this so it made no sense to do the merge.

Then I went to Pymavlink (Python-mavgen) · MAVLink Developer Guide to see how I could do this and then I read this:

The link does not properly handle multiple systems running on the same port. If you need a multi-vehicle network see source-system-filtering.

The link leads to the closed branch. So I am at loss, is there a way to connect to multiple within a same link or not? And if there is a way, how can I do it?

It doesn’t even need to be a big help, just need some pointers in the right direction and I can figure out the rest

I am working on a similar project where I need the status of 2 drones to be monitored simultaneously on a laptop.

I found a solution using the combination of pymavlink and MAVProxy.
Basically, I read the mavlink stream of the drone using MAVProxy, and divert the output to two ports: one for a GCS software (like mission planner) and other for the pymavlink connection.

Here is the function that does this:

'''Function to start MAVProxy on the detected ports, split the MAVLINK streams and connect to one stream from each port'''
def pymavlink_connect(output_port = 14550):

    com_ports = com_scan()   # User defined function to scan the com ports for detecting the telemetry modules connected via USB. 

    i = 0
    for port in com_ports:
        connected = False
        while not(connected):
            mavproxy_input = "--master="+str(port)+",115200"

            print(f"\t Starting MAVProxy on {port}...........")
            PROC.append(subprocess.Popen(['mavproxy.exe', mavproxy_input, f'--out=udpbcast:127.255.255.255:{output_port}', 
                                                f'--out=udpbcast:127.0.0.1:{output_port+1}','--no-console', '--daemon'], shell=False))
    

            # Establish pymavlink connection
            try:
                CONNECTIONS[port] = (mavutil.mavlink_connection(f'udp:127.0.0.1:{output_port+1}'))  
                CONNECTIONS[port].wait_heartbeat()
                print(f"Pymavlink connected on {port}")
                output_port += 2
                i += 1
                connected = True
                sleep(0.5)

            except Exception as e:
                print(f"Unable to connect to the UDP port {output_port}! Error: ")
                print(e)
                PROC[i].kill()
                print("Attempting Reconnect!")
1 Like