Skip to content

Device Upgrade SDK: QuecOTAUpgradeKit

Feature Description

This SDK enable device upgrade via cloud or Bluetooth.

objc
#import <QuecOTAUpgradeKit/QuecOTAUpgradeKit.h>
/// Initialize
[QuecOTAManager sharedInstance]

Attention:

To ensure the state synchronization of device upgrades over HTTP, poll and call the following API to check the device upgrade state once.

objc
 /// deviceModelList: device list page
for (QuecDeviceModel *device in deviceModelList) {
    [QuecOTAManager.sharedInstance checkDeviceHttpOtaWithDeviceModel:device];
}

Device Upgrade

The procedures for device upgrade are as follows:

  1. Query the device upgrade plan.
  2. Set an event listener.
  3. Start device upgrade.
  4. Obtain the upgrade process and result through event callbacks.
  5. Display the upgrade result and remove the event listener.

The SDK will determine whether to use cloud OTA or Bluetooth OTA according to device online status:

  1. Cloud OTA when the device is online on the platform.
  2. Bluetooth OTA when the device is offline on the platform.

Query Upgrade Plan of Single Device

API

Query an upgrade plan of a single device. If the device has an upgrade plan, the upgrade plan will be returned; otherwise, null will be returned.

objc
- (void)checkVersionWithProductKey:(NSString *)productKey
                          deviceKey:(NSString *)deviceKey
                         planBlock:(void (^)(QuecOtaPlanInfoModel * planInfo))planBlock;

Parameter

ParameterRequiredDescription
productKeyYProductKey.
deviceKeyYDeviceKey.
planBlockNInterface callback.

Example

objc
[QuecOTAManager.sharedInstance checkVersionWithProductKey:@"pk"
                                                    deviceKey:@"dk"
                                                    planBlock:^(QuecOtaPlanInfoModel * _Nonnull planInfo) {
    /// Next Action
}];

QuecOtaPlanInfoModel Definition

FieldTypeDescription
productKeyNSStringProductKey.
deviceKeyNSStringDeviceKey.
productIconNSStringProduct icon.
deviceNameNSStringDevice name.
planIdlong longUpgrade plan ID.
planNameNSStringUpgrade plan name.
planStartTimelong longThe start time of the upgrade plan. The timestamp is accurate to milliseconds.
planEndTimelong longThe end time of the upgrade plan. The timestamp is accurate to milliseconds.
userConfirmStatusNSIntegerUser's upgrade confirmation state.
0-Unconfirmed
1-Upgrade immediately
userConfirmStatusDescintDescription of user's upgrade confirmation state.
deviceStatusNSIntegerUpgrade state.
0-Not upgraded
1-Upgrading
2-Successful upgrade
3-Failed upgrade
deviceStatusDescintDescription of user's upgrade confirmation state.
upgradeFinishTipsintUpgrade result confirmation state.
0-Confirmed
1-Not confirmed; ignore this step if no confirmation is required.
upgradeProgressfloatUpgrade progress. Range: 0 and 1.
0-Not upgraded
1-Successful upgrade
upgradeVersionInfoNSStringText of user's upgrade confirmation state.
versionInfoNSStringText of the version package required for the upgrade of components to be upgraded (being upgraded). No update description exists in the early versions, so use this text as the upgrade text.
comVerListNSArray<QuecOtaPlanComVerInfo *> *Upgrade component list.

QuecOtaPlanComVerInfo Definition

FieldTypeDescription
sortintComponent sort.
comNoNSStringComponent number.
comTypeintComponent type.
0-Module
1-MCU
dataTypeintUpgrade method.
0-Full-FOTA
1-DFOTA
cverNSStringCurrent version number.
tverNSStringTarget version number.
versionInfoNSStringText of the version package required for component upgrade.
versionMatchBOOLWhether the component is suitable for upgrade. Always true, only return the list of upgradable components.
True-Yes
False-No
batteryNSStringThe lowest power required for an upgrade.
signalintThe weakest signal required for an upgrade.
spacelong longDisk space required for the upgrade, unit: B (the maximum file size of the firmware needed for the upgrade).
downloadStatusintComponent firmware download state.
0-Not downloaded
1-Downloading
2-Successful download
3-Failed download
downloadProgressNSStringDownload progress.
upgradeStatusNSStringComponent upgrade state.
0-Not upgraded
1-Upgrading
2-Successful upgrade
3-Failed upgrade
fileListNSArray<QuecOtaPlanFileInfo *> *Firmware information required for component upgrade.

QuecOtaPlanFileInfo Definition

FieldTypeDescription
updIndexintUpgrade file index.
fileNameNSStringUpgrade file name.
filePathNSStringFile download address.
fileSizelong longUpgrade file size.
fileSha256NSStringSHA-256 value of the update file.
fileMd5NSStringMD5 checksum.
fileCrcNSStringCRC checksum.

Batch Query Device Upgrade Plan

API

objc
- (void)checkListVersionWithDeviceList:(NSArray *)deviceList
                         planListBlock:(void (^)(NSArray<QuecOtaPlanInfoModel *> * planInfos))planListBlock;

Parameter

ParameterRequiredDescription
deviceListYDevice list.
planListBlockYCallback function of the request.

Example

objc
[QuecOTAManager.sharedInstance checkListVersionWithDeviceList:@[@{@"pk" : @"your pk", @"dk" : @"your dk"}] planListBlock:^(NSArray<QuecOtaPlanInfoModel *> * _Nonnull planInfos) {
    /// Next Action
}];

Query Upgrade Plan for All Device Under Account

API

objc
- (void)checkAllVersionWithPage:(NSInteger)page
                        pageSize:(NSInteger)pageSize
                  planListBlock:(void (^)(NSArray<QuecOtaPlanInfoModel *> * planInfos))planListBlock;

Parameter

ParameterRequiredDescription
pageYPage number.
pageSizeYPage size.
planListBlockYCallback function of the request.

Example

objc
[QuecOTAManager.sharedInstance checkAllVersionWithPage:1
                                                  pageSize:10
                                             planListBlock:^(NSArray<QuecOtaPlanInfoModel *> * _Nonnull planInfos) {
    /// Next Action
}];

Query Device Version Information

API

objc
- (void)queryCurrentVersionWithProductKey:(NSString *)productKey
                                deviceKey:(NSString *)deviceKey
                                   result:(void (^)(NSArray<QuecBleVersionInfo *> * versionInfos))result;

Parameter

ParameterRequiredDescription
productKeyYProductKey.
deviceKeyYDeviceKey.
resultYCallback function of the request.

Example

objc
[QuecOTAManager.sharedInstance queryCurrentVersionWithProductKey:@"your pk"
                                                           deviceKey:@"your dk"
                                                              result:^(NSArray<QuecBleVersionInfo *> * _Nonnull versionInfos) {
    /// Next Action
}];

QuecBleVersionInfo Definition

FieldTypeDescription
componentNameNSStringComponent name.
versionNSStringComponent version.
componentTypeintComponent type.
0-Module
1-MCU

Start Device Upgrade

API

A specified device starts OTA upgrade. Upgrade method will be automatically determined when the method is called.

objc
- (void)startOtaWithPlanInfoModel:(QuecOtaPlanInfoModel *)planInfoModel;

Parameter

ParameterRequiredDescription
planInfoModelYUpgrade information.

Example

objc
//Information obtained from upgrade plan query.
QuecOtaPlanInfoModel *planInfo = QuecOtaPlanInfoModel.new;
[QuecOTAManager.sharedInstance startOtaWithPlanInfoModel:planInfo];

Stop Device Upgrade

API

Note

Device upgrade can only be stopped when upgrading through Bluetooth. If upgrading through cloud, the upgrading will not be stopped and will continue until finished.

Specify a device to stop an OTA upgrade.

objc
- (void)stopOtaWithPlanInfoModel:(QuecOtaPlanInfoModel *)planInfoModel;

Parameter

