TuyaOSNetworked Product FrameworkCapability MapActivation and Binding with QR Code

Activation and Binding with QR Code

Last Updated on : 2023-12-19 08:36:57download

Activate and bind a device by scanning its QR code using the mobile app.

Terms

  • QR code

    A QR code is a kind of two-dimensional barcode that holds encoded data in a graphical black-and-white pattern.

  • Short URL

    Convert a long URL into a shorter one using a program. Short URLs hide the real address and are easier to read, share, and remember.

Feature description

The process of activation and binding with QR code.

  1. The device connects to the cloud over MQTT.
  2. The mobile app reads the device’s QR code and then sends the decoded data to the cloud.
  3. The mobile app requests the token for pairing.
  4. The cloud sends the token to the device.
  5. The device disconnects from the MQTT server.
  6. The device uses the token to request information such as the domain name and time zone to perform activation and binding.

Source of the QR code:

  1. Get the QR code when the device is produced and place the QR code on the device or packaging.
  2. If the device has a screen, it requests the short URL from the cloud after getting connected. Then, it generates a QR code and displays it on the screen.

Activation and binding with QR code applies to the following devices:

  • Devices that use cellular networks, including GPRS, 3G, and 4G.
  • Wireless devices with screens that allow the user to enter Wi-Fi passwords, such as digital photo frames.
  • Wired devices.

All of these devices can connect to the internet and MQTT without depending on the mobile app.

How it works

DeviceCloudAppInitiate connection over MQTT.Determine if thedevice can directlyconnect to thecloud.Establish a connection if thedevice can be directlyconnected.Request the short URL.Return the short URL.Save the short URLGenerate a QR code and display it.opt[Device with screen]Read the QR code to get the short URL.Request the token for pairing.Return the token for pairing.Send the token.Disconnect the MQTTconnection.Get the configurationinformation with the token.Return information includingdomain name and time zone.Connect to the cloud foractivation.Poll for a device based on thetoken.Return the information aboutthe device activated with thetoken.DeviceCloudAppActivation and binding with QR code

Development guide

Runtime environment

Open tuya_iot_config.h and check if the following macro is defined.

#define ENABLE_QRCODE_ACTIVE 1

How to

  • Create a product on the Tuya IoT Development Platform and then enter the product development process. Click on the Function Definition tab, scroll down to Advanced Functions, and enable LinkSDK. Purchase licenses for device authorization using the PID of this product.

    Activation and Binding with QR Code

    You might not find LinkSDK in Advanced Functions. This is because the product solution does not have this function bound. To request binding it with your product, contact your account manager or submit a service ticket.

    You can use the purchased license to implement the function of activation and binding with QR code only after enabling LinkSDK.

  • After the call of device initialization, set the network information (for Wi-Fi devices, set the Wi-Fi’s SSID and password with an API request). After the device is connected to the internet, it will initiate an MQTT connection and proceed with activation.

  • If you need the short URL to generate a QR code for display, register the callback active_shorturl provided in IoT device functionality callbacks during device initialization. This callback returns the short URL after the device is connected to the internet.

Frequently requesting short URLs from the cloud might trigger the cloud’s protection mechanism, causing functional exceptions.
We recommend saving the short URL after obtaining it. You can use the saved short URL directly after the next power-on to avoid frequent access.