Dronekit : unable to connect. Link time out error

I’m trying to connect to the drone using a simple dronekit python script but I keep getting the error. I searched online for possible solutions but to no avail.

from dronekit import connect, VehicleMode, LocationGlobalRelative, APIException

from pymavlink import mavutil
import time
import socket
import exceptions
import argparse

def connectQuad():
        parser = argparse.ArgumentParser(description='Commands')
        parser.add_argument('--connect')
        args = parser.parse_args()
        connection_string= args.connect
        print 'Connecting to vehicle on: %s' % args.connect
        vehicle = connect(connection_string, wait_ready=True)
        return vehicle

vehicle = connectQuad()


pi@navio:~/drone-kit $ python connect_quad.py --connect 127.0.0.1:14550
Connecting to vehicle on: 127.0.0.1:14550
WARNING:dronekit:Link timeout, no heartbeat in last 5 seconds
ERROR:dronekit.mavlink:Exception in MAVLink input loop
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/dronekit/mavlink.py", line 211, in mavlink_thread_in
    fn(self)
  File "/usr/local/lib/python2.7/dist-packages/dronekit/__init__.py", line 1371, in listener
    self._heartbeat_error)
APIException: No heartbeat in 30 seconds, aborting.
Traceback (most recent call last):
  File "connect_quad.py", line 18, in <module>
    vehicle = connectQuad()
  File "connect_quad.py", line 15, in connectQuad
    vehicle = connect(connection_string, wait_ready=True)
  File "/usr/local/lib/python2.7/dist-packages/dronekit/__init__.py", line 3166, in connect
    vehicle.initialize(rate=rate, heartbeat_timeout=heartbeat_timeout)
  File "/usr/local/lib/python2.7/dist-packages/dronekit/__init__.py", line 2275, in initialize
    raise APIException('Timeout in initializing connection.')
dronekit.APIException: Timeout in initializing connection.
2 Likes

Hi @novice,

May I ask you to describe your step-by-step actions that led to this issue? Have you tried using the IP address of your GCS instead?

Hi Polina,

Sorry about the much delayed reply. I was ill and was hospitalized. Well, I did try using the IP of the GCS and no luck there so far.

Hi @novice,

I apologize for the amount of time it takes to understand the issue!

We’re looking into the issue with the Dronekit connection. Unfortunately, this might take more time. I’ll be in touch immediately once there’s news.

1 Like

Hi there Polina, I seem to be having this same problem with even the simplest Dronekit script on my real hardware. I am wondering if there is a timetable for a solution? I’m currently running the Emlid 2019-11-28 release. emlidtool reports Kernel: 4.19.83-emlid-v7l+ If it helps I’m running this on a Raspberry Pi 4. I do have a spare Pi 3 that I could downgrade to if there is an image available? Even so I hate to rebuild my Drone if at all possible. Is there an earlier Pi 4 release that doesn’t have this problem and is available?

Thanks for your help.
Dave Rounds

Problem Solved – Ok, I solved this problem by pulling the master branch from the repository and building it locally. I then set my locally built arducopter image to be ardupilot firmware controlled by the service as described in the Emlid documentation. Dronekit Vehicle.connect methods no longer timeout. Apparently the firmware bundled with the Pi Buster image has a bug that has been fixed in the master branch.

1 Like

Hi @solar, can you make a video about it and post a link here . Several guys are facing the same problem including me .

To get you up and running quickly here are my notes. This assumes you’re using the latest Pi build from Emlid (Buster) since I think the service invocation steps may be different in the different Linux OS versions.
• On Raspberry Pi in pi user home directory
• Create a directory
• git clone https://github.com/ardupilot/ardupilot
○ This clones the master or use a different branch
• cd ardupilot
• git submodule update --init --recursive
• ./waf list_boards
• ./waf configure --board=navio2 --debug
○ --debug optional
• ./waf --targets bin/arducopter
• Executable arducopter in ~/src/???/ardupilot/build/navio2/bin/arducopter
• To use this custom binary
• Note this doesn’t remove the existing/installed version but I suppose you could take that route too
○ modify /etc/systemd/system/ardupilot.service to point to the version you’ve built (uncomment execution)
○ Add options to /etc/default/ardupilot for ARDUPILOT_OPTS
○ Use systemctl to start the modified ardupilot service
§ pi@navio: ~ sudo systemctl start ardupilot && sudo systemctl enable ardupilot

3 Likes

Hi Dave,

Thanks for sharing your solution!

We’re currently working on resolving the issue with our image.

Any updates on this? I still have the same issue

getting the same error.
I’ve tried using solar’s fix by building from source and then modifying ardupilot.service to point to the new version/build.
Any help on this would be highly appreciated :slight_smile:

Okay…managed to get it working now. Did what solar has mentioned earlier, I edited ardupilot.service to point to the binary, now I can’t connect to Mission Planner but dronekit works.

@curiosityrover i’m facing the same error , when i fix the IP of my GCS in the arducopter config the misson planner works well but i have a problem in dronekit , and when i dont make a changement in arducopter config (with 127.0.0.1:14550) the dronekit works fine and the misson planner doesn’t connect

Hey everyone,

We’re working on this issue. Sorry it takes longer than expected.

I am having the same problem, but I want to keep Mission Planner working. Is there any solution to this issue yet?

Ankith,

We’re working on a new Navio2 image that should solve this issue. I’m afraid I can’t provide you with any exact release dates for now.

Hey guys,

Thanks for your patience!

The new Navio2 image is out now with the fix for the Dronekit connection issue. We’d be grateful if you checked it out to see if everything works as expected for you.

More details on the fixes and improvements are available in this community forum thread.