Device Pairing

Last Updated on : 2024-06-24 08:06:51download

The device pairing service in the BizBundle SDK is encapsulated and extended on top of the Smart Life App SDK. It simplifies the pairing process and improves the reusability of code. Informative pairing status callbacks and error codes enable real-time monitoring of the pairing process and effective troubleshooting.

Features

The device pairing service provides unified and parallel device searching and activation services. It supports the following capabilities:

  • Wi-Fi Easy Connect mode (a.k.a. EZ mode)
  • Wi-Fi access point mode (a.k.a. AP mode)
  • Pairing with QR code (for smart cameras)
  • Zigbee wired gateway pairing
  • Zigbee sub-device pairing
  • Pairing with QR code (app scans device’s QR code)
    • For directly connected devices
    • For Bluetooth devices
  • Pegasus pairing
  • NB-IoT device pairing
  • Bluetooth device pairing
    • Bluetooth Low Energy (LE) device pairing
    • Bluetooth mesh device pairing
    • Bluetooth LE and Wi-Fi combo device pairing
    • Beacon device pairing
  • TuyaLink-based device binding
  • Matter device pairing
  • Composite scan

How-to

The class ThingActivatorCoreKit provides APIs for the device pairing service, with scanning for nearby devices and pairing devices at the core.

//Scan for nearby devices
val scanManager = ThingActivatorCoreKit.getScanDeviceManager()

//Pair a discovered device
val activeManager = ThingActivatorCoreKit.getActiveManager().newThingActiveManager()

For the supporting features, check the code comments.

Error codes

Error codes Reason
10002 Invalid parameter.
DEVICE_ALREADY_BIND Strong binding error. The device is already bound with a user. Pairing can work only after the device is unbound from the current user.
GUEST_NOT_SUPPORT_STRONG_BIND A guest account is not allowed to pair a device of strong binding.

System compatibility

For Android 12 and later:

  • In Android 11 and earlier, individual apps require location permissions to use Bluetooth scan and get the SSID of the Wi-Fi network to connect.
  • From Android 12, the location permissions are split. To scan for nearby ordinary Bluetooth devices, you only need to request the Bluetooth scan and Bluetooth connect permissions, without the location permissions. And, add the usesPermissionFlags attribute to your Bluetooth scan permission declaration, and set this attribute’s value to neverForLocation. For more information, see the official Android documentation Bluetooth permissions.

To scan for iBeacon broadcast signals, you still need to request the location permissions.

  • If your app is not used to control iBeacon devices, you only need to request Bluetooth-specific permissions.

    Beacons such as iBeacon are filtered from the scan results when including the neverForLocation flag.

    <uses-permission android:name="android.permission.BLUETOOTH_SCAN"
            android:usesPermissionFlags="neverForLocation"/>
        <uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>
        <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE"/>
    
  • If your app is used to control iBeacon devices, you need to request the location permissions and not include the neverForLocation flag.

    <uses-permission android:name="android.permission.BLUETOOTH_SCAN"/>
    <uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>
    <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />