Wi-Fi EZ Mode

Last Updated on : 2024-05-28 05:52:13download

This topic describes pairing a device using the Wi-Fi EZ mode, also known as Wi-Fi Easy Connect or SmartConfig. In the pairing process, a mobile phone connects to the router and broadcasts the Wi-Fi credentials and pairing token to enable the smart device to get this information for connection and pairing. It is easy-to-use, but has compatibility requirements for mobile phones and routers. The success rate is lower than that of AP mode.

Initialize IActivator

Parameters

Parameter Type Required Description
mode ActivatorMode Yes The pairing mode.

Example

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

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

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

Stop pairing

This method stops device pairing.

Example

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