English
English
简体中文
Contact Us
Register
Log In

AP Mode

Last Updated on : 2022-10-28 03:14:14download

This topic describes the access point (AP) or hotspot mode to pair devices. It is a connection capability for pairing over Wi-Fi. After the mobile phone is connected to the Wi-Fi hotspot of the device to be paired, the app is paired and communicates with the device over Wi-Fi. This pairing mode features a high success rate and excellent reliability, and supports routers that can process data using both 2.4 GHz and 5 GHz frequencies. Users must manually change the Wi-Fi band on their mobile phones to enable pairing.

Pairing process

Process of pairing in AP mode

AP Mode

Initialize pairing parameters

API description

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

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

				}

				@Override
				public void onActiveSuccess(DeviceBean devResp) {

				}

				@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_AP to represent the AP mode.
timeout The timeout value of a pairing task. Default value: 100. Unit: seconds.

Get a token

Before the AP 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().newActivator(builder);
// Starts pairing.
mTuyaActivator.start();
// Stops pairing.
mTuyaActivator.stop();
// Exits the page and destroys certain caches and listeners.
mTuyaActivator.onDestroy();