Accessing real-time MAVLink messages via pymavlink

Hi @Kolappan ,

You can use the code below for reading the message that you’ve requested:

def get_requested_data(master, message_name: str, dict_key: str, value_unit: str, save_name: str):

    try:

        message_index = 0

        dict1 = master.recv_match(type= message_name, blocking=True, timeout=0.1).to_dict()

        dict_value = dict1[dict_key]

       

        toWrite = "Message_Index, " + message_index + " :" + str(dict_value) + value_unit

        with open(save_name, 'a') as file:

            file.write(toWrite)

            file.write('\n')  

            message_index += 1

    except:

        pass

If you just want to monitor the data on Terminal instead of saving it to a file, you can go with deleting the lines below and simply use a print function:

toWrite = "Message_Index, " + message_index + " :" + str(dict_value) + value_unit

        with open(save_name, 'a') as file:

            file.write(toWrite)

            file.write('\n')  

            message_index += 1

And here is the example usage of the loop code:

request_message_interval(master, "VFR_HUD", 1)

while True:

    try:

        get_requested_data(master, "VFR_HUD", 'alt', "m", save_name)

    except:

        pass