Wi-Fi EZ Mode

Last Updated on : 2024-05-17 03:10:29download

The Wi-Fi EZ mode is also known as the SmartConfig mode. After a user connects a mobile phone to a router, the router broadcasts packets to communicate and pair with a target smart device. It is easy-to-use, but has compatibility requirements for mobile phones and routers. The success rate is lower than that of hotspot pairing.

Initialize pairing parameters

API description

ActivatorBuilder builder = new ActivatorBuilder()
		.setSsid(ssid)
		.setContext(context)
		.setPassword(password)
		.setActivatorModel(ActivatorModelEnum.TY_EZ)
		.setTimeOut(timeout)
		.setToken(token)
		.setListener(new IThingSmartActivatorListener() {

				@Override
				public void onError(String errorCode, String errorMsg) {

				}

				@Override
				public void onActiveSuccess(DeviceBean devResp) {
					// Multiple callbacks are required to pair multiple devices in the same call.
				}

				@Override
				public void onStep(String step, Object data) {

				}
			}
		));

Parameters

Parameter Description
token The pairing token.
context The context to be set in activity.
ssid The name of the Wi-Fi network to which a paired device is connected.
password The password of the Wi-Fi network to which a paired device is connected.
activatorModel The pairing mode. For example, the value is set to ActivatorModelEnum.TY_EZ to represent the Wi-Fi EZ mode.
timeout The timeout value of a pairing task. Default value: 100. Unit: seconds.

Get a token

Before the Wi-Fi EZ pairing process, the SDK must get a pairing token from the cloud in the networked state. The token is valid for 10 minutes and expires immediately after the device is paired. A new token must be generated if the device needs to be paired again.

API description

ThingHomeSdk.getActivatorInstance().getActivatorToken(homeId,
		new IThingActivatorGetToken() {

			@Override
			public void onSuccess(String token) {

			}

			@Override
			public void onFailure(String s, String s1) {

			}
		});

Parameters

Parameter Description
homeId The home ID. For more information, see Home Management.

Call the pairing method

IThingActivator mThingActivator = ThingHomeSdk.getActivatorInstance().newMultiActivator(builder);
// Starts pairing.
mThingActivator.start();
// Stops pairing.
mThingActivator.stop();
// Exits the page and destroys certain caches and listeners.
mThingActivator.onDestroy();