EOF on TCP Socket Error with DroneKit-Python and Rpanion Server

Hi everyone, hope everybody is doing well.
I am encountering a persistent issue with an automated Python script that utilizes DroneKit-Python for mission loading based on specific landing locations. The script is set to run automatically through a systemd service on a Raspberry Pi, which acts as the companion computer.
Environment:

  • Pixhawk: Cube Orange/Orange+
  • Raspberry Pi: 4 Model B with 4GB RAM
  • Rpanion Server: Version 0.10

The script connects to the autopilot using the following connection string:`

connection_string = ‘tcp:127.0.0.1:5760’
vehicle = connect(connection_string) # connect is imported from dronekit`

The TCP server at port 5760 is enabled on the Rpanion server side.

Issue: We are observing constant connection losses, preventing the script from executing as intended. The major error encountered is “EOF on TCP socket”. This error emerges in two distinct scenarios:

  1. Before establishing a connection.
  2. After successfully connecting to the vehicle, it appears after some time.

Below is an excerpt of systemd service logs retrieved using journalctl highlighting these scenarios:

Fig 1 : During initial vehicle connection

Fig 2 : After Vehicle connection is established

We have found similar issues reported in these threads but are yet to find a concrete solution:

@stephendade , any insights or solutions to resolve this “EOF on TCP socket” error would be greatly appreciated!

Thank you in advance :grinning:

Does this EOF error occur in a GCS too? (MAVProxy, Mission Planner, etc).

I’ve not seen this error when using MAVProxy or other pymavlink scripts.

Does it only occur with dronekit?

Hi @stephendade ,

Thank you for your response. We have observed TCP connectivity fluctuations in Mission Planner as well, but they are not as frequent as the ones we see with our script connectivity.

The “EOF on TCP socket” error message is indeed generated by pymavlink. You can find this in the mavtcp class, inside the handle_eof() function in the pymavlink code base. Here is the link to the reference in the code base.

At this point, we are not certain whether this issue is specific to DroneKit or if it’s related to pymavlink. We are continuing our investigation, and any further insights or suggestions would be greatly appreciated.

Thank you in advance for your help.

I’ve not yet been able to replicate your issue, using this pymavlink script:

#!/usr/bin/env python3
from pymavlink import mavutil

# Setup MAVLink to connect
conn = mavutil.mavlink_connection("tcp:127.0.0.1:5760", autoreconnect=False, source_system=1, force_connected=False, source_component=mavutil.mavlink.MAV_COMP_ID_LOG)

# wait for the heartbeat msg to find the system ID
while True:
    if conn.wait_heartbeat(timeout=0.5) != None:
        # Got a heartbeat from remote MAVLink device, good to continue
        break

print("Got Heartbeat from ArduPilot (system {0} component {1})".format(conn.target_system,
                                                                 conn.target_system))

while True:
    msg = conn.recv_match(blocking=True, timeout=0.5)
    if msg:
        if msg.get_type() == 'STATUSTEXT':
            #print STATUSTEXT packet text
            print(msg.text)

Could you check if you get the EOF error with the above script?

Hi @stephendade ,

Thank you for providing the script. Could you tell me whether you have done your script testing only on an SITL?

As for my own testing, I’ve primarily been using a script that utilizes DroneKit for vehicle connection. When running this script on an SITL, I haven’t encountered the EOF errors. However, when deploying it on a Pixhawk, I did observe sporadic EOF errors, albeit inconsistently. Unfortunately, I wasn’t able to intentionally replicate these errors under specific conditions.

Here is the block diagram of the testing environment (with a pixhawk) on which i have tested my script,

Any insights on this would be greatly appreciated!

Thank you :grinning:

I tested with a CubeOrange connected via USB to a Raspberry Pi.

I don’t quite understand your diagram. How is the Pixhawk connected to the Raspberry Pi? And I don’t understand why you’ve got a SITL instance connected to the Pixhawk - that doesn’t make sense.

Hi @stephendade ,

Thank you for your reply. Apologies for the confusion earlier, @stephendade . I made a mistake in the diagram I provided. In the correct setup, the Pixhawk is connected to the Raspberry Pi via the Telem 2 port, not as depicted in the previous diagram. I hope this clears up any misunderstandings.

I did test your script on my setup, didn’t see an EOF pop up. As i have mentioned before, the EOF error is very erratic and random, not able to replicate it frequently.

I’ve tested a quick dronekit python script and I’ve not seen any issues.

You’ll need to test your setup in more detail and get back to me when you’ve got more solid information about where the issue is.