AP Pairing

Last Updated on : 2024-05-28 05:57:38download

This topic describes the access point (AP) to pair devices. It is a connection capability for pairing over Wi-Fi. In the pairing process, a mobile phone connects to the AP of the smart device and broadcasts the Wi-Fi credentials and pairing token over the LAN to enable the smart device to get this information for network connection and pairing. With a high success rate and good reliability, this mode adapts to 2.4 GHz and 5 GHz dual-band routers. However, users need to manually switch between the Wi-Fi bands connected to the mobile phone.

Initialize IActivator

Parameters

Parameter Type Required Description
mode ActivatorMode Yes The pairing mode.

Example

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

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 WiFiModeTableViewController: 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 APActivatorParams instance
let params = APActivatorParams(ssid: "my_wifi_ssid", password: "my_wifi_password", pairToken: "my_pair_token")

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

Stop pairing

This method stops device pairing.

Example

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