Wired Device Pairing

Last Updated on : 2024-05-27 06:01:13download

A wired device connects to a router over an Ethernet cable. During the pairing process, users do not need to enter the name and password of the access point. This topic describes how to pair a wired device, using the wired Zigbee gateway as an example.

Initialize IActivator

Parameters

Parameter Type Required Description
mode ActivatorMode Yes The pairing mode.

Example

WiredActivator wiredActivator = (WiredActivator) ActivatorService.activator(ActivatorMode.Wired);

Get a pairing token

Before pairing a wired device, the SDK requests a pairing token valid for 10 minutes from the cloud. This token will become invalid immediately after the pairing is successful. To pair the device again, you must request a new token.

Parameters

Parameter Type Required Description
assetId String Yes The ID of the specified asset.
callback IndustryDataCallBack Yes The callback.

Example

// Get the asset activation token.
ActivatorService.activatorToken("assetId", new IndustryDataCallBack<String>() {
            @Override
            public void onSuccess(String s) {
                Log.d(TAG, "onSuccess: " + s);
            }

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

Register IDiscoveryListener to listen for scanning result

Parameters

IWiredDevice data model

Parameter Type Required Description
getIP() String Yes Get the IP address of the device.
getGWId() String Yes Get the ID of the gateway.
getProductKey() String Yes Get the product key for the device.
IDiscovery iDiscovery = ActivatorService.discovery(DiscoveryMode.WIRED);
iDiscovery.setListener(new IDiscoveryListener() {
            @Override
            public void didDiscover(@NonNull IDiscoveryDevice iDiscoveryDevice) {
                if (iDiscoveryDevice instanceof IWiredDevice){
                    ((IWiredDevice) iDiscoveryDevice).getIP();
                    ((IWiredDevice) iDiscoveryDevice).getGWId();
                    ((IWiredDevice) iDiscoveryDevice).getProductKey();
                }
            }
        });

Initialize pairing parameters

Parameters

Parameter Type Required Description
gwDevice IWiredDevice Yes Pass in the gateway object.
time int Yes Set the timeout.
token String Yes Set the token.

Example

WiredActivatorParams wiredActivatorParams = new WiredActivatorParams.Builder()
                .setGWDevice(gwDevice)
                .setTimeout(time)
                .setToken("token")
                .build();
wiredActivator.setParams(wiredActivatorParams);

Register IActivatorListener to listen for pairing result

Parameters

Parameter Type Required Description
listener IActivatorListener Yes Listen for the callback.

Example

wiredActivator.setListener(new IActivatorListener() {
            @Override
            public void onSuccess(@Nullable IDevice iDevice) {
                Log.d(TAG, "onSuccess: ");
            }

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

            }
        });

Start pairing

This method starts device pairing.

Example

wiredActivator.start();

Stop pairing

This method stops device pairing.

Example

wiredActivator.stop();