Wired Mode

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

A wired device connects to a router over an Ethernet cable. During the pairing process, users do not need to enter the hotspot name and password of the router. This topic describes the process to pair a Zigbee wired gateway.

Pairing process

Wired Mode

Discover a device

The SDK provides the capability to discover the wired device pending pairing. The device must be connected to the same network as the mobile phone to enable pairing. Then, register the notification of data of the wired device. When the SDK receives the data broadcasted by the wired device, it forwards the data as a notification to the app.

API description

ITuyaGwSearcher mTuyaGwSearcher = TuyaHomeSdk.getActivatorInstance().newTuyaGwActivator().newSearcher();
		mTuyaGwSearcher.registerGwSearchListener(new IGwSearchListener() {
			@Override
			public void onDevFind(HgwBean hgwBean) {

			}
		});

Parameters

Parameter Description
hgwBean The data entity of the discovered gateway.

Initialize pairing parameters

Device discovery supported

API description

ITuyaActivator mITuyaActivator = TuyaHomeSdk.getActivatorInstance().newGwActivator(
		new TuyaGwActivatorBuilder()
			.setToken(token)
			.setTimeOut(timeout)
			.setContext(context)
			.setHgwBean(hgwBean)
			.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.
timeout The timeout value of a pairing task. Default value: 100. Unit: seconds.
hgwBean The data entity of the discovered gateway.

Device discovery unsupported

API description

ITuyaActivator mITuyaActivator = TuyaHomeSdk.getActivatorInstance().newGwActivator(
		new TuyaGwActivatorBuilder()
			.setToken(token)
			.setTimeOut(timeout)
			.setContext(context)
			.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.
timeout The timeout value of a pairing task. Default value: 100. Unit: seconds.

Get a token

Before the wired device 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.

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 mITuyaActivator = TuyaHomeSdk.getActivatorInstance().newGwActivator(builder);
// Starts pairing.
mITuyaActivator.start()
// Stops pairing.
mITuyaActivator.stop()
// Exits the page and clears cached data.
mITuyaActivator.onDestroy()