Skip to content

Send telemetry to known GCSes by unicast - #5

Open
peterbarker wants to merge 1 commit into
ArduPilot:masterfrom
peterbarker:wifi-unicast
Open

peterbarker wants to merge 1 commit into
ArduPilot:masterfrom
peterbarker:wifi-unicast

Conversation

@peterbarker

@peterbarker peterbarker commented Nov 15, 2026 •

Copy link
Copy Markdown

Summary

Send telemetry to each GCS that has talked to us by unicast instead of broadcasting every MAVLink message. Broadcasts lost 3-6% of messages over WiFi; unicast loses next to none, so ATTITUDE now reaches the GCS at the rate the flight controller sends it.

Description

Every MAVLink message from the flight controller went to WiFi as its own UDP broadcast to 255.255.255.255:14550. The radio sends a broadcast once, unacknowledged and at the basic rate, so whatever doesn't arrive is gone. The flight controller was sending the full 4 Hz and the Sonix forwarded it promptly; the loss was all on the WiFi hop. Unicast pings over the same link lost nothing.

With this change:

  • the UDP socket is read with recvfrom(), and the address of each GCS that sends us a MAVLink message is remembered (up to four, forgotten after 5 seconds of silence) as soon as its first message parses, so the reply to a camera command that is its first message reaches it; anything that doesn't parse as MAVLink is ignored, as is our own address
  • each remembered GCS gets its own unicast copy of the telemetry, which WiFi acknowledges and retries
  • HEARTBEAT is still broadcast, so a GCS that hasn't sent anything yet can find the vehicle, and is also sent to any GCS on a port other than 14550, which the broadcast doesn't reach
  • with no GCS known, everything is broadcast as before
  • the mavunicast 0|1 console command turns unicast off and on until the next boot, and mavlink status lists the GCSes
  • the FC packet count on the web page still counts each message once, however many GCSes it goes to

A GCS that only listens and never sends to UDP 14550 gets only heartbeats while another GCS is connected. QGroundControl, MAVProxy and Mission Planner all send heartbeats, so they are unaffected.

Testing

On a SkyViper, measured at the GCS from the flight controller's sequence numbers, switching mavunicast on the same firmware:

GCS Broadcast Unicast
Linux PC (USB WiFi), ATTITUDE at 4 Hz 2.7-2.9% lost, ATTITUDE 3.84-3.89 Hz 0.1-0.2% lost, ATTITUDE 4.00 Hz
Linux PC (USB WiFi), ATTITUDE at 50 Hz 5.5-6.0% lost, ATTITUDE ~45 Hz 0.1% lost, ATTITUDE ~50 Hz
Android phone, QGroundControl 5.1.5 loss counter climbing loss counter not moving

No repeated or out-of-order messages in any of these. One combination did show them: a PC's built-in card (MediaTek mt7921e) with WiFi power save on got 16% of unicast messages out of order, up to 2.4 s late; with power save off it was clean. The phone did not show this with QGroundControl in the foreground.

A GCS on another port, with a passive listener on 14550 alongside it:

GCS on port 37366 Listener on 14550 receives GCS receives
sends nothing everything (broadcast) nothing
sends non-MAVLink data everything (broadcast) nothing; not taken as a GCS
sends HEARTBEAT HEARTBEAT only everything, HEARTBEAT included, ATTITUDE at 50 Hz
silent for over 5 s everything again (broadcast) nothing

With one GCS already known, a new GCS whose first packet is MAV_CMD_REQUEST_CAMERA_INFORMATION to the camera got the COMMAND_ACK and CAMERA_INFORMATION in each of 4 tries.

@AP-Review

AP-Review commented Nov 15, 2026 •

Copy link
Copy Markdown

Deprecated — see below for the updated review.

Previous review (2026-11-15)

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: COMMENT

Reviewed at head 4f124a8a90.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/skyrockettoys-sonix/5/1.html#prSkyRocketToys-Sonix-5

This works as described and builds cleanly at 4f124a8, with no blocking issues. A few small behaviour and diagnostic points are worth a look.

Should fix

  • mavlink_wifi.c:2083: every UDP datagram registers its sender as a GCS before it is parsed, so stray traffic or another vehicle's broadcast switches off the telemetry broadcast for passive listeners on 14550, which then see only heartbeats (R333). Register only after a valid MAVLink frame, and note the behaviour change and the non-persistent mavunicast 0 in the PR.
  • mavlink_wifi.c:322: a GCS learned on a port other than 14550 gets telemetry but no heartbeats. Unicast HEARTBEAT to clients whose port is not MAVLINK_DEST_PORT. Doing that for all clients would send duplicate heartbeats to 14550 listeners.
Minor (2)
  • mavlink_wifi.c:307: sent_pkts now counts once per destination, so mavlink_fc_pkt_count() (the APWeb FC MAVLink count) scales with the number of GCSes. Count messages separately or relabel it.
  • mavlink_wifi.c:2217: inet_ntoa uses a shared static buffer that the telemetry task can overwrite mid-print. Use inet_ntoa_r with a local buffer here and at R301.

Not fully reviewed: on-hardware WiFi loss and recovery, and real GCS or phone-app interoperability, were not tested.

@AP-Review

AP-Review commented Nov 15, 2026 •

Copy link
Copy Markdown

Deprecated — see below for the updated review.

Previous review (2026-11-15)

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: COMMENT

Reviewed at head 288eecfec9.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/skyrockettoys-sonix/5/2.html#prSkyRocketToys-Sonix-5

This builds at 288eecf and nothing blocks, but one ordering problem is worth fixing.
Since the review at 4f124a8, all four earlier points are fixed: registration needs a valid MAVLink frame, heartbeats go to clients on other ports, the packet count is per message again, and the prints use inet_ntoa_r.

Should fix

  • mavlink_wifi.c:251: camera replies are sent from inside camera_udp_input before wifi_client_seen runs (R254). While another GCS is known, a new GCS's first camera command or param request is answered only to the others. Before this PR that reply was broadcast to 14550. Register the sender where *framed is set, before the switch.
Minor (2)
  • mavlink_wifi.c:1128: framed comes from one static parser shared by all senders, so a partial frame left by one sender's truncated (>300 byte) datagram eats another sender's next heartbeat and delays its registration. Resetting the parser state at the start of each datagram avoids this.
  • mavlink_wifi.c:291: get_local_ip() copies from lwIP's shared ip_ntoa buffer, which other tasks also write, so the self check can race and register our own IP as a GCS. Comparing from->sin_addr with EMAC_if.ip_addr.addr directly avoids the race and the string conversion.

Not fully reviewed: on-hardware WiFi loss and recovery, the claimed broadcast-loss improvement, and real GCS or phone-app interoperability were not tested.

Every MAVLink message went to WiFi as a broadcast, which the radio
sends once, unacknowledged and at the basic rate.  5-10% of them
never reached the GCS, more at higher message rates, while unicast
pings over the same link lost none.

Note the address of each GCS that sends us MAVLink (up to four,
forgotten after 5 seconds of silence) and send each of them its own
unicast copy, which WiFi acknowledges and retries.  HEARTBEAT is still
broadcast, so a GCS that hasn't sent anything yet can find us, and is
also sent to any GCS on a port other than 14550, which the broadcast
doesn't reach.  Everything is broadcast while no GCS is known.

While a GCS is known, a program that only listens on 14550 and never
sends gets only heartbeats.  QGroundControl, MAVProxy and Mission
Planner all send heartbeats, so they are unaffected.

The mavunicast console command turns this off (0) or on (1) until the
next boot, and "mavlink status" lists the GCSes.  The FC packet count
shown on the web page still counts each message once, however many
GCSes it goes to.
@AP-Review

Copy link
Copy Markdown

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: ACCEPT

Reviewed at head 5a6f9fb64f.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/skyrockettoys-sonix/5/3.html#prSkyRocketToys-Sonix-5

This looks good to merge at 5a6f9fb. It builds, and none of the three review passes found anything new.
Since the review at 288eecf, all three points are fixed. A new GCS is now registered before its first camera command is answered. The parser state is reset for each datagram. The self check compares with EMAC_if directly.

Not fully reviewed: on-hardware WiFi loss and recovery, the claimed broadcast-loss improvement, and real GCS, phone-app or passive-listener interoperability were not tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants