Last Updated on : 2024-06-25 03:32:14download
This topic describes how to update firmware over-the-air (OTA).
OTA technology enables the device firmware to be updated wirelessly. You can use Tuya-enabled gateways or the Tuya Smart app to deliver updates to devices, continuously enhancing the user experience.
The OTA update logic for TuyaOS Bluetooth Low Energy (LE) is handled by the component tuya_ble_ota.c
. The logic applies to all the chip platforms. The storage logic is handled by tkl_ota.c
, while the processing logic varies by chip platform.
typedef enum {
TUYA_BLE_OTA_REQ,
TUYA_BLE_OTA_FILE_INFO,
TUYA_BLE_OTA_FILE_OFFSET_REQ,
TUYA_BLE_OTA_DATA,
TUYA_BLE_OTA_END,
TUYA_BLE_OTA_UNKONWN,
} tuya_ble_ota_data_type_t;
TUYA_BLE_OTA_REQ
: Requests to initiate an OTA update.TUYA_BLE_OTA_FILE_INFO
: Reads the OTA update information.TUYA_BLE_OTA_FILE_OFFSET_REQ
: Reads the OTA update offset.TUYA_BLE_OTA_DATA
: Writes the OTA data.TUYA_BLE_OTA_END
: Finishes the OTA update.TUYA_BLE_OTA_UNKONWN
: Unknown status.typedef struct {
tuya_ble_ota_data_type_t type;
UINT16_T data_len;
UINT8_T *p_data;
} tuya_ble_ota_data_t;
type
: See tuya_ble_ota_data_type_t
.data_len
: The length of the OTA data.p_data
: The OTA data.TUYA_BLE_FEATURE_OTA_ENABLE
API description
UINT32_T tuya_ble_ota_handler(tuya_ble_ota_data_t* ota);
Direction
Parameter description
Parameter | Description |
---|---|
ota | The data of the OTA update protocol. |
API description
tuya_ble_status_t tuya_ble_ota_response(tuya_ble_ota_response_t *p_data);
Direction
Parameter description
Parameter | Description |
---|---|
p_data | The response to the OTA update request. |
API description
STATIC UINT32_T tuya_ble_ota_req_handler(UINT8_T* cmd, UINT16_T cmd_size, tuya_ble_ota_response_t* rsp)
Direction
Parameter description
Parameter | Description |
---|---|
cmd | The protocol content for the respective command. |
cmd_size | The length of the protocol content for the respective command. |
rsp | The response to the protocol content for the respective command. |
API description
STATIC UINT32_T tuya_ble_ota_file_info_handler(UINT8_T* cmd, UINT16_T cmd_size, tuya_ble_ota_response_t* rsp)
Direction
Parameter description
Parameter | Description |
---|---|
cmd | The protocol content for the respective command. |
cmd_size | The length of the protocol content for the respective command. |
rsp | The response to the protocol content for the respective command. |
API description
STATIC UINT32_T tuya_ble_ota_file_offset_handler(UINT8_T* cmd, UINT16_T cmd_size, tuya_ble_ota_response_t* rsp)
Direction
Parameter description
Parameter | Description |
---|---|
cmd | The protocol content for the respective command. |
cmd_size | The length of the protocol content for the respective command. |
rsp | The response to the protocol content for the respective command. |
API description
STATIC UINT32_T tuya_ble_ota_data_handler(UINT8_T* cmd, UINT16_T cmd_size, tuya_ble_ota_response_t* rsp)
Direction
Parameter description
Parameter | Description |
---|---|
cmd | The protocol content for the respective command. |
cmd_size | The length of the protocol content for the respective command. |
rsp | The response to the protocol content for the respective command. |
API description
STATIC UINT32_T tuya_ble_ota_end_handler(UINT8_T* cmd, UINT16_T cmd_size, tuya_ble_ota_response_t* rsp)
Direction
Parameter description
Parameter | Description |
---|---|
cmd | The protocol content for the respective command. |
cmd_size | The length of the protocol content for the respective command. |
rsp | The response to the protocol content for the respective command. |
API description
OPERATE_RET tkl_ota_get_old_firmware_info(TUYA_OTA_FIRMWARE_INFO_T **info)
This API is used for OTA resumable transfer.
Parameter description
Parameter | Description |
---|---|
info | The information about the OTA update that has been downloaded. |
The macro TUYA_BLE_FEATURE_OTA_ENABLE
is enabled by default.
See the example in tuya_ble_protocol_callback.c
.
STATIC VOID_T tuya_ble_protocol_callback(tuya_ble_cb_evt_param_t* event)
{
switch (event->evt) {
…………
case TUYA_BLE_CB_EVT_OTA_DATA: {
if (event->ota_data.p_data[0] == 0) {
#if defined(TUYA_BLE_FEATURE_OTA_ENABLE) && (TUYA_BLE_FEATURE_OTA_ENABLE == 1)
tuya_ble_ota_handler(&event->ota_data);
#endif
} else {
…………
}
} break;
…………
default: {
TAL_PR_INFO("tuya_ble_protocol_callback Unprocessed event type 0x%04x", event->evt);
} break;
}
}
VOID_T tuya_ble_protocol_init(VOID_T)
{
…………
#if defined(TUYA_BLE_FEATURE_OTA_ENABLE) && (TUYA_BLE_FEATURE_OTA_ENABLE == 1)
tuya_ble_ota_init();
#endif
…………
}
Write the license to the device for authorization.
Open the Tuya Developer Platform. In the development process of the target product, under the Hardware Development tab, choose TuyaOS for access mode and select the hardware based on the chip platform you use.
Click Add Custom Firmware and complete the required information.
Click New Firmware Version. Complete the required information, upload the firmware update, and enable the firmware.
Click OTA Updates. Click New Update Deployment and complete the required settings.
Click Verify > Add by Device ID.
Open the device panel on the mobile app and tap the pencil icon in the top right corner. Tap Device Information, copy the Virtual ID, and paste it into the dialog in the previous steps.
On the mobile app, go back to the previous page and tap Device Update. Tap Update and wait for it to complete.
If you have any problems with TuyaOS development, you can post your questions in the Tuya Developer Forum.
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback