Skip to content

feat(mqtt): fall back to WebSocket when UDP audio is blocked - #2339

Open
suharvest wants to merge 1 commit into
78:mainfrom
suharvest:feat/mqtt-udp-websocket-fallback
Open

suharvest wants to merge 1 commit into
78:mainfrom
suharvest:feat/mqtt-udp-websocket-fallback

Conversation

@suharvest

Copy link
Copy Markdown

Problem

Closes #2338.

On networks that drop UDP (e.g. behind a transparent proxy), MQTT signaling works but the UDP audio channel is dead: reply text shows up, no TTS audio plays, and the user's speech never gets an stt.

Solution

  • MqttProtocol counts received UDP packets. A tts segment with at least one sentence_start, lasting ≥ 1 s, and zero UDP packets marks UDP as blocked.
  • If a WebSocket URL is configured, this is stored per network (AP BSSID) in NVS and the device reboots; InitializeProtocol() then picks WebSocket.
  • The fallback lasts 10 boots on that network, then MQTT is retried (period doubles on repeated failure, max 200). A TTS segment that receives UDP audio clears it.
  • Kconfig MQTT_UDP_FALLBACK_TO_WEBSOCKET (default y).

Testing

SenseCAP Watcher on a network that drops UDP:

W (32358) MQTT: TTS segment (3 sentences, 7022 ms) delivered no UDP audio
E (32361) MQTT: UDP audio is blocked on this network; rebooting into WebSocket for 10 boots
...
W (5196) MQTT: UDP audio was blocked on this network, using WebSocket (9 boots left)
I (41907) Application: >> 你好小智
I (81459) Application: >> Oh it it.

Builds: sensecap-watcher, bread-compact-ml307.

On networks that drop UDP (e.g. behind a transparent proxy), MQTT
signaling works but the UDP audio channel is dead: reply text shows up,
no TTS audio plays, and speech never gets an stt.

MqttProtocol counts received UDP packets. A tts segment that announced
sentences, lasted at least 1 s and received no UDP packet marks UDP as
blocked. If a WebSocket URL is configured, the decision is stored per
network (AP BSSID) and the device reboots; InitializeProtocol() then
picks WebSocket. The fallback lasts 10 boots on that network, doubling
up to 200 on repeated failure, and is cleared once UDP audio arrives.

Controlled by MQTT_UDP_FALLBACK_TO_WEBSOCKET (default y).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Fall back to WebSocket when MQTT's UDP audio is blocked

1 participant