Last Updated on : 2024-06-07 07:09:29download
Firmware update is the process to flash new firmware to a chip and update the earlier firmware. Tuya supports regular firmware updates to meet your development and market requirements. Tuya also deactivates certain legacy firmware versions in line with chip iterations of the manufacturers. In the case of device feature updates, a firmware update is also required.
Returns the device update information. The firmware update model ThingSmartFirmwareUpgradeModel
provides the following properties:
upgradeMode
: indicates the firmware update mode.type
: indicates the firmware update channel type.typeDesc
: describes the firmware type.Firmware update modes
When you query the list of firmware updates, the upgradeMode
field of ThingSmartFirmwareUpgradeModel
includes the following valid values:
Generic firmware update: The field value is 0
. This is the traditional mode to update device firmware.
Update PID-specific firmware: The field value is 1
. This update mode applies the philosophy of products. Update versions can be differentiated by functional modules, such as product schema, panel settings, multilingual settings, and shortcut control.
The new API methods are required to get the firmware list and trigger a PID-specific firmware update.
Firmware update channel types
For the generic firmware update mode, when you query a list of firmware updates, the type
field of ThingSmartFirmwareUpgradeModel
indicates the type of firmware update channel and typeDesc
describes each channel.
The following table lists descriptions of type
for a generic firmware update. We recommend that you describe the firmware by using the value of typeDesc
that is actually returned by the model.
Channel type of generic firmware update | Description of firmware update channel |
---|---|
0 | Main module, Wi-Fi module, and Bluetooth module. |
1 | Bluetooth module |
2 | GPRS module |
3 | Zigbee module |
5 | 433 MHz module |
6 | NB-IoT module |
9 | MCU module |
10 to 19 | Extension module |
API description
// Returns firmware information required by generic update and PID-specific update.
- (void)checkFirmwareUpgrade:(void (^)(NSArray<ThingSmartFirmwareUpgradeModel *> *firmwares))success failure:(nullable ThingFailureError)failure;
// (Deprecated) Returns only the firmware information required by generic update.
- (void)getFirmwareUpgradeInfo:(nullable void (^)(NSArray <ThingSmartFirmwareUpgradeModel *> *upgradeModelList))success failure:(nullable ThingFailureError)failure;
Parameters
Parameter | Description |
---|---|
success | The success callback. A list of firmware update information is returned. |
failure | The failure callback. |
Data model of ThingSmartFirmwareUpgradeModel
Field | Type | Description |
---|---|---|
desc | NSString | The description of the update. |
type | NSInteger | The type of firmware update channel. The value is used for a generic firmware update. |
typeDesc | NSString | The description of the firmware update channel. |
upgradeStatus | NSInteger |
|
version | NSString | The target firmware version. |
currentVersion | NSString | The current firmware version. |
devType | NSInteger |
|
upgradeType | NSInteger |
|
url | NSString | The URL at which the firmware update package of the Bluetooth device can be downloaded. |
fileSize | NSString | The size of the firmware update package. Unit: bytes. FileSize only supports Bluetooth devices. |
md5 | NSString | The MD5 (Message-Digest algorithm 5) hash value of the firmware. |
controlType | BOOL |
|
waitingDesc | NSString | The description of waiting for the device to wake up. |
upgradingDesc | NSString | The description of the firmware update in progress. |
canUpgrade | NSNumber |
|
remind | NSString | The description of a failed pre-validation. |
upgradeMode | ThingSmartDeviceUpgradeMode | The type of firmware update. Valid values:
|
Example
Objective-C:
- (void)getFirmwareUpgradeInfo {
// self.device = [ThingSmartDevice deviceWithDeviceId:@"your_device_id"];
[self.device checkFirmwareUpgrade:^(NSArray<ThingSmartFirmwareUpgradeModel *> *upgradeModelList) {
NSLog(@"getFirmwareUpgradeInfo success");
} failure:^(NSError *error) {
NSLog(@"getFirmwareUpgradeInfo failure: %@", error);
}];
}
Swift:
func getFirmwareUpgradeInfo() {
device?.checkFirmwareUpgrade({ (upgradeModelList) in
print("getFirmwareUpgradeInfo success")
}, failure: { (error) in
if let e = error {
print("getFirmwareUpgradeInfo failure: \(e)")
}
})
}
Returns information about the firmware being updated. If no firmware is being updated, a failure
is returned.
API description
- (void)getFirmwareUpgradingStatus:(void (^)(ThingSmartFirmwareUpgradeStatusModel *status))success failure:(nullable ThingFailureError)failure
Parameters
Parameter | Description |
---|---|
success | The success callback. An update status model is returned. |
failure | The failure callback. An error message is returned to indicate that the device is not being updated or the API request failed. |
Data model of ThingSmartFirmwareUpgradeStatusModel
Field | Type | Description |
---|---|---|
upgradeStatus | ThingSmartDeviceUpgradeStatus | The update status. Valid values:
|
statusText | NSString | The description of the firmware status. |
statusTitle | NSString | The title of the firmware status. |
progress | NSInteger | The update progress. In certain conditions, the value might be less than 0. If any, ignore this type of value. |
type | NSInteger | The type of firmware update channel. The value is used when users confirm the update. |
upgradeMode | ThingSmartDeviceUpgradeMode |
|
error | NSError | The error message. |
Example
Objective-C:
- (void)getFirmwareUpgradeInfo {
// self.device = [ThingSmartDevice deviceWithDeviceId:@"your_device_id"];
[self.device getFirmwareUpgradingStatus:^(ThingSmartFirmwareUpgradeStatusModel *status) {
NSLog(@"getFirmwareUpgradingStatus success");
} failure:^(NSError *error) {
NSLog(@"getFirmwareUpgradingStatus failure: %@", error);
}];
}
Swift:
func getFirmwareUpgradeInfo() {
device?.getFirmwareUpgradingStatus({ (status) in
print("getFirmwareUpgradingStatus success")
}, failure: { (error) in
if let e = error {
print("getFirmwareUpgradingStatus failure: \(e)")
}
})
}
API description
// Both generic update and PID-specific update are supported.
// Based on the original update capabilities, Bluetooth LE devices and Bluetooth mesh dynamic gateways are also supported.
// Multiple firmware versions can be sequentially updated for the same device.
- (void)startFirmwareUpgrade:(NSArray<ThingSmartFirmwareUpgradeModel *> *)firmwares
// Deprecated. - startFirmwareUpgrade: is recommended to initiate an update.
// Only generic firmware update is supported. Only Wi-Fi devices and Zigbee sub-devices are supported. Bluetooth LE devices are not supported.
// Only a single firmware update task can be initiated.
// type: the type of update. You can call getFirmwareUpgradeInfo to get the value.
- (void)upgradeFirmware:(NSInteger)type success:(nullable ThingSuccessHandler)success failure:(nullable ThingFailureError)failure;
Parameters
-startFirmwareUpgrade
Parameter | Description |
---|---|
firmwares | You can call getFirmwareUpgradeInfo to get a list of firmware versions. |
success | The success callback. |
failure | The failure callback. |
-upgradeFirmware:success:failure:
Parameter | Description |
---|---|
type | The type of update. You can call getFirmwareUpgradeInfo to get the value. |
success | The success callback. |
failure | The failure callback. |
The list returned by getFirmwareUpgradeInfo
includes the following status information:
No new version (upgradeStatus: 0
)
New version available (upgradeStatus: 1
)
Updating (upgradeStatus: 2
)
Wait for the device to wake up (upgradeStatus: 5
)
The status information is displayed to indicate the update status. An update can be initiated only when a new version is available (upgradeStatus: 1
). You need to implement the features to filter and display the status information on your own.
Certain devices require a pre-validation before an update. Call getFirmwareUpgradeInfo
to get a list of firmware information. Check the value of canUpgrade
in the object of the update information model ThingSmartFirmwareUpgradeModel
.
Value result | Value |
---|---|
Pre-validation is not required and update is allowed. | canUpgrade == nil |
Pre-validation is required and failed, so update is not allowed. | canUpgrade != nil && canUpgrade.integerValue == 0 |
Pre-validation is required and passed, so update is allowed. | canUpgrade != nil && canUpgrade.integerValue == 1 |
If a pre-validation is required and an update is allowed only after the pre-validation is passed, remind
can be used to return the description that an update is not allowed.
Example
Objective-C:
- (void)upgradeFirmwareNew {
// self.device = [ThingSmartDevice deviceWithDeviceId:@"your_device_id"];
// firmwares: the list of firmware information returned by getFirmwareUpgradeInfo.
// Note that the firmware versions that do not meet the preceding rules must be filtered out.
[self.device startFirmwareUpgrade:firmwares];
}
Swift:
func upgradeFirmware() {
// firmwares: the list of firmware information returned by getFirmwareUpgradeInfo.
// Note that the firmware versions that do not meet the preceding rules must be filtered out.
device?.startFirmwareUpgrade(firmwares);
}
Currently, this API method applies only when the callback for the update progress is returned and when error.code
is ThingOTAErrorCodeSignalStrengthNotSatisfy
.
For Wi-Fi devices and combo devices, to ensure a successful update, the minimum signal strength level is specified. When an update is triggered, the system checks whether the device signal strength is within an acceptable range. If not, the callback for the update progress is returned, including error.code = ThingOTAErrorCodeSignalStrengthNotSatisfy
. Then, you can implement a UI interaction for users to make decisions. For example, a dialog box appears, saying “The device signal is weak, and the update might fail. Continue to update?”
API description
- (void)confirmWarningUpgradeTask:(BOOL)isContinue;
Parameters
Parameter | Description |
---|---|
isContinue | Indicates whether to continue the update task. |
This process applies to only the update that is initiated by -startFirmwareUpgrade:
.
Example
Objective-C:
- (void)continueFirmware {
// isContinue: asks users whether to continue the update.
[self.device confirmWarningUpgradeTask:isContinue];
}
Swift:
func continueFirmware() {
// isContinue: asks users whether to continue the update.
device?.confirmWarningUpgradeTask(isContinue)
}
Currently, only low-power devices are supported. After an update is initiated for this type of device, the update task might get into the status of waiting for the device to wake up (upgradeStatus
= 5
). This API method can be called to cancel the update task in this status.
API description
// Currently, an update task can be canceled only for low-power devices.
- (void)cancelFirmwareUpgrade:(ThingSuccessHandler)success
failure:(nullable ThingFailureError)failure;
// Deprecated. -cancelFirmwareUpgrade:failure: is recommended.
// type: the type of update. You can call getFirmwareUpgradeInfo to get the value.
- (void)cancelUpgradeFirmware:(NSInteger)type success:(nullable ThingSuccessHandler)success failure:(nullable ThingFailureError)failure;
Parameters
Parameter | Description |
---|---|
success | The success callback. |
failure | The failure callback. |
This API method applies only in the status of waiting for the device to wake up. upgradeStatus
is 5
to indicate this status.
Example
Objective-C:
- (void)cancelFirmware {
// self.device = [ThingSmartDevice deviceWithDeviceId:@"your_device_id"];
// type: the type of update. You can call getFirmwareUpgradeInfo to get the value.
// ThingSmartFirmwareUpgradeModel - type
// This API method applies only in the status of waiting for the device to wake up. upgradeStatus is 5 to indicate this status.
[self.device cancelFirmwareUpgrade:^{
NSLog(@"cancel success");
} failure:^(NSError *error) {
NSLog(@"cancel failure: %@", error);
}];
}
Swift:
func cancelFirmware() {
// This API method applies only in the status of waiting for the device to wake up. upgradeStatus is 5 to indicate this status.
device?.cancelFirmwareUpgrade(success: {
print("cancel success")
}, failure: { (error) in
if let e = error {
print("cancel failure: \(e)")
}
})
}
For the update initiated by -startFirmwareUpgrade:
, we recommend that you use -device:otaUpdateStatusChanged:
to register the callback. This callback includes the status changes, progress, and failure reason. Other deprecated callback methods can still be executed. To prevent repeated callback listeners, we recommend that you port respective logic to this callback.
Example
Objective-C:
- (void)device:(ThingSmartDevice *)device otaUpdateStatusChanged:(ThingSmartFirmwareUpgradeStatusModel *)statusModel {
// The callback for the status and progress of the firmware update.
// Recommended for use with -startFirmwareUpgrade:
}
- (void)device:(ThingSmartDevice *)device firmwareUpgradeStatusModel:(ThingSmartFirmwareUpgradeStatusModel *)upgradeStatusModel {
// The callback for the device update status.
// Recommended for use with -upgradeFirmware:success:failure:.
}
- (void)deviceFirmwareUpgradeSuccess:(ThingSmartDevice *)device type:(NSInteger)type {
// The firmware is updated. Deprecated. - device:firmwareUpgradeStatusModel: is recommended.
}
- (void)deviceFirmwareUpgradeFailure:(ThingSmartDevice *)device type:(NSInteger)type {
// Failed to update the firmware. Deprecated. - device:firmwareUpgradeStatusModel: is recommended.
}
- (void)device:(ThingSmartDevice *)device firmwareUpgradeProgress:(NSInteger)type progress:(double)progress {
// The progress of the firmware update.
// Recommended for use with -upgradeFirmware:success:failure:.
}
Swift:
func device(_ device: ThingSmartDevice, firmwareUpgradeStatusModel upgradeStatusModel: ThingSmartFirmwareUpgradeStatusModel) {
// The callback for the device update status.
}
func deviceFirmwareUpgradeSuccess(_ device: ThingSmartDevice!, type: Int) {
// The firmware is updated. This API method will be deprecated soon. device(_:, firmwareUpgradeStatusModel:) is recommended.
}
func deviceFirmwareUpgradeFailure(_ device: ThingSmartDevice!, type: Int) {
// Failed to update the firmware. This API method will be deprecated soon. device(_:, firmwareUpgradeStatusModel:) is recommended.
}
func device(_ device: ThingSmartDevice!, firmwareUpgradeProgress type: Int, progress: Double) {
// The progress of the firmware update.
}
Certain devices support an automatic update to the latest version. You can use ThingSmartDeviceModel - supportAuto
to check whether a device supports this feature.
API description
// Checks whether this feature is enabled.
- (void)getAutoUpgradeSwitchInfoWithSuccess:(nullable ThingSuccessID)success
failure:(nullable ThingFailureError)failure;
// Saves the switch states.
- (void)saveUpgradeInfoWithSwitchValue:(NSInteger)switchValue
success:(nullable ThingSuccessHandler)success
failure:(nullable ThingFailureError)failure;
Parameters
Parameter | Description |
---|---|
switchValue | The status of the feature. Valid values:
|
success | The success callback. |
failure | The failure callback. |
Example
Objective-C:
- (void)getAutoUpgradeSwitchInfo {
// self.device = [ThingSmartDevice deviceWithDeviceId:@"your_device_id"];
// Note that ThingSmartDeviceModel - supportAuto must be used to check whether the device supports this feature first.
[self.device getAutoUpgradeSwitchInfoWithSuccess:^(NSNumber *status) {
// 0: disabled. 1: enabled. This feature is disabled in this example.
NSLog(@"current switch status: %@", status);
} failure:^(NSError *error) {
NSLog(@"get current switch status fail. %@", error);
}];
}
- (void)saveAutoUpgradeSwitchInfo {
// self.device = [ThingSmartDevice deviceWithDeviceId:@"your_device_id"];
// Note that ThingSmartDeviceModel - supportAuto must be used to check whether the device supports this feature first.
NSInteger status = 0; // 0: disabled. 1: enabled. This feature is disabled in this example.
[self.device saveUpgradeInfoWithSwitchValue:status success:^{
NSLog(@"save auto switch status success.");
} failure:^(NSError *error) {
NSLog(@"save auto switch status fail. %@", error);
}];
}
Swift:
func getAutoUpgradeSwitchInfo() {
// Note that ThingSmartDeviceModel - supportAuto must be used to check whether the device supports this feature first.
device?.getAutoUpgradeSwitchInfo(success: { status in
// 0: disabled. 1: enabled.
if let value = status {
print("get current status: \(value)")
}
}, failure: { error in
if let e = error {
print("get status failure: \(e)")
}
})
}
func saveAutoUpgradeSwitchInfo() {
// Note that ThingSmartDeviceModel - supportAuto must be used to check whether the device supports this feature first.
let status = 0 // 0: disabled. 1: enabled. This feature is disabled in this example.
device?.saveUpgradeInfo(withSwitchValue: 0, success: {
print("save success")
}, failure: { error in
if let e = error {
print("success failure: \(e)")
}
})
}
This API method is only applicable to apps developed based on App SDK v3.0.0 or later.
API description
- (void)memberCheckFirmwareStatus:(void (^)(NSArray<ThingSmartMemberCheckFirmwareInfo *> *infos))success
failure:(ThingFailureError)failure;
Parameters
Parameter | Description |
---|---|
success | The success callback. |
failure | The failure callback. |
Data model of ThingSmartMemberCheckFirmwareInfo
Field | Type | Description |
---|---|---|
type | NSInteger | The type of firmware update channel. |
upgradeStatus | NSInteger |
|
version | NSString | The target firmware version. |
upgradeText | NSString | The information about firmware update. |
Example
Objective-C:
- (void)getAutoUpgradeSwitchInfo {
// self.device = [ThingSmartDevice deviceWithDeviceId:@"your_device_id"];
[self.device memberCheckFirmwareStatus:^(NSArray<ThingSmartMemberCheckFirmwareInfo *> * _Nonnull infos) {
NSLog(@"member check success");
} failure:^(NSError *error) {
NSLog(@"member check failure");
}];
}
Swift:
func getAutoUpgradeSwitchInfo() {
device?.memberCheckFirmwareStatus(success: { infos in
print("member check success: \(infos)")
}, failure: { error in
if let e = error {
print("member check failure: \(e)")
}
})
}
The error codes in ThingSmartFirmwareUpgradeStatusModel
only apply to the API methods for a PID-specific firmware update.
Error code | Description | Remarks |
---|---|---|
5000 | All device firmware versions are up to date and do not need to be updated. | None. |
5001 | No firmware update found. | None. |
5002 | For Bluetooth devices, only one device can be updated in the same task. | In most cases, this error code applies to Bluetooth LE devices, Tuya mesh sub-devices, and Bluetooth mesh sub-devices. |
5003 | Failed to download the firmware package by using the app. | None. |
5004 | Failed to check whether the signal strength detection is required. | None. |
5005 | The signal strength level of the device does not meet firmware update requirements. | We recommend that you implement a UI interaction to ask users whether to continue the update. The update might fail if it is continued. You can call - confirmWarningUpgradeTask: to continue or cancel the update. |
5006 | Failed to connect to the device. | In most cases, this error code applies to Bluetooth LE devices, Tuya mesh sub-devices, and Bluetooth mesh sub-devices. |
5007 | A timeout error has occurred while unbinding the Bluetooth LE device from the gateway. | None. |
5009 | The MD5 check failed while downloading firmware by using the app. | None. |
5010 | Failed to send the firmware by using the app. | In most cases, this error code applies to Bluetooth LE devices, Tuya mesh sub-devices, and Bluetooth mesh sub-devices. |
5012 | The device is offline. | None. |
5013 | The pre-validation prior to the update is not passed. | None. |
5014 | The Bluetooth feature is not enabled on the mobile phone. | None. |
5015 | Failed to get the list of available firmware updates. | None. |
5016 | The device update timed out. | None. |
5099 | A global error code. | None. |
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback