fix(mtp): MQTT 3.1.1 agent compatibility for mqtt broker and mqtt-adapter - #407
Open
DevenDucommun wants to merge 1 commit into
Open
fix(mtp): MQTT 3.1.1 agent compatibility for mqtt broker and mqtt-adapter#407DevenDucommun wants to merge 1 commit into
DevenDucommun wants to merge 1 commit into
Conversation
…pter MQTT 3.1.1 USP agents (e.g. OB-USP-Agent/obuspa in 3.1.1 mode) cannot use MQTT 5.0 Response Topic or User Properties, and encode their reply topic as a 'reply-to=<url-encoded topic>' suffix appended to the publish topic instead. Against current dev, such agents connect but cannot complete any USP exchange. Five fixes, verified end-to-end against a real obuspa 3.1.1 agent on Linksys hardware: - adapter: guard nil NoSessionContext when parsing device info records (MqttConnect records have no payload; previously panicked) and register the device with basic info instead. - mqtt broker: fall back to the MQTT client ID in OnSubscribed and OnDisconnect status events when no MQTT5 User Properties are present, so 3.1.1 devices still get online/offline status published. - mqtt-adapter: resolve 'reply-to=' encoded segments when mapping incoming MQTT topics to NATS subjects (device ID extraction) and outgoing NATS subjects to MQTT topics (agent topic resolution); previously the literal 'reply-to=...' string leaked into NATS subjects and MongoDB device IDs. - mqtt-adapter: embed the api response topic as a 'reply-to=' suffix on downlink publishes, since 3.1.1 agents cannot see the MQTT5 ResponseTopic property; without it agents answer on their controller topic and API requests time out. - mqtt-adapter: additionally subscribe 'oktopus/usp/+/api/+/+' and 'oktopus/usp/+/controller/+/+' — 3.1.1 agent replies carry the reply-to suffix as an extra topic level, one deeper than the existing filters, so the broker never delivered them to the bridge.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
MQTT 3.1.1 USP agents (e.g. OB-USP-Agent / obuspa configured with
ProtocolVersion 3.1.1) can't use the MQTT 5.0Response TopicorUser Propertiesfeatures. Per the USP MQTT binding, they instead encode the reply topic as areply-to=<url-encoded topic>suffix appended to the publish topic. Against currentdev, such an agent connects to the broker but cannot complete any USP exchange:MqttConnectrecord;reply-to=...leaks into NATS subjects and MongoDB device IDs;reply-to=suffix, which is both the wrong routing path for the API waiter and one topic level deeper than the bridge's subscription filters, so the reply is silently never delivered.Fixes (all in this PR, one per bullet)
NoSessionContextwhen parsing device-info records;Record_MqttConnecthas no payload — register the device with basic info instead of panicking.OnSubscribed/OnDisconnect, fall back to the MQTT client ID when no MQTT5 User Properties are present, so 3.1.1 devices still get status events (client ID is the agent's configuredClientID).reply-to=segments when extracting the device ID from incoming topics, and when resolving the agent topic for outgoing publishes.reply-to=suffix on downlink publishes (3.1.1 agents can't see the MQTT5ResponseTopicproperty) so agent replies route back to the API waiter.oktopus/usp/+/api/+/+andoktopus/usp/+/controller/+/+— agent replies carry thereply-to=suffix as an extra topic level, one deeper than the existing filters.MQTT 5.0 agents are unaffected: User Properties still take precedence in the broker hooks, the MQTT5
ResponseTopicproperty is still set, and the extra subscriptions/decoding only engage when areply-to=segment is actually present.Testing
Validated end-to-end against a real OB-USP-Agent (obuspa) in MQTT 3.1.1 mode on Linksys router hardware, with the compose stack (
nats controller adapter mqtt frontendprofiles):reply-to=artifacts in MongoDB);OperSuccess;ValueChangesubscription Notify (triggered by a controller-side Set) was captured delivering through broker → mqtt-adapter → NATS;docker buildon each service'sbuild/Dockerfile).Happy to split this into separate PRs per service if you prefer.