HarmonyOS Native SDK
Provisioning and Registration
Bluetooth Provisioning

Bluetooth Provisioning

BLE provisioning uses a unified capability to connect, send Wi-Fi credentials, poll for registration, and disconnect. The target must already have been discovered over Bluetooth.

Start provisioning

import {
  GizDeviceRegistrationInfo,
  GizProvisionEvent,
  GizProvisionStage,
} from '@gizwits/smart-sdk';
import { hilog } from '@kit.PerformanceAnalysisKit';
 
const registration: GizDeviceRegistrationInfo | undefined =
  await device.bleCapability.provideWiFiCredentials(
    device,
    'wifi-ssid',
    'wifi-password',
    60,
    (event: GizProvisionEvent): void => {
      hilog.info(
        0x0000,
        'GizwitsSample',
        'Provision stage=%{public}s code=%{public}d',
        event.stage,
        event.code
      );
 
      if (event.stage === GizProvisionStage.CONFIG_SUCCESS) {
        // Update ArkUI with the successful state.
      }
    }
  );

Parameters are the device, SSID, password, total timeout in seconds, and event callback. Success returns registration data containing productKey, mac, deviceId, and randomCode.

Cancel provisioning

device.bleCapability.stopProvideWiFiCredentials(device);

The callback receives CONFIG_CANCELLED, and the pending Promise rejects.

Send Wi-Fi credentials only

GizBluetoothManager.configureNetwork() is a low-level API. It only sends Wi-Fi credentials to a discovered device and does not poll cloud registration. Prefer provideWiFiCredentials() for normal integrations.

await GizBluetoothManager.configureNetwork(device, 'wifi-ssid', 'wifi-password');
⚠️

A Wi-Fi password is sensitive. Never include it in hilog output, analytics, or feedback content.