Wired Device Pairing

Last Updated on : 2024-04-04 16:36:27download

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

Pairing process

Wired Device Pairing

Discover device

The SDK provides the capability to discover a wired device ready for pairing. The device must be connected to the same network as the mobile phone. Then, register the notification for discovering wired devices. When the SDK receives the packet advertised by the wired device, it forwards the device information through notifications.

Example

IThingGwSearcher mTuyaGwSearcher = ThingOSActivator.deviceActivator().newThingGwActivator().newSearcher();

mTuyaGwSearcher.registerGwSearchListener(newIGwSearchListener() {
	@Override
	public void onDevFind(HgwBean hgwBean) {
	}
});

Parameter description

Parameter Description
hgwBean The data entity of the discovered gateway.

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.

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

Enable device discovery

Example

IThingActivator mIThingActivator = ThingOSActivator.deviceActivator().newGwActivator(
		new ThingGwActivatorBuilder()
			.setToken(token)
			.setTimeOut(timeout)
			.setContext(context)
			.setHgwBean(hgwBean)
			.setListener(new IThingSmartActivatorListener() {

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

					}

					@Override
					public void onActiveSuccess(DeviceBean devResp) {

					}

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

					}
			}
		));

Parameter description

Parameter Description
token The activation key.
timeout The pairing timeout, defaulting to 100, in seconds.
context The context passed to the activity.
hgwBean The data entity of the discovered gateway.

Disable device discovery

Example

IThingActivator mIThingActivator = ThingOSActivator.deviceActivator().newGwActivator(
		new ThingGwActivatorBuilder()
			.setToken(token)
			.setTimeOut(timeout)
			.setContext(context)
			.setListener(new IThingSmartActivatorListener() {

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

					}

					@Override
					public void onActiveSuccess(DeviceBean devResp) {

					}

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

					}
			}
		));

Parameter description

Parameter Description
token The activation key.
timeout The pairing timeout, defaulting to 100, in seconds.
context The context passed to the activity.

Pairing methods

IThingActivator mIThingActivator = ThingOSActivator.deviceActivator().newGwActivator(builder);
// Start pairing
mIThingActivator.start()
// Stop pairing
mIThingActivator.stop()
// Destroy
mIThingActivator.onDestroy()