Pair with QR Code (For Smart Cameras)

Last Updated on : 2024-05-14 02:38:21download

A smart device scans the QR code generated by the mobile app to get the Wi-Fi credentials and token. It then connects to the router and gets activated in the cloud. This pairing method is typically used for devices with a camera and Wi-Fi module, such as smart cameras and doorbells.

Query pairing token

Before the pairing process, the app 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.

ThingActivatorDeviceCoreKit.getActivatorInstance()
                .getActivatorToken(spaceId,IThingActivatorGetToken)

Parameter description

Parameters Description
spaceId The ID of the home with which the device is bound.
callback The callback for the result.

Generate a QR code

val mThingActivator =
        ThingActivatorDeviceCoreKit.INSTANCE.getActivatorInstance().newCameraDevActivator(new ThingCameraActivatorBuilder()
            .setSsid(ssid)
            .setPassword(pass)
            .setToken(token)
            .setListener(object : IThingSmartCameraActivatorListener {
                override fun onQRCodeSuccess(qrcodeUrl: String) {

                }

                override fun onError(errorCode: String, errorMsg: String) {

                }

                override fun onActiveSuccess(devResp: DeviceBean) {}
            })
        )

mThingActivator.createQRCode()

Parameter description

Parameters Description
ssid The name of the target Wi-Fi network.
password The password of the target Wi-Fi network.
token The pairing token.
listener The callback for the result.

Start pairing

val builder = ThingDeviceActiveBuilder()
            .setActiveModel(ThingDeviceActiveModeEnum.QC)
            .setContext(context)
            .setSsid(ssid)
        .setPassword(pwd)
        .setToken(token)
        .setTimeOut(timeout)
            .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()

activeManager.startActive(builder)

Parameter description

Parameters Description
context The context.
ssid The name of the target Wi-Fi network.
pwd The password of the target Wi-Fi network.
timeout The timeout value, in seconds.
token The information about the token.
activeModel The pairing capability enum.
listener The callback for the result of pairing.

Stop pairing

activeManager.stopActive()