Device Pairing in QR Code Mode

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

This method only applies to devices that are connected to the internet.

Pairing process

Device Pairing in QR Code Mode

Query device UUID

Map<String, Object> postData = new HashMap<>();
// The URL obtained after the device QR code is scanned.
postData.put("code", url);

TuyaHomeSdk.getRequestInstance().requestWithApiNameWithoutSession("tuya.m.qrcode.parse", "4.0", postData, String.class, new ITuyaDataCallback<String>() {
	@Override
	public void onSuccess(String result) {
	  // The UUID returned in the result.
	  Log.i("TAG" , result);
	}

	@Override
	public void onError(String errorCode, String errorMessage) {
		Log.i("TAG" , errorCode);
	}
});

Initialize pairing parameters

TuyaQRCodeActivatorBuilder builder = new TuyaQRCodeActivatorBuilder()
		.setUuid(uuid)
		.setHomeId(homeId)
		.setContext(mActivity)
		.setTimeOut(timeout)
		.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
uuid The UUID that is returned after a device QR code is scanned.
homeId The home ID. For more information, see Home Management.
timeout The timeout value of a pairing task. Default value: 100. Unit: seconds.

Call the pairing method

ITuyaActivator mTuyaActivator = TuyaHomeSdk.getActivatorInstance().newQRCodeDevActivator(builder);
// Starts pairing.
mTuyaActivator.start();
// Stops pairing.
mTuyaActivator.stop();
// Destroys the pairing task.
mTuyaActivator.onDestory();