thingsboard-python-client-sdk icon indicating copy to clipboard operation
thingsboard-python-client-sdk copied to clipboard

[Question] Error when performing a firmware update

Open JeromeJalkh opened this issue 3 years ago • 1 comments

Hello,

I am using the TBDeviceMqttClient class from the "tb_device_mqtt.py".

I am getting this error when launching a firmware update: File "/home/ubuntu/.local/lib/python3.8/site-packages/tb_device_mqtt.py", line 324, in _on_decoded_message callback = self._attr_request_dict.pop(req_id) KeyError: 1

My question concerns the messages received by the client:

  • The client receives all the update details (fw_title, fw_version, fw_tag, fw_size, fw_checksum_algorithm, fw_checksum) on the "v1/devices/me/attributes" topic
  • Then if the versions are different the client sends a request and it receives the update on "v2/fw/request/${requestId}/chunk/${chunk}" topic
  • The client receives also a message on the "v1/devices/me/attributes/response/+" topic which includes all the changed shared attributes related to the update

When the client receives a message on the "v1/devices/me/attributes/response/+" topic, it has to get the callback function: callback = self._attr_request_dict.pop(req_id) However, the self._attr_request_dict is updated (and thus the callback is added to the dict) when the user calls the request_attributes function which calls the _add_attr_request_callback. In the case of a firmware update, no callback function was added or defined to be called when a message is received on the "v1/devices/me/attributes/response/+" topic, and as a consequence, the error is raised.

Is there any problem in the client script or am I missing something?

JeromeJalkh avatar Sep 29 '22 12:09 JeromeJalkh

I am also having this issue, preventing me from using the firmware updating feature entirely. I could resort to directly using an MQTT client, but that defeats the purpose of this SDK.

It seems indeed that the implementation of _on_decoded_message() contains conflicting blocks for handling request_attributes() and get_firmware_update() server responses (both check whether the incoming message topic contains the attribute response topic). The incoming messages are always handled as coming from a request_attributes() call, causing the issue.

Nielesonimusso avatar Mar 08 '23 15:03 Nielesonimusso