Last Updated on : 2024-06-24 10:18:02download
The main network module can have different subordinate modules (such as controllers and voice modules) mounted to support various use cases. The TuyaOS framework supports OTA updates for the firmware on these modules.
Update channel ID: Used to associate with the channel for updating the device firmware, files, or configurations.
Generic channel ID: The fixed channels used to update the specified types of firmware, ranging from 0 to 9.
Name | Channel ID | Description |
---|---|---|
DEV_NM_ATH_SNGL | 0 | The update channel for the main network firmware. |
DEV_BLE_SNGL | 1 | The update channel for the Bluetooth firmware. |
DEV_ZB_SNGL | 3 | The update channel for the Zigbee firmware. |
DEV_NM_NOT_ATH_SNGL | 9 | The update channel for the MCU firmware. |
Custom channel ID: Assigned based on your needs, ranging from 10 to 19.
Name | Channel ID | Description |
---|---|---|
DEV_ATTACH_MOD_x | ≥ 10 | The custom update channels. |
Update the firmware on multiple subordinate modules.
Multiple update methods are available.
The update methods for the subordinate firmware are the same as those for the main network firmware. Subordinate firmware also supports automatic updates.
The application can reject an update request.
The update process and the trigger of silent updates for the subordinate firmware are the same as those for the main network firmware. See How the firmware update works for the main network module.
tuya_iot_com_api.h
tuya_devos_utils.h
Create firmware on the Tuya Developer Platform, choose the firmware type and channel, and obtain the firmware key.
Call the device initialization API.
Register the channel ID and firmware version for the subordinate firmware.
Register the callback gw_ug_cb
to get notified when a subordinate firmware update starts.
(Optional) Register the callback pre_gw_ug_cb
to get notified when the framework receives an update request.
To reject an update request, set the return value of this callback to anything other than OPRT_OK
.
When notified of the start of a subordinate firmware update, call the API to download the update package.
After the update is installed, update the version number of the subordinate firmware.
/**
* @brief tuya_iot_upgrade_gw_notify
* @desc upgrage gateway firmware
*
* @param[in] fw: firmware info
* @param[in] get_file_cb: download content storage callback
* @param[in] upgrd_nofity_cb: firmware download finish callback
* @param[in] pri_data: private param of get_file_cb && upgrd_nofity_cb
* @param[in] notify: notify app the upgrade status
* @param[in] download_buf_size: max download buffer size when downloading
*
* @return OPRT_OK: success Other: fail
*/
OPERATE_RET tuya_iot_upgrade_gw_notify(IN CONST FW_UG_S *fw,
IN CONST GET_FILE_DATA_CB get_file_cb,
IN CONST UPGRADE_NOTIFY_CB upgrd_nofity_cb,
IN CONST PVOID_T pri_data,
BOOL_T notify, UINT_T download_buf_size);
#define tuya_iot_upgrade_gw(fw, get_file_cb, upgrd_nofity_cb, pri_data) \
tuya_iot_upgrade_gw_notify(fw, get_file_cb, upgrd_nofity_cb, pri_data, TRUE, 0)
typedef struct {
/** attach ota channel */
GW_PERMIT_DEV_TP_T tp;
/** attach version, format xx.xx.xx */
CHAR_T ver[SW_VER_LEN + 1];
CHAR_T md5[SW_MD5_LEN + 1];
} GW_ATTACH_ATTR_T;
/**
* @brief set versions of pointer attach module.
*
* @param[in] tp: type of attach module
* @param[in] attr: attributes of attach module
*
* @note This API is used for attach modules updating in case of firmware update
* Info of main network module will also be included when upload.
*
* @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
*/
OPERATE_RET tuya_iot_dev_set_attach_attr(GW_PERMIT_DEV_TP_T tp, GW_ATTACH_ATTR_T * attr);
After downloading the Networked Product Development Framework, you can find the example code for all features in the tuyaos_demo_examples
folder under the apps
directory. See the code in examples/service_ota/example_attach_ota.c
. For the usage of the example code, see TuyaOS Example Collection.
Check if the version number of the subordinate firmware has been updated. The app determines the update result based on the current version number.
The priority is THREAD_PRIO_3
.
The update task is of the lowest priority in the TuyaOS framework. The OTA task does not automatically enter sleep mode, but it can be blocked when receiving data. If network data is consistently accessible, OTA tasks will not release CPU resources proactively. Tasks with lower priority than THREAD_PRIO_3
may not be executed.
The framework does not respond to DP commands during an update.
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback