Sub-Device Pairing

Last Updated on : 2024-05-14 02:42:33download

The app sends a sub-device pairing command to the cloud, which forwards the command to the gateway to initiate the pairing process. After the sub-device receives the pairing command, it registers and activates with the cloud through the gateway. On success, the cloud notifies the app of the result.

The sub-device connects to the cloud through a Wi-Fi or wired gateway as an intermediary.

Start searching

val scankey = ThingActivatorCoreKit.getScanDeviceManager().startGatewaySubDeviceSearch(
       gatewayId: String,
    millisTimeOut: Long,
    thingActivatorScanCallback: ThingActivatorScanCallback
)

Parameter description

Parameters Description
gwId The gateway ID.
millisTimeOut The timeout value, in milliseconds.
thingActivatorScanCallback The search timeout callback.

Stop searching

ThingActivatorCoreKit.getScanDeviceManager().stopScan(scankey)

Start pairing

Method 1: Pair a sub-device from the search result

val builder = ThingDeviceActiveBuilder()
            .setActiveModel(ThingDeviceActiveModeEnum.SUB)
            .setSubSearchBeans(thingActivatorScanDeviceBeans)
            .setTimeOut(timeout)
            .setListener(object : IThingDeviceActiveListener {
                override fun onFind(devId: String) {
                }

                override fun onBind(devId: String) {
                }

                override fun onActiveSuccess(deviceBean: DeviceBean) {

                }

                override fun onActiveError(errorBean: ThingDeviceActiveErrorBean) {

                }

                override fun onActiveLimited(limitBean: ThingDeviceActiveLimitBean) {
                }
            })

val activeManager = ThingActivatorCoreKit.getActiveManager().newThingActiveManager()

activeManager.startActive(builder)

Parameter description

Parameters Description
subSearchBeans The list of discovered devices.
timeout The timeout value, in seconds.
activeModel The pairing capability enum.
listener The callback for the result of pairing.

Method 2: Pair a sub-device directly

val builder = ThingDeviceActiveBuilder()
            .setActiveModel(ThingDeviceActiveModeEnum.SUB)
            .setTimeOut(120)
            .setGwId(mScanBuilder.gwId)
            .setListener(object : IThingDeviceActiveListener {
                override fun onFind(devId: String) {
                }

                override fun onBind(devId: String) {
                }

                override fun onActiveSuccess(deviceBean: DeviceBean) {

                }

                override fun onActiveError(errorBean: ThingDeviceActiveErrorBean) {

                }

                override fun onActiveLimited(limitBean: ThingDeviceActiveLimitBean) {
                }
            })

val activeManager = ThingActivatorCoreKit.getActiveManager().newThingActiveManager()

activeManager.startActive(builder)

Parameter description

Parameters Description
gwid The gateway ID.
timeout The timeout value, in seconds.
activeModel The pairing capability enum.
listener The callback for the result of pairing.

Stop pairing

mThingActivatorManager.stopActive()