Recv_match returns outdated messages, how get in real time messages?

I request 1 time per second a message about the position of the RC_CHANNELS, but recv_match gives me outdated messages (see time_boot)

I know that if I constantly make requests everything will be fine, but I want to handle the case when the data stops being synchronized, how can I fix it? Dirty solution to reconnect via mavutil.mavlink_connection but maybe there is a better solution?

import time
from pymavlink import mavutil

master = mavutil.mavlink_connection('/dev/serial0', baud=921600)


while True:
    message = master.recv_match(type='RC_CHANNELS', blocking=True).to_dict()
    print('time_boot sec:',message['time_boot_ms']/1000, message)
    time.sleep(1)#1sec sleep

any advice would be greatly appreciated)

You could drain the queue and keep just the last message. Something like this:

while True:

  # Drain the queue, saving the last message
  msg = None
  while temp := mav.recv_msg(type='RC_CHANNELS')
    msg = temp

  # If there were no messages, wait for one
  if msg is None:
    msg = mav.recv_msg(type='RC_CHANNELS', blocking=True)

1 Like

thank you very much - that’s what I need)