Enable voice capabilities for Bluetooth network provisioning on Android apps

更新时间:
复制 MD 格式

Bluetooth-assisted network provisioning allows a mobile app to send Wi-Fi hotspot information to a device over Bluetooth. Network provisioning error messages can also be sent back to the user over the Bluetooth channel to help troubleshoot issues. This document describes how to develop the feature to provision your device's network over Bluetooth and enable its voice capabilities on Android.

Prerequisites

You have completed product development in the console and device-side development for Bluetooth-assisted network provisioning. For more information, see Device-side development.

  1. Create your app. For more information, see Create an app.
  2. Obtain the app-side software development kit (SDK). For more information, see Download and integrate the SDK.
  3. Initialize the SDK. For more information, see SDK initialization.
  4. Implement Combo device discovery. You can discover Combo devices by calling the LocalDeviceMgr method startDiscovery. If you have already implemented device discovery, add the DiscoveryType.BLE_ENROLLEE_DEVICE type to the EnumSet<DiscoveryType> input parameter.
    1. Initiate local discovery.
      EnumSet<DiscoveryType> discoveryTypes=EnumSet.of(DiscoveryType.CLOUD_ENROLLEE_DEVICE, DiscoveryType.SOFT_AP_DEVICE, DiscoveryType.LOCAL_
                                                       ONLINE_DEVICE, DiscoveryType.BLE_ENROLLEE_DEVICE);
      LocalDeviceMgr.getInstance().startDiscovery(AApplication.getInstance
                                                  (), discoveryTypes, null, new IDeviceDiscoveryListener() {
          @Override
          public void onDeviceFound(DiscoveryType discoveryType, L
                                    ist<DeviceInfo> list) {
      
          }
      });
    2. Call the Get product ProductKey API. Use the ProductId to obtain the device's ProductKey.
    3. Call the Filter local device list information API to filter out invalid devices, such as devices that are already attached.
  5. Implement Combo device attachment. The following example shows the Combo fast provisioning flow for the Cloud Intelligence App. You can implement this flow based on your business logic.
    1. Call the DevService.breezeSubDevLogin Bluetooth online API. Pass in parameters such as ProductKey and MAC. The following code provides an example.
      DevService.breezeSubDevLogin(pk, mac, new DevService.ServiceListener() {
          @Override
          public void onComplete(boolean b, Object o) {
          }
      });
    2. After the API is called, the SDK returns the Bluetooth online result in the onComplete interface. If the device is brought online, proceed with the attachment operation. If it fails, the flow ends.
    3. Call the Attach a device based on a time window API to attach the device to the cloud.
    4. Call the DevService.notifySubDeviceBinded interface to notify the device of the attachment result. The following code provides an example.
      private void tmpNotify(String iotId){
              ALog.d(TAG, "tmpNotify->" + iotId);
              SubDevInfo subDevInfo=new SubDevInfo();
              subDevInfo.iotId=iotId;
              if (netType==ILopNetTypeCodes.NET_TYPE_BT){
                  ALog.d(TAG, "mac->" + mac);
                  subDevInfo.deviceName=mac;
              }else {
                  ALog.d(TAG, "dn->" + dn);
                  subDevInfo.deviceName=dn;
              }
              subDevInfo.productKey=pk;
      
      // Call the DevService.notifySubDeviceBinded interface to notify the device that it is successfully attached.
              DevService.notifySubDeviceBinded(subDevInfo,new DevService.ServiceListener(){
      
                  @Override
                  public void onComplete(boolean b, @Nullable Object o) {
                      ThreadTools.runOnUiThread(new Runnable() {
                          @Override
                          public void run() {
                              gotoStepFinish();
                          }
                      });
                  }
              });
      
          }
  6. Implement Combo device network provisioning.
    Note If the Combo device type is DiscoveryType.COMBO_SUBTYPE_0X04_DEVICE, the device is already provisioned. You can ignore the following operations in this step.
    1. When provisioning starts, set wifistate to DeviceWifiStatus_Setting to indicate that Wi-Fi is being configured. The following code provides an example.
      DevService.setWifiStatus(iotID, TmpEnum.DeviceWifiStatus.DeviceWifiStatus_Setting, new DevService.ServiceListenerEx() {
         @Override
      public void onComplete(boolean b, @Nullable String s) {
      
      }});
    2. Call AddDeviceBiz.getInstance().setDevice to set the provisioning information. The following code provides an example.
      DeviceInfo deviceInfo = new DeviceInfo();
      deviceInfo.devType = ILopNetTypeCodes.DEV_TYPYE_BLE_SUBTYPE_3;
      deviceInfo.mac = mac;
      deviceInfo.linkType = LinkType.ALI_BLE.getName();
      RegionInfo regionInfo = new RegionInfo();
      regionInfo.shortRegionId = 0;
      deviceInfo.regionInfo = regionInfo;
      
      // Activate voice capabilities. Annotate whether the device supports voice capabilities.
      deviceInfo.isInSide = true;
      
      ProvisionConfigParams params = new ProvisionConfigParams();
      params.ignoreSoftAPRecoverWiFi = true;
      params.enableGlobalCloudToken = true;
      ProvisionConfigCenter.getInstance().setProvisionConfiguration(params);
      AddDeviceBiz.getInstance().setDevice(deviceInfo);
      Note Activate voice capabilities. This setting indicates whether the device supports voice capabilities.

      deviceInfo.isInSide = true;

    3. Call the AddDeviceBiz.getInstance().startAddDevice method to start provisioning. The following code provides an example.
      
      
      
      AddDeviceBiz.getInstance().startAddDevice(AApplication.getInstance(), new IAddDeviceListener() {
          @Override
          public void onPreCheck(boolean b, DCErrorCode dcErrorCode) {
      
          }
      
          @Override
          public void onProvisionPrepare(int prepareType) {
              if (prepareType == 1) {
      // Pass in the SSID and Wi-Fi password to start provisioning.
                 AddDeviceBiz.getInstance().toggleProvision(ssid, password, 60);
              }
          }
      
          @Override
          public void onProvisioning() {
      
          }
      
          @Override
          public void onProvisionStatus(ProvisionStatus provisionStatus) {
              if ((provisionStatus != null) && provisionStatus.code() == ProvisionStatus.BLE_DEVICE_SCAN_SUCCESS.code()) {
                  ALog.d(TAG, "BLE_DEVICE_SCAN_SUCCESS");
                  if (provisionStatus.getExtraParams() != null) {
              // The device is scanned.
                      String devType = (String) provisionStatus.getExtraParams().get(ILopNetTypeCodes.KEY_DEV_TYPE);
                      String bleMac = (String) provisionStatus.getExtraParams().get(ILopNetTypeCodes.KEY_BLE_MAC);
                      String prouctID = (String) provisionStatus.getExtraParams().get(ILopNetTypeCodes.KEY_PRODUCT_ID);
                      ALog.d(TAG, "devType->" + devType + " bleMac->" + bleMac + " prouctID->" + prouctID);
                      if (ILopNetTypeCodes.DEV_TYPYE_BLE_SUBTYPE_3.equals(devType)){
                  // Continue provisioning.
                          AddDeviceBiz.getInstance().continueProvision(null);
                      }
                  }
              }
          }
      
          @Override
          public void onProvisionedResult(boolean isSuccess, DeviceInfo deviceInfo, DCErrorCode dcErrorCode) {
              String message = "onProvisionedResult. isSuccess:" + isSuccess + " deviceInfo:" + deviceInfo + " dcErrorCode:" + dcErrorCode;
              ALog.d(TAG, message);
              ThreadTools.runOnUiThread(new Runnable() {
                  @Override
                  public void run() {
                     AddDeviceBiz.getInstance().stopAddDevice();// Provisioning is complete. End the current provisioning flow.
                      if (isSuccess) {
                     // Provisioning successful.
      
                      } else {
                        // Provisioning failed.
                      }
                  }
              });
      
          }
      });
                                      
  7. Call DevService#setWifiStatus to notify the technology manager (TM) of the device's provisioning result. The following code provides an example.
    DevService.setWifiStatus(iotID, TmpEnum.DeviceWifiStatus.state, new DevService.ServiceListenerEx() {
       // If provisioning is successful, set state to DeviceWifiStatus_Set. If provisioning is not successful, set state to DeviceWifiStatus_NotSet.
    @Override
        public void onComplete(boolean b, @Nullable String s) {
             }
    });