Skip to content

Device Upgrade SDK: QuecOtaUpgradeSdk

Feature Description

This SDK enable device upgrade via cloud or Bluetooth.

kotlin
QuecOtaManager

Device Upgrade

The procedures for device upgrade are as follows:

  1. Query the device upgrade plan.
  2. Set a 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 cloud online.
  2. Bluetooth OTA when the device is cloud offline.

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.

kotlin
fun checkVersion(pk: String, dk: String, callback: QuecCallback<QuecOtaInfo?>)

Parameter

ParameterRequiredDescription
pkYProductKey.
dkYDeviceKey.
callbackYCallback function of the request.

Example

kotlin
QuecOtaManager.checkVersion("pk", "dk") {
    if (it.isSuccess) {
        //Query an upgrade plan of a single device successfully.  A non-empty data value indicates that there is an upgrade plan.
        val data = it.data
    } else {
        val code = it.code //Failed. Error code.
        val msg = it.msg   //Failed. Error message.
    }
}

QuecOtaInfo Definition

FieldTypeDescription
productKeyStringProductKey.
deviceKeyStringDeviceKey.
upgradeVersionInfoStringUpgrade version information.
planIdStringUpgrade plan ID.
planNameStringUpgrade plan name.
comVerListList<ComVer>Component version information.
productIconStringProduct icon.
deviceNameStringDevice name.

QuecOtaInfo.ComVer Definition

FieldTypeDescription
sortIntComponent sort.
comNoStringComponent number.
comTypeintComponent type.
0-Module
1-MCU
cverStringCurrent version number.
tverStringTarget version number.
versionInfoStringComponent version information.
fileListList<File>Upgrade file list.

QuecOtaInfo.File Definition

FieldTypeDescription
updIndexIntUpgrade file serial number.
fileNameStringUpgrade file name.
filePathStringUpgrade file path.
fileSizeLongUpgrade file size.
fileSha256StringSHA-256 value of the update file.

Batch Query Device Upgrade Plan

API

kotlin
 fun checkListVersion(list: List<Info>, callback: QuecCallback<List<QuecOtaInfo>>)

Parameter

ParameterRequiredDescription
listYDevice list.
callbackYCallback function of the request.

Example

kotlin
QuecOtaManager.checkListVersion(
    listOf(
        IQuecOtaManager.Info("pk1", "dk1"),
        IQuecOtaManager.Info("pk2", "dk2"),
    )
) {
    if (it.isSuccess) {
        //Batch a query device upgrade successfully. When the size in the data is greater than 0, it indicates that there is an upgrade plan.
        val data = it.data
    } else {
        val code = it.code //Failed. Error code.
        val msg = it.msg   //Failed. Error message.
    }
}

IQuecOtaManager.Info Definition

FieldTypeDescription
pkStringProductKey.
dkStringDeviceKey.

Query Upgrade Plan for All Device Under Account

API

kotlin
fun checkAllVersion(
    page: Int,
    pageSize: Int,
    callback: QuecCallback<QuecPageResponse<QuecOtaInfo>>
)

Parameter

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

Example

kotlin
QuecOtaManager.checkAllVersion(1, 10) {
    if (it.isSuccess) {
        //Query a upgrade plan for all devices under a account successfully.
        val data = it.data
    } else {
        val code = it.code //Failed. Error code.
        val msg = it.msg   //Failed. Error message.
    }
}

Query Device Version Information

API

kotlin
fun queryCurrentVersion(
    pk: String,
    dk: String,
    callback: QuecCallback<List<QuecOtaInfo.ComVer>>
)

Parameter

ParameterRequiredDescription
pkYProductKey.
dkYDeviceKey.
callbackYCallback function of the request.

Example

kotlin
QuecOtaManager.queryCurrentVersion("pk", "dk") {
    if (it.isSuccess) {
        //Query device version information successfully. A non-empty data value indicates that there is version information.
        val data = it.data
    } else {
        val code = it.code //Failed. Error code.
        val msg = it.msg   //Failed. Error message.
    }
}

