Firmware Update

Last Updated on : 2022-03-03 06:47:48

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 earlier firmware versions in line with chip iterations of the manufacturers. In the case of device feature updates, firmware updates are also required.

Update process

  1. Query device update information.
  2. Send a command to update the module.
  3. The module is updated.
  4. Send a command to update the device control module.
  5. The device control module is updated.

Get firmware update information

Returns the device update information. The firmware update model TuyaSmartFirmwareUpgradeModel provides the type property to indicate the firmware type and the typeDesc property to describe the firmware type.

API description

- (void)getFirmwareUpgradeInfo:(nullable void (^)(NSArray <TuyaSmartFirmwareUpgradeModel *> *upgradeModelList))success failure:(nullable TYFailureError)failure;

Parameters

Parameter Description
success The success callback. A list of firmware update information is returned.
failure The failure callback.

Data model of TuyaSmartFirmwareUpgradeModel

Field Type Description
desc NSString The description of the update.
typeDesc NSString The description of the device type.
upgradeStatus NSInteger
  • 0: no updates
  • 1: updates available
  • 2: updating
  • 5: wait for the device to wake up
version NSString The target firmware version.
upgradeType NSInteger
  • 0: app notification of updates
  • 2: forced updates
  • 3: check for updates
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.
md5 NSString The MD5 (Message-Digest algorithm 5) hash value of the firmware.
upgradingDesc NSString The description of the firmware update.

Example

ObjC:

- (void)getFirmwareUpgradeInfo {
	// self.device = [TuyaSmartDevice deviceWithDeviceId:@"your_device_id"];

	[self.device getFirmwareUpgradeInfo:^(NSArray<TuyaSmartFirmwareUpgradeModel *> *upgradeModelList) {
		NSLog(@"getFirmwareUpgradeInfo success");
	} failure:^(NSError *error) {
		NSLog(@"getFirmwareUpgradeInfo failure: %@", error);
	}];
}

Swift:

func getFirmwareUpgradeInfo() {
    device?.getFirmwareUpgradeInfo({ (upgradeModelList) in
        print("getFirmwareUpgradeInfo success")
    }, failure: { (error) in
        if let e = error {
            print("getFirmwareUpgradeInfo failure: \(e)")
        }
    })
}

Start an OTA update

API description

- (void)upgradeFirmware:(NSInteger)type success:(nullable TYSuccessHandler)success failure:(nullable TYFailureError)failure;

Parameters

Parameter Description
type The type of update. You can call getFirmwareUpgradeInfo to get the value.
success The success callback.
failure The failure callback.

Example

ObjC:

- (void)upgradeFirmware {
	// self.device = [TuyaSmartDevice deviceWithDeviceId:@"your_device_id"];
	// `type`: the type of update. You can call `getFirmwareUpgradeInfo` to get the value.
	// TuyaSmartFirmwareUpgradeModel - type

	[self.device upgradeFirmware:type success:^{
		NSLog(@"upgradeFirmware success");
	} failure:^(NSError *error) {
		NSLog(@"upgradeFirmware failure: %@", error);
	}];
}

Swift:

func upgradeFirmware() {
    // `type`: the type of update. You can call `getFirmwareUpgradeInfo` to get the value.
    // TuyaSmartFirmwareUpgradeModel - type
    device?.upgradeFirmware(type, success: {
        print("upgradeFirmware success")
    }, failure: { (error) in
        if let e = error {
            print("upgradeFirmware failure: \(e)")
        }
    })
}

Listener callback

Example

ObjC:

- (void)deviceFirmwareUpgradeSuccess:(TuyaSmartDevice *)device type:(NSInteger)type {
	// The firmware is updated.
}

- (void)deviceFirmwareUpgradeFailure:(TuyaSmartDevice *)device type:(NSInteger)type {
	// Failed to update the firmware.
}

- (void)device:(TuyaSmartDevice *)device firmwareUpgradeProgress:(NSInteger)type progress:(double)progress {
	// The progress of the firmware update.
}

Swift:

func deviceFirmwareUpgradeSuccess(_ device: TuyaSmartDevice!, type: Int) {
    // The firmware is updated.
}

func deviceFirmwareUpgradeFailure(_ device: TuyaSmartDevice!, type: Int) {
    // Failed to update the firmware.
}

func device(_ device: TuyaSmartDevice!, firmwareUpgradeProgress type: Int, progress: Double) {
    // The progress of the firmware update.
}