Sub-Device Pairing

Last Updated on : 2024-05-27 06:06:49download

Sub-device pairing can be initiated only when a gateway is online in the cloud, and the sub-device stays in pairing mode. This topic describes how to pair a sub-device, using the Zigbee sub-device as an example.

Initialize IActivator

Parameters

Parameter Type Required Description
mode ActivatorMode Yes The pairing mode.

Example

ZigbeeActivator zigbeeActivator = (ZigbeeActivator) ActivatorService.activator(ActivatorMode.Zigbee);

Register IActivatorListener to listen for pairing result

Parameters

Parameter Type Required Description
listener IActivatorListener Yes Listen for callback

Example

zigbeeActivator.setListener(new IActivatorListener() {
            @Override
            public void onSuccess(@Nullable IDevice iDevice) {
                Log.d(TAG, "onSuccess: ");
                if (null != iDevice){
                    // The ID of the gateway device.
                    iDevice.getDeviceId();
                }
            }

            @Override
            public void onError(@NonNull String s, @NonNull String s1) {
                Log.d(TAG, "onError: " + s);
            }
        });

Initialize pairing parameters

Parameters

Parameter Type Required Description
gwDeviceId String Yes The ID of the gateway.
time int Yes Set the timeout.

Example

ZigbeeActivatorParams zigbeeActivatorParams = new ZigbeeActivatorParams.Builder()
                .setGwDeviceId(gwDeviceId)
                .setTimeout(time)
                .build();
zigbeeActivator.setParams(zigbeeActivatorParams);

Start pairing

This method starts device pairing.

Example

zigbeeActivator.start();

Stop pairing

This method stops device pairing.

Example

zigbeeActivator.stop();