Last Updated on : 2024-07-24 07:06:01download
This topic describes how to update the robot vacuum firmware via OTA. An over-the-air (OTA) update is the wireless delivery of new software, firmware, or other data to connected devices. TuyaOS Robot Vacuum Development Framework provides APIs to help you integrate the OTA update feature into your product easily.
The OTA firmware update process involves three components: mobile app, device, and cloud.
Tuya provides the following methods to initiate a firmware update on the user side.
OTA update condition callback: ty_dev_upgrade_pre_check_cb()
is called before each update to verify if the update condition is met. You can add restrictions in this callback.
/**
* @brief The callback for checking if the OTA update condition is met.
* @param [TY_SDK_FW_UG_T] *fw
* @return [*]
*/
INT_T ty_dev_upgrade_pre_check_cb(IN CONST FW_UG_S *fw)
{
#define BATTERY_CHECK_THREAD 30 // Battery level threshold: 30%
/*The update conditions, such as battery level, device status, etc.*/
char battery_percentage = 15;
if(battery_percentage < BATTERY_CHECK_THREAD) {//Low battery
return TUS_UPGRADE_ERROR_LOW_BATTERY;
}
/*Other conditions you add*/
return TUS_RD;
}
OTA update request callback: ty_user_upgrade_inform_cb()
, with parameters including the firmware download url
and the file size
.
INT_T ty_user_upgrade_inform_cb(IN CONST FW_UG_S *fw)
{
OPERATE_RET ret = OPRT_OK;
PR_DEBUG("Rev Upgrade Info");
PR_DEBUG("fw->fw_url:%s", fw->fw_url);
PR_DEBUG("fw->sw_ver:%s", fw->sw_ver);
PR_DEBUG("fw->file_size:%u", fw->file_size);
tuya_iot_upgrade_gw_notify(fw, __ty_user_get_file_data_cb, __ty_user_upgrade_notify_cb, NULL, true, 0);
return 0;
}
In tuya_iot_upgrade_gw_notify
, the first callback __ty_user_get_file_data_cb
returns file shard data. This function has input and output parameters. The input parameters can be used for your purpose. After you get the output parameters, you need to return whether the data has been written. Return 0
on successful writing.
The second callback __ty_user_upgrade_notify_cb
is used to display the update progress.
Replace the old firmware with the new one in __ty_user_upgrade_notify_cb
. See the demo for details.
After the firmware is downloaded, you need to implement firmware replacement and restart the device in the specified function.
OPERATE_RET __ty_user_upgrade_notify_cb(IN CONST FW_UG_S *fw, IN CONST INT_T download_result, IN PVOID_T pri_data)
{
PR_DEBUG("Upgrade Finish");
PR_DEBUG("download_result:%d fw_url:%s", download_result, fw->fw_url);
switch (download_result) {
case 0:
/* Once the OTA file is successfully downloaded to the specified path, you need to perform the OTA update. [ p_mgr_info->upgrade_file_path ]*/
break;
case OPRT_COM_ERROR:
break;
default:
// Clear the update status when receiving an update failure.
PR_DEBUG("upgrade https error:%d\n", download_result);
break;
}
// Reboot
return OPRT_OK;
}
If the OTA update fails, add the restart operation in __ty_user_upgrade_notify_cb
.
The OTA update is not reversible. If it fails, the device must be restarted.
The device downloads firmware through a URL and calls tuya_iot_dev_upgd_progress_rept
to report download progress.
/*
\fn tuya_robot_upgrade_progress_report
\brief Send update progress to the cloud and app.
\param[in] percent: Update progress in percentage, range [0,100]
\return SUCCESS - OPERATE_RET, FAIL - COMM ERROR
*/
OPERATE_RET tuya_robot_upgrade_progress_report(IN UINT_T percent)
The default timeout for OTA updates is 60 seconds. You can specify a timeout value on the Tuya Developer Platform.
The app displays the message: Update failed, possibly due to a weak signal. Please check your device’s network and try again. What could be the possible reasons for this?
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback