Link timeout, no heartbeat in last 5 seconds

Hello guys,

Am getting this warning message every time I try to run my python code.
This is my script on my raspberry pi:

from dronekit import connect, VehicleMode, LocationGlobalRelative, APIException
import time
import socket
import exceptions
import math
import argparse

def connectMyCopter():
    parser = argparse.ArgumentParser(description="commands")
    parser.add_argument("--connect")
    args=parser.parse_args()
    connection_string=args.connect
    baud_rate=921600
    vehicle = connect(connection_string,baud_rate,wait_ready=True)
    return vehicle

def arm():
   while vehicle.is_armable == False:
       print("Waiting")
       timer.sleep(1)
    vehicle.armed = True

    while vehicle.armed == False:
        print("Waiting to become armed")

    print("Vehicle is now armed")


vehicle = connectMyCopter()
arm()
print("End of Script")

Then I run the command:

python arm_test.py --connect=/dev/ttyAMA0

and this is what I get on the terminal:

WARNING:dronekit:Link timeout, no heartbeat in last 5 seconds
ERROR:dronekit.mavlink:Exception in MAVLink input loop

and then a traceback showing that a

dronekit.APIException('Timeout in initializing connection') 

was raised.

Note:

I have tested my pixhawk on the mission planner simulator and it was working fine.
I also tried running the following command on the raspberry pi terminal

mavproxy.py --master=/dev/ttyAMA0

and it works! it allows me to connect to the pixhawk and run commands through the command line

Can anyone help me please :frowning:

Does the below work?

import dronekit
vehicle = dronekit.connect(ip="/dev/ttyAMA0", baud=921600, wait_ready=True)
print(vehicle.mode.name)

Still same warning message

https://dronekit-python.readthedocs.io/en/latest/examples/guided-set-speed-yaw-demo.html

I’ve looked at this code and they also have the same warning log, but on their example, the exception is not raised and the code somehow still works at the end.

This should work. It is bare minimum.

Probably it is about serial device permissions or you’re setting the baud rate or connection string wrong.
Take a close look.

1 Like

You are using python 2 or python 3? Try the latter and remove ‘Exceptions’.

1 Like

ok, I’ll look into that thank you!

I was using python 2, should I use python 3? It says on the dronekit guide that python3 is not supported :confused:

https://dronekit-python.readthedocs.io/en/latest/develop/installation.html
at the end of this page ^

I’m not really certain why it is not working if you set it up for python 2 , but I’ve moved on to a python 3 configuration. Perhaps you can try an earlier version of ardupilot (eg, 4.07).

As mentioned by @Mustafa_Gokce, there are a number of reasons that can account for a bad link, but mavproxy seems to work for you.

I’ve written a blog on this subject.

2 Likes

On the raspberry:

Go in /boot/config.txt and add the following near the end of the file. There should be some other dtoverlays, just put it under those.

dtoverlay=disable-bt

go into raspi-config and enable uart

The first disables bluetooth that uses uart channel the second enables uart and disables serial console.

1 Like

Thank you, guys! it worked! What did was I rebooted my raspberry pi, reinstalled all the libraries (this time I used python 3 instead of python 2. I also changed the variable SERIAL2_BAUD to 921 using the mission planner, just as depicted here Communicating with Raspberry Pi via MAVLink — Dev documentation. I also did what @Corrado_Steri just said about the disable-bt

1 Like

I do have another problem now (same error message) but this time it is related to the dronekit-sitl so I am just gonna open another discussion.

Thank you, guys! it also worked! I have the same issue with you. however for me I can not use python 3 instead of python 2. I just changed the variable SERIAL2_BAUD to 921 using the mission planner, just as depicted at Communicating with Raspberry Pi via MAVLink — Dev documentation , and thank for jack douglas for sending recommended tecniques to me.

Thank you so much for @jax200

thanks for @Corrado_Steri

I still have the same error
can anyone help me out

maybe try reinstalling all your related software.

I have same problem please help anyone