Wired Device Pairing

Last Updated on : 2024-05-28 06:08:53download

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

self.pair = ActivatorService.shared.activator(.WiredGateway)

Get a pairing token

Parameters

Parameter Type Required Description
assetId String Yes The ID of the specified asset.
longitude String No The longitude.
latitude String No The latitude.
success ((String)->(Void))? No The success callback.
failure ((Error)->(Void))? No The failure callback.

Example

// Get the asset activation token.
ActivatorService.shared.activatorToken(assetId: "123456", longitude: "30.1234", latitude: "120.5678", success: { token in
    // The success callback.
    print("The activation token is \(token)")
}, failure: { error in
    // The failure callback.
    print("Failed to get the activation token. Error \(error.localizedDescription)")
})

Register IActivatorListener to listen for pairing result

Parameters

Parameter Type Required Description
deviceModel IActivatedDevice? Yes If the operation is successful, it indicates the information about the activated device. Otherwise, it is nil.
params ActivatorParams? Yes The parameters of actions.

Callbacks

Function name Parameter Description
onSuccess deviceModel: IActivatedDevice? , params: ActivatorParams? The success callback, returning the information about the activated device.
onError error: Error, params: ActivatorParams? The failure callback, returning an error message.

Example

private func start() {
    pair.listener = self
}

extension ViewController: IActivatorListener {
    func onSuccess(deviceModel: IActivatedDevice?, params: ActivatorParams?) {
        SVProgressHUD.dismiss()
        self.navigationController?.popToRootViewController(animated: true)
    }

    func onError(error: Error, params: ActivatorParams?) {
        SVProgressHUD.dismiss()
        SVProgressHUD.showInfo(withStatus: error.localizedDescription)
    }
}

Start pairing

This method starts device pairing.

Parameters

Parameter Type Required Description
params ActivatorParams Yes The parameters of the pairing action. See the example.

Example

// Create WiredGatewayActivatorParams instance.
let params = WiredGatewayActivatorParams(token: "my_pair_token")

// Start pairing. pair is generated during initialization.
// self.pair = ActivatorService.shared.activator(.WiredGateway)
pair.startPair(params)

Stop pairing

This method stops device pairing.

Example

// Stop pairing. pair is generated during initialization.
// self.pair = ActivatorService.shared.activator(.WiredGateway)
pair.stopPair()