Last Updated on : 2024-07-26 06:40:02download
To implement the bulk OTA updates service, the following capabilities are needed:
Only users with an admin role or higher can initiate an OTA update.
Check user role
Integrate with the Home Management BizBundle SDK and check the user role with the following code.
// Check the current user's role.
var mMemberUseCase : IMemberUseCase = FamilyManagerCoreKit.getMemberUseCase()
mMemberUseCase.getMemberInfo(11,111,object :IFamilyMemberDataCallback<MemberBean>{
override fun onSuccess(result: MemberBean?) {
/**
* 0: Home owner, MemberRole.ROLE_OWNER
* 1: Home admin, MemberRole.ROLE_ADMIN
* 2: Common member, MemberRole.ROLE_MEMBER
*/
result?.role
}
override fun onError(errorCode: String?, errorMessage: String?) {
}
})
Request the list of devices in the current home that are available for OTA updates. The UpgradeDevListBean
data model contains the device name, ID, and firmware information for UI creation.
IDeviceOTAManager otaManager = DeviceBusinessDataManager.getInstance().getDeviceOTAManager();
otaManager.queryHasUpgradeInfoDeviceList(mGid, new Business.ResultListener<UpgradeDevListBean>() {
@Override
public void onFailure(BusinessResponse bizResponse, UpgradeDevListBean bizResult, String apiName) {
// Failed
}
@Override
public void onSuccess(BusinessResponse bizResponse, UpgradeDevListBean bizResult, String apiName) {
if (bizResult.isStatus()) {
} else {
// Failed
}
}
});
Start updating the target devices individually. The SDK does not support updates in one go, so you must call the OTA update method individually for each device. For Bluetooth mesh or beacon devices, throughout the update process, the phone must stay connected to the target device and the app cannot be closed. Otherwise, the OTA update may fail.
Theoretically, you can call the OTA update method with the firmware information returned in step 1 to start an update. However, the OTA information might change during this period. To ensure a smooth update, request the latest firmware information before proceeding with the OTA update.
val mIThingOTAService : IThingOTAService = OtaServiceManager.instance.getOtaService(devId)
mIThingOTAService?.getFirmwareUpgradeInfo(object : IGetOtaInfoCallback {
override fun onSuccess(upgradeInfoBeans: MutableList<UpgradeInfoBean>?) {
mIThingOTAService?.startFirmwareUpgrade(upgradeInfoBeans)
}
override fun onFailure(code: String?, error: String?) {
callback?.onError(code, error)
}
})
Listen for the update status of each device individually.
IThingOTAService mIThingOTAService = OtaServiceManager.instance.getOtaService(devId)
mIThingOTAService.registerDevOTAListener(new IDevOTAListener() {
@Override
public void firmwareUpgradeStatus(ThingDevUpgradeStatusBean upgradeStatusBean) {
// Get the OTA status of a single device.
}
});
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback