Bulk OTA Updates

Last Updated on : 2024-07-26 06:40:02download

To implement the bulk OTA updates service, the following capabilities are needed:

  • Get the list of devices in the current home that are available for OTA updates
  • Start bulk OTA updates
  • Listen for the OTA update status

Prerequisites

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?) {

      }
    })

Step 1: Get the list of devices in the current home that are available for OTA updates

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

Step 2: Start bulk OTA updates

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

Step 3: Listen for the OTA update status

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.
    }
});