TuyaLink-Based Device Pairing

Last Updated on : 2024-06-24 08:04:15download

TuyaLink is an open solution that enables smart devices, including proprietary network modules and smart devices, to connect to Tuya’s cloud services. 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. For more information, see TuyaLink.

Parse the QR code

ThingActivatorCoreKit.getCommonBizOpt().parseQrCode("str", new Business.ResultListener<ScanActionBean>() {
                @Override
                public void onFailure(BusinessResponse bizResponse, ScanActionBean bizResult, String apiName) {

                }

                @Override
                public void onSuccess(BusinessResponse bizResponse, ScanActionBean bizResult, String apiName) {

                }
            });

Request parameters

Parameters Description
code The string of the QR code.

Description of ScanActionBean

Parameters Description
actionName The actionName for a TuyaLink-based device is "device_net_conn_bind_tuyalink".
actionData The device information.

Pair a device

// builder
val builder = ThingDeviceActiveBuilder()
            .setActiveModel(ThingDeviceActiveModeEnum.THING_LINK) //Device pairing mode enum
            .setGroupType("homeGroup")
            .setUuid(uuid)
            .setRelationId(homeId)
            .setListener(object : IThingDeviceActiveListener {
                override fun onFind(devId: String) {
                }

                override fun onBind(devId: String) {
                }

                override fun onActiveSuccess(deviceBean: DeviceBean) {

                }

                override fun onActiveError(errorBean: ThingDeviceActiveErrorBean) {

                }

                override fun onActiveLimited(limitBean: ThingDeviceActiveLimitBean) {
                }
            })

val activeManager = ThingActivatorCoreKit.getActiveManager().newThingActiveManager()

//Start
activeManager.startActive(builder)

Parameter description

Parameters Description
groupType It is fixed as homeGroup.
uuid The unique identifier of the device.
relationId The ID of the home with which the device is bound.
activeModel The pairing capability enum.
listener The callback for the result of pairing.

Stop pairing

activeManager.stopActive()

Error codes

Error codes Reason
10002 Invalid parameter.
DEVICE_ALREADY_BIND Strong binding error. The device is already bound with a user. Pairing can work only after the device is unbound from the current user.
GUEST_NOT_SUPPORT_STRONG_BIND A guest account is not allowed to pair a device of strong binding.