Wi-Fi EZ Mode

Last Updated on : 2024-04-03 16:34:31download

How Wi-Fi EZ mode works:

Wi-Fi EZ Mode

Get a token

Before the 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

Get the pairing token.

ThingOSActivator.deviceActivator().getActivatorToken(final long gid, final IThingActivatorGetToken activatorGetToken);

Parameter description

Parameter Description
gid The relation ID of the area to which the device belongs. See Get Area Relation ID.
activatorGetToken The callback.

Example

ThingOSActivator.deviceActivator().getActivatorToken(gid,
		new IThingActivatorGetToken() {

			@Override
			public void onSuccess(String token) {

			}

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

			}
		});

Initialize pairing parameters

Example

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) {
					// If multiple devices are activated at the same time, they will be called back multiple times
				}

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

				}
			}
		));

Parameter description

Parameter Description
token The activation key.
context The context passed to the activity.
ssid The name of the home Wi-Fi network the paired device is connected to.
password The password of the home Wi-Fi network the paired device is connected to.
activatorModel The pairing mode. It is set to ActivatorModelEnum.TY_EZ for Wi-Fi EZ mode.
timeout The pairing timeout, defaulting to 100, in seconds.

Pairing methods

IThingActivator mTuyaActivator = ThingOSActivator.deviceActivator().newMultiActivator(builder);
// Start pairing.
mTuyaActivator.start();
// Stop pairing.
mTuyaActivator.stop();
// Destroy the cache and listeners when exiting the page.
mTuyaActivator.onDestroy();