Here is my code:
from pymavlink import mavutil
def request_messages(a):
""" Requesting MAVLink messages"""
a.mav.command_long_send(
a.target_system,
a.target_component,
mavutil.mavlink.MAV_CMD_REQUEST_MESSAGE,
253,
0, 0, 0, 0, 0, 0, 0
)
print(a.recv_match(type='COMMAND_ACK', blocking=True, timeout=2))
while True:
print(a.recv_match(type='STATUSTEXT', blocking=True, timeout=10))
connection = mavutil.mavlink_connection('/dev/ttyACM2')
print(connection.mav.heartbeat_send(mavutil.mavlink.MAV_TYPE_ONBOARD_CONTROLLER, mavutil.mavlink.MAV_AUTOPILOT_INVALID, 0, 0, 0))
connection.wait_heartbeat()
print("Heartbeat from system (system %u component %u)" % (connection.target_system, connection.target_component))
request_messages(connection)
Output:
None
Heartbeat from system (system 1 component 0)
COMMAND_ACK {command : 512, result : 0, progress : 0, result_param2 : 0, target_system : 255, target_component : 0}
None
None
None
STATUSTEXT {severity : 2, text : PreArm: Hardware safety switch, id : 0, chunk_seq : 0}
STATUSTEXT {severity : 2, text : PreArm: AHRS: EKF3 Yaw inconsistent 130 deg. Wait , id : 7, chunk_seq : 0}
STATUSTEXT {severity : 2, text : or reboot, id : 7, chunk_seq : 1}
STATUSTEXT {severity : 2, text : PreArm: GPS 1: Bad fix, id : 0, chunk_seq : 0}
STATUSTEXT {severity : 2, text : PreArm: Battery 1 unhealthy, id : 0, chunk_seq : 0}
STATUSTEXT {severity : 2, text : PreArm: Waiting for RC, id : 0, chunk_seq : 0}
None
None
I don’t think we can ask for “STATUSTEXT” message as after the request message it is unable to print it. Even in my code inside the def method I tried the while loop and within which only receiving request and STATUSTEXT revcmatch. Then also no luck in getting these messages
Sample Code:
def request_messages(a):
""" Requesting MAVLink messages"""
while True:
a.mav.command_long_send(
a.target_system,
a.target_component,
mavutil.mavlink.MAV_CMD_REQUEST_MESSAGE,
253,
0, 0, 0, 0, 0, 0, 0
)
print(a.recv_match(type='STATUSTEXT', blocking=True, timeout=2))
Output:
None
Heartbeat from system (system 1 component 0)
None
None
None
None
None
STATUSTEXT {severity : 2, text : PreArm: Hardware safety switch, id : 0, chunk_seq : 0}
STATUSTEXT {severity : 2, text : PreArm: AHRS: EKF3 Yaw inconsistent 131 deg. Wait , id : 20, chunk_seq : 0}
STATUSTEXT {severity : 2, text : or reboot, id : 20, chunk_seq : 1}
STATUSTEXT {severity : 2, text : PreArm: GPS 1: Bad fix, id : 0, chunk_seq : 0}
STATUSTEXT {severity : 2, text : PreArm: Battery 1 unhealthy, id : 0, chunk_seq : 0}
STATUSTEXT {severity : 2, text : PreArm: Waiting for RC, id : 0, chunk_seq : 0}
None
None