Wi-Fi EZ Mode

Last Updated on : 2023-05-22 06:38:23download

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.

Pairing process

Wi-Fi EZ Mode

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 ITuyaSmartActivatorListener() {

				@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

TuyaHomeSdk.getActivatorInstance().getActivatorToken(homeId,
		new ITuyaActivatorGetToken() {

			@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

ITuyaActivator mTuyaActivator = TuyaHomeSdk.getActivatorInstance().newMultiActivator(builder);
// Starts pairing.
mTuyaActivator.start();
// Stops pairing.
mTuyaActivator.stop();
// Exits the page and destroys certain caches and listeners.
mTuyaActivator.onDestroy();