Firmware Update

Last Updated on : 2024-07-23 10:24:24download

Users use the mobile app to check for device firmware updates and initiate the update process. This topic describes the process of how firmware updates work on the device, including receiving an update request, performing the update, reporting progress, and completing the update.

Detect update

Operation

Users will be prompted to update the firmware when they open the device preview screen if an update is available.

Alternatively, users tap the target device on the mobile app to enter the device panel. Tap the settings button in the top right corner, find Device Update, and select the update to install.

Code

The device firmware can detect an update using the registered callback below, which will be triggered when an update is initiated.

ipc_sdk_run_var.upgrade_info.upgrade_cb = TUYA_IPC_Upgrade_Inform_cb;

To update the main firmware and extended firmware, see the DEV_TYPE_T tp; parameter in FW_UG_S.

See the ty_sdk_upgrade.c implementation in app_user_upgrade. Call the following functions in TUYA_IPC_Upgrade_Inform_cb to register callbacks for data requests and update status notifications.

OPERATE_RET tuya_ipc_upgrade_sdk(IN CONST FW_UG_S *fw,
                                 IN CONST GET_FILE_DATA_CB get_file_cb,
                                 IN CONST UPGRADE_NOTIFY_CB upgrd_nofity_cb,
                                 IN PVOID_T pri_data);

Perform update

During the update process, you only need to manage the parameters of these two callbacks:

  • GET_FILE_DATA_CB get_file_cb
  • UPGRADE_NOTIFY_CB upgrd_nofity_cb

The SDK sends the update file in packets using get_file_cb. You must handle caching or processing the received packet.

Report progress

Use the following function to report the update progress. The reporting interval is subject to your requirements.

OPERATE_RET tuya_ipc_upgrade_progress_report(IN UINT_T percent);

To report the version of the extended firmware, see the following.

OPERATE_RET tuya_ipc_upgrade_progress_report_by_type(IN UINT_T percent, IN BYTE_T type);
//type  refer to  FW_UG_S -> DEV_TYPE_T tp

Finish update

After installing the update, the device needs to update its firmware version and report the latest number to the cloud upon restarting. If the version number is verified successfully, an update success message will be displayed on the mobile app. See the example code below:

strcpy(env.dev_sw_version, pRunInfo->iot_info.dev_sw_version);

The extended firmware calls the following function to update its version number.

OPERATE_RET tuya_iot_dev_update_attachs(UINT_T attr_num, GW_ATTACH_ATTR_T *attrs)