固件升级

更新时间:2024-01-31 08:30:14下载pdf

固件升级流程

获取设备升级信息 -> 下发联网模块升级指令 -> 联网模块升级成功 -> 下发设备控制模块升级指令 -> 设备控制模块升级成功

使用获取设备升级信息接口获取到的 TuyaSmartFirmwareUpgradeModel 固件升级模型中,type 属性能获取到固件的类型,typeDesc 属性能获取到固件类型的描述

获取设备升级信息

接口说明

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

参数说明

参数 说明
success 成功回调,设备的固件升级信息列表
failure 失败回调

TuyaSmartFirmwareUpgradeModel 数据模型

字段 类型 说明
desc NSString 升级文案
typeDesc NSString 设备类型文案
upgradeStatus NSInteger 0:无新版本 1:有新版本 2:在升级中 5:等待设备唤醒
version NSString 新版本使用的固件版本
upgradeType NSInteger 0:app 提醒升级 2:app 强制升级 3:检测升级
url NSString 蓝牙设备的升级固件包下载 URL
fileSize NSString 固件包的 size, byte
md5 NSString 固件的 md5
upgradingDesc NSString 固件升级中的提示文案

示例代码

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)")
        }
    })
}

开始升级

接口说明

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

参数说明

参数 说明
type type: 需要升级的类型,从设备升级信息接口 getFirmwareUpgradeInfo 获取
success 成功回调
failure 失败回调

示例代码

Objc:

- (void)upgradeFirmware {
	// self.device = [TuyaSmartDevice deviceWithDeviceId:@"your_device_id"];
	// type: 从获取设备升级信息接口 getFirmwareUpgradeInfo 返回的固件类型
	// TuyaSmartFirmwareUpgradeModel - type

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

Swift:

func upgradeFirmware() {
    // type: 从获取设备升级信息接口 getFirmwareUpgradeInfo 返回的固件类型
    // TuyaSmartFirmwareUpgradeModel - type
    device?.upgradeFirmware(type, success: {
        print("upgradeFirmware success")
    }, failure: { (error) in
        if let e = error {
            print("upgradeFirmware failure: \(e)")
        }
    })
}

回调监听

示例代码

Objc:

- (void)device:(TuyaSmartDevice *)device firmwareUpgradeStatusModel:(TuyaSmartFirmwareUpgradeStatusModel *)upgradeStatusModel {
    //固件升级状态回调
}

- (void)deviceFirmwareUpgradeSuccess:(TuyaSmartDevice *)device type:(NSInteger)type {
	//固件升级成功。方法废弃,推荐使用 `- device:firmwareUpgradeStatusModel:`
}

- (void)deviceFirmwareUpgradeFailure:(TuyaSmartDevice *)device type:(NSInteger)type {
	//固件升级失败。方法废弃,推荐使用 `- device:firmwareUpgradeStatusModel:`
}

- (void)device:(TuyaSmartDevice *)device firmwareUpgradeProgress:(NSInteger)type progress:(double)progress {
	//固件升级的进度
}

Swift:

func device(_ device: TuyaSmartDevice, firmwareUpgradeStatusModel upgradeStatusModel: TuyaSmartFirmwareUpgradeStatusModel) {
    //设备升级状态变更
}

func deviceFirmwareUpgradeSuccess(_ device: TuyaSmartDevice!, type: Int) {
    //固件升级成功,即将弃用,推荐使用 `device(_:, firmwareUpgradeStatusModel:)`
}

func deviceFirmwareUpgradeFailure(_ device: TuyaSmartDevice!, type: Int) {
    //固件升级失败,即将弃用,推荐使用 `device(_:, firmwareUpgradeStatusModel:)`
}

func device(_ device: TuyaSmartDevice!, firmwareUpgradeProgress type: Int, progress: Double) {
    //固件升级的进度
}