Fix OTA firmware subscribe topic accordingly to server implementation#268
Open
neomilium wants to merge 1 commit intothingsboard:masterfrom
Open
Fix OTA firmware subscribe topic accordingly to server implementation#268neomilium wants to merge 1 commit intothingsboard:masterfrom
neomilium wants to merge 1 commit intothingsboard:masterfrom
Conversation
FIRMWARE_RESPONSE_SUBSCRIBE_TOPIC was "v2/fw/response/+" but the ThingsBoard server only accepts "v2/fw/response/+/chunk/+". The wrong topic caused a SUBACK rejection on every MQTT connect, which in turn made the SDK send fw_state=FAILED / fw_error="Subscribing the given topic (v2/fw/response/+) failed" as telemetry — polluting the device firmware state on the dashboard. The subscribe topic was also inconsistent with its two sibling constants defined on adjacent lines (FIRMWARE_RESPONSE_TOPIC and FIRMWARE_REQUEST_TOPIC), both of which already include the /chunk/ segment. Server reference: MqttTopics.DEVICE_FIRMWARE_RESPONSES_TOPIC resolves to "v2/fw/response/+/chunk/+" and MqttTransportHandler.processSubscribe() rejects anything else with TOPIC_FILTER_INVALID.
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.
On every MQTT connection, the device reports a firmware error to ThingsBoard:
OTA checking and downloading still work — the subscribe failure does not prevent
firmware updates. However, the device's firmware state on the ThingsBoard
dashboard permanently shows FAILED, which is misleading and prevents
reliable monitoring of actual OTA status.
Bug
FIRMWARE_RESPONSE_SUBSCRIBE_TOPICis set to"v2/fw/response/+", but theThingsBoard server only accepts subscriptions to
"v2/fw/response/+/chunk/+".The subscribe topic is inconsistent with the two other topic constants defined
right next to it, both of which include the
/chunk/segment.The ThingsBoard MQTT transport handler (
MqttTransportHandler.java) validatessubscribe topics with an exact-match
switchstatement. The only acceptedfirmware response topic is
DEVICE_FIRMWARE_RESPONSES_TOPIC, which resolves to"v2/fw/response/+/chunk/+":Any topic that doesn't match a
casefalls through todefault, which returnsTOPIC_FILTER_INVALIDin the SUBACK:When
Firmware_OTA_Subscribe()detects the failure, it sendsFirmware_Send_State(FW_STATE_FAILED, message)to the server — polluting thedevice's firmware state.
Additional note: MQTT wildcard mismatch
Even if the server accepted
v2/fw/response/+, the subscription would nevermatch firmware chunks. The server publishes to topics like
v2/fw/response/42/chunk/0(5 levels). The MQTT+wildcard matches exactlyone topic level (MQTT spec §4.7.1), so
v2/fw/response/+(4 levels) cannotmatch.
Why OTA still works despite the error
Resubscribe_Topics()callsFirmware_OTA_Subscribe()on every MQTT connect.This is the code path that triggers the spurious
FAILEDstate. It runsunconditionally, even when no firmware update is in progress. The return value
is discarded:
(void)api->Resubscribe_Topic().The actual OTA check and download paths are unaffected:
v1/devices/me/attributes/response/+,a completely separate MQTT path that works correctly.
Firmware_Shared_Attribute_Received(),calls
Firmware_OTA_Subscribe()again independently. Whether this second callsucceeds or fails depends on the MQTT client implementation — some clients
tolerate SUBACK errors and still deliver matching messages.
The only visible impact is the false
FAILEDstate on the server dashboard,which is reported on every connect regardless of whether an update is in progress.