ParameterRequiredDescription
planInfoModelYUpgrade information.

Example

objc
//Information obtained from upgrade plan query.
QuecOtaPlanInfoModel *planInfo = QuecOtaPlanInfoModel.new;
[QuecOTAManager.sharedInstance stopOtaWithPlanInfoModel:planInfo];

Add Update State Listener

API

Add an upgrade state listener. Through the callback of this listener, upgrade status and progress can be obtained.

objc

typedef void (^QuecOtaStateBlock)(QuecOTAStateModel *stateModel);

/// add listener
- (void)addStateListener:(id)listener state:(QuecOtaStateBlock)state;

Parameter

ParameterRequiredDescription
listenerYListener.
stateYOTA upgrade information.

Example

objc
/// add listener
[QuecOTAManager.sharedInstance addStateListener:self state:^(QuecOTAStateModel * _Nonnull stateModel) {
    /// Next Action
}];

QuecOTAStateModel Definition

FieldTypeDescription
planIdNSStringUpgrade Plan ID.
stateQuecOTAStateUpgrade state: QuecOTAState.
pkStringProductKey.
dkStringDeviceKey.
progressdoubleUpgrade progress (0.0 – 100.0).
channelModeQuecOTAChannelModeUpgrade channel mode: QuecOTAChannelMode.
userConfirmStatusintUser's upgrade confirmation state.
0-Unconfirmed
1-Upgrade immediately

QuecOTAState Enumeration Definition

objc
typedef NS_ENUM(int, QuecOTAState) {
    QuecOTAUpgradeEmpty = 0, // No upgrade plan.
    QuecOTAUpgrading,        // Upgrading.
    QuecOTAUpgradeSuccess,   // Upgraded successfully.
    QuecOTAUpgradeFailure,   // Upgrade fails.
    QuecOTAUpgradeExpired,   // Upgrade expires.
};

QuecOTAChannelMode Enumeration Definition

objc
typedef NS_ENUM(int, QuecOTAChannelMode) {
    QuecOTAChannelUnknown = 0, // No available channel. 
    QuecOTAChannelCloud,        // Cloud upgrade.
    QuecOTAChannelBle,        // Bluetooth upgrade.
};

Remove Upgrade State Listener

API

Remove an upgrade state listener. Remove the listener after completing the OTA upgrade to avoid memory leak.

objc
/// remove listener
- (void)removeStateListener:(id)listener;

Parameter

ParameterRequiredDescription
listenerYListener.

Example

objc
/// remove listener
[QuecOTAManager.sharedInstance removeStateListener:self];

Remove All Caches in Class

API

Remove all caches in a class and call them when OTA resources are no longer in use.

objc
- (void)releaseAllOta;

Example

objc
[QuecOTAManager.sharedInstance releaseAllOta];

Query Specified Device OTA Upgrade Progress and State

API

Query a specified device OTA upgrade progress and state. An empty value indicates that the device has no state.

objc
- (QuecOTAStateModel *)getOtaStateWithProductKey:(NSString *)productKey deviceKey:(NSString *)deviceKey;

Parameter

ParameterRequiredDescription
productKeyYProductKey.
deviceKeyYDeviceKey.

The return value is upgrade state and progress.

Example

objc
QuecOTAStateModel *stateModel = [QuecOTAManager.sharedInstance getOtaStateWithProductKey:@"your pk" deviceKey:@"your dk"];

Query Device Upgrade Method

API

Call this function before starting the device upgrade to obtain the upgrade method that will be selected when the current upgrade begins.

objc
- (QuecOTAChannelMode)getDeviceUpgradeChannelWithProductKey:(NSString *)productKey deviceKey:(NSString *)deviceKey;

Parameter

ParameterRequiredDescription
productKeyYProductKey.
deviceKeyYDeviceKey.

The return value is an enumeration of the upgrade method.

Example

objc
QuecOTAChannelMode mode = [QuecOTAManager.sharedInstance getDeviceUpgradeChannelWithProductKey:@"your pk" deviceKey:@"your dk"];