Device Pairing UI BizBundle

Last Updated on : 2024-06-12 10:22:39download

Device Pairing UI BizBundle is used to implement pairing guidance and smart device activation. It applies to multiple common types of smart devices, such as Wi-Fi devices, Zigbee devices, Bluetooth devices, and devices that support QR code scanning like GPRS & NB-IoT devices. The UI BizBundle provides the service logic and UI encapsulation to guide pairing and activate smart devices over different protocols.

Device types

Wi-Fi device pairing

Wi-Fi smart devices can be paired and connected to cloud services in two modes: Wi-Fi Easy Connect (EZ) mode and access point (AP) or hotspot mode. IP cameras (IPCs) can be paired after QR code scanning.

Term Description
Wi-Fi EZ mode Also known as the EZ mode. This pairing mode is implemented through the following steps:
  1. The app encapsulates the pairing data into the specified section of an IEEE 802.11 packet and sends the packet to the network.
  2. The Wi-Fi module of a smart device runs in promiscuous mode and listens for and captures all packets over the network.
  3. The Wi-Fi mode parses the packets that carry the pairing data from the app into the data format specified by the protocol.
AP mode Also known as the hotspot mode. A mobile phone acts as a station (STA) and connects to the hotspot of a smart device. Then, both devices are paired to establish a socket connection between them and exchange data through the specified ports.
IPC pairing in QR code mode An IPC scans the QR code on the app to get the pairing data.

Zigbee device pairing

Zigbee gateways and sub-devices can be paired.

Term Description
Zigbee gateway The device that integrates the coordinator with Wi-Fi features on a Zigbee network. The gateway is responsible to formulate the Zigbee network and store data.
Zigbee sub-device A router or an end device on a Zigbee network. Each Zigbee sub-device is responsible to forward data, or respond to control commands.

Bluetooth device pairing

Tuya provides the following Bluetooth solutions.

Term Description
Bluetooth Low Energy (LE) A point-to-point connection is created between a Bluetooth or Bluetooth LE device and a mobile phone.
Bluetooth mesh Enable many-to-many (m:m) device communications over a mesh network released by Bluetooth Special Interest Group (SIG). This solution is also known as Bluetooth LE mesh.
Tuya mesh Tuya’s proprietary technology that enables Bluetooth devices to communicate over a mesh network.
Combo devices The devices that support Bluetooth and Wi-Fi combo can be paired over either Bluetooth or Wi-Fi.

QR code pairing

A smart device that supports this pairing mode is connected to Tuya’s cloud services immediately after power on. The app can be used to scan the QR code on the device to implement cloud-based device activation and binding. The QR code must comply with Tuya’s QR code rules. For more information, contact Tuya’s account manager.

Term Description
GPRS devices Smart devices that apply GPRS technologies to connect to the network and access cloud services.
NB-IoT devices Smart devices that apply NB-IoT technologies.

Matter device pairing

If you want to use the Matter device pairing feature, see Prepare for Integration with Matter Device for initialization.

Pairing by auto discovery

Tuya provides efficient pairing features on top of Tuya’s generic pairing technologies for smart devices.

Integrate with the UI BizBundle

  1. Create a project.
    Integrate Smart Life App SDK for Android into your project with Android Studio and add the framework of the UI BizBundle to your project.

  2. Configure the build.gradle file.

    
    dependencies {
        api enforcedPlatform("com.thingclips.smart:thingsmart-BizBundlesBom:${biz_bom_version}")
        api "com.thingclips.smart:thingsmart-bizbundle-device_activator"
        // To implement the QR code scanning feature, depend on the BizBundle for QR code scanning.
        api "com.thingclips.smart:thingsmart-bizbundle-qrcode_mlkit"
        api "com.thingclips.smart:thingsmart:${sdk_version}}"
    }
    
    
  3. Obfuscate the code.

    #fastJson
    -keep class com.alibaba.fastjson.**{*;}
    -dontwarn com.alibaba.fastjson.**
    
    #rx
    -dontwarn rx.**
    -keep class rx.** {*;}
    -keep class io.reactivex.**{*;}
    -dontwarn io.reactivex.**
    -keep class rx.**{ *; }
    -keep class rx.android.**{*;}
    
    #fresco
    -keep class com.facebook.drawee.backends.pipeline.Fresco
    -keep @com.facebook.common.internal.DoNotStrip class *
    -keepclassmembers class * {
    @com.facebook.common.internal.DoNotStrip *;
    }
    
    #tuya
    -keep class com.thingclips.**{*;}
    -dontwarn com.thingclips.**
    

Configure features

Configuration items Field name Description Default value
Hotspot name settings <string name="ap_mode_ssid">SmartLife</string> The prefix of a device hotspot for pairing. SmartLife
Support for Bluetooth devices <bool name="is_need_ble_support">true</bool> Specifies whether Bluetooth devices can be paired. true
Support for Bluetooth mesh devices <bool name="is_need_blemesh_support">true</bool> Specifies whether Bluetooth mesh devices can be paired. true
Support for QR code scanning <bool name="is_scan_support">true</bool> Specifies whether the app can be used to scan the QR code on a device and start pairing. true
Whether the Wi-Fi EZ mode is supported by automatic discovery <bool name="is_config_activator_ez">false</bool> Specifies whether smart devices that support the EZ mode can be automatically discovered. false

Configure auto discovery

Create a JSON file named activator_auto_serach_capacity.json in the assets directory. Add the following code to this file.

{
    //Specifies whether to support searching for sub-devices. 
  "searchTypeZigbee": false,
    //Specifies whether to support searching for Wi-Fi EZ devices. 
  "searchTypeEZ": true,
    //Specifies whether to support searching for Pegasus devices. 
  "searchTypePegasus": false,
    //Specifies whether to support searching for Bluetooth devices. 
  "searchTypeBle": false,
    //Specifies whether to support searching for wired devices. 
  "searchTypeWired": false,
    //Specifies whether to support searching for Matter devices. 
  "searchTypeMatter": false
}

Make API requests

Open the pairing page

ThingDeviceActivatorManager.INSTANCE.startDeviceActiveAction(this);

ThingDeviceActivatorManager.INSTANCE.addListener(new IThingDeviceActiveListener() {

            @Override
            public void onDevicesAdd(List<String> list) {

            }

            @Override
            public void onRoomDataUpdate() {

            }

            @Override
            public void onOpenDevicePanel(String s) {

            }

            @Override
            public void onExitConfigBiz() {

            }
        });

Request parameters

Parameter Description
activity The pairing activity.
homeId The home ID. For more information, see Home Information Management.

Response parameters

Parameter Description
devIds The success callback. A list of paired device IDs is returned.
updateRoomData Indicates whether room device details are updated.
onOpenDevicePanel Indicates whether a certain panel can be opened. You can implement this feature as needed.
onExitConfigBiz Indicates whether to exit the pairing service if pairing is not performed. You can implement this feature as needed.

Open the QR code scanning page

ScanManager.INSTANCE.openScan(this);