Start Device Upgrade

API

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

kotlin
fun startOta(info: QuecOtaInfo)

Parameter

ParameterRequiredDescription
infoYUpgrade information.

Example

kotlin
//Information obtained from upgrade plan query.
val otaInfo = getOtaInfo()
QuecOtaManager.startOta(otaInfo)

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.

kotlin
fun stopOta(info: QuecOtaInfo)

Parameter

ParameterRequiredDescription
infoYUpgrade information.

Example

kotlin
//Information obtained from upgrade plan query.
val otaInfo = getOtaInfo()
QuecOtaManager.stopOta(otaInfo)

Add Update State Listener

API

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

kotlin
interface QuecOnOtaStateChangeListener {
    fun onCall(state: QuecOTAStateModel)
}

fun addStateListener(listener: QuecOnOtaStateChangeListener)

Parameter

ParameterRequiredDescription
listenerYListener.

Example

kotlin
val listener = object : QuecOnOtaStateChangeListener {
    override fun onCall(state: QuecOTAStateModel) {
        //Device state changes.
    }
}
QuecOtaManager.addStateListener(listener)

QuecOTAStateModel Definition

FieldTypeDescription
planIdlongUpgrade Plan ID.
stateenumUpgrade state: QuecOTAState.
pkStringProductKey.
dkStringDeviceKey.
progressdoubleUpgrade progress(0.0 – 100.0).
failCodeenumFailure reason: IQuecOtaManager.ErrorCode. This field contains a value only when the upgrade fails.
channelModeenumUpgrade channel mode: QuecOTAChannelMode.

QuecOTAStateModel Enumeration Definition

FieldDescription
QuecOTAUpgradeEmptyNo upgrade plan.
QuecOTAUpgradeWaitWaiting for upgrade.
QuecOTAUpgradingUpgrading.
QuecOTAUpgradeSuccessUpgraded successfully.
QuecOTAUpgradeFailureUpgrade failed.
QuecOTAUpgradeExpiredUpgrade plan expired.

IQuecOtaManager.ErrorCode Enumeration Definition

FieldDescription
COMMONCommon error.
FILE_DOWNLOAD_FAILOTA file download failed.
NOT_CONNECTDevice connection failed.
NO_FILE_PATHUpgrade plan is invalid.
FILE_CHECK_FAILOTA file verification failed.
DEVICE_REFUSEDevice refuses the upgrade.
DEVICE_CANCELLEDDevice cancels the upgrade.
DEVICE_FAILDevice responds the upgrade failure.
TIMEOUTUpgrade timeout.

QuecOTAChannelMode Enumeration Definition

FieldDescription
QuecOTAChannelUnknownUnknown.
QuecOTAChannelCloudCloud upgrade.
QuecOTAChannelBleBluetooth upgrade.

Remove Upgrade State Listener

API

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

kotlin
fun removeStateListener(listener: QuecOnOtaStateChangeListener)

Parameter

ParameterRequiredDescription
listenerYListener.

Example

kotlin
val listener = object : QuecOnOtaStateChangeListener {
    override fun onCall(state: QuecOTAStateModel) {
        //Device state changes.
    }
}
QuecOtaManager.removeStateListener(listener)

Remove All Caches in Class

API

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

kotlin
fun release()

Example

kotlin
QuecOtaManager.release()

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.

kotlin
fun getOtaState(pk: String, dk: String): QuecOTAStateModel?

Parameter

ParameterRequiredDescription
pkYProductKey.
dkYDeviceKey.

The return value is upgrade state and progress.

Example

kotlin
val state = QuecOtaManager.getOtaState("pk", "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.

kotlin
fun getDeviceUpgradeChannel(pk: String, dk: String): QuecOTAStateModel.QuecOTAChannelMode

Parameter

ParameterRequiredDescription
pkYProductKey.
dkYDeviceKey.

The return value is an enumeration of the upgrade method.

Example

kotlin
val mode = QuecOtaManager.getDeviceUpgradeChannel("pk", "dk")