English
English
简体中文
Contact Us
Register
Log In

TuyaLink-Based Device Binding

Last Updated on : 2022-09-22 12:30:12download

TuyaLink is an open solution that enables IoT devices, including proprietary network modules and smart devices, to connect to Tuya’s cloud services.

TuyaLink lowers the bar for IoT development by integrating with Tuya’s IoT Core technologies, including things data model, rule engines, data parsing, device management, operations and monitoring, alert management, OTA firmware updates, and application development.

TuyaLink allows you to quickly integrate with the Tuya ecosystem and achieve interconnectivity between devices across different domains. A range of development resources for PaaS, SaaS, and apps helps you implement IoT projects with improved cost efficiency and reduced lead time.

TuyaLink-Based Device Binding

For more information, see TuyaLink.

Device binding

Each TuyaLink-based device is created with a QR code on the Tuya IoT Development Platform. To bind a TuyaLink-based device with the app, users scan the QR code of the device first. The system parses the URL of the QR code and returns a universally unique identifier (UUID) of the device. Then, the UUID is used in the API request to bind the device.

Query device UUID

// Similar to the operation to pair a device after QR code scanning.
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);
	}
});

Bind a device

//ITuyaDeviceActivator.java
void bindTuyaLinkDeviceWithQRCode(long homeId, String uuid, ITuyaDevActivatorListener listener);

Parameters

Parameter Description
homeId The home ID.
uuid The UUID that is returned after a device QR code is scanned and parsed.
ITuyaDevActivatorListener The listener for the binding result.

Example

TuyaHomeSdk.getActivatorInstance().bindTuyaLinkDeviceWithQRCode(homeId, mUuid, new ITuyaDevActivatorListener() {
                    @Override
                    public void onError(String errorCode, String errorMsg) {
                        Log.d(TAG,"errorMsg = " + errorMsg + " / errorCode = " + errorCode);
                    }

                    @Override
                    public void onActiveSuccess(DeviceBean devResp) {
                        Log.d(TAG,"onActiveSuccess --->>" );
                    }
                });