Enhanced QR Code Pairing

Last Updated on : 2026-06-24 01:49:58Copy for LLMView as MarkdownDownload PDF

Enhanced QR code pairing for Wi-Fi devices works as follows:

  1. Scan & Fetch: The app scans the QR code to get a short URL and fetches pairing data (PIN, UUID) from the cloud.
  2. Local pairing: The app connects to the device hotspot.
  3. Activation: The device polls the cloud via a token to complete activation and binding.

Terms

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

  • Short URL: A shortened URL string generated from a long URL through programmatic conversion. Short URLs hide the real address and are easier to read, share, and remember.

QR code binding

The general process of QR code binding is as follows:

  1. Power on the device to enter the hotspot pairing mode and wait for the app to connect.
  2. The app scans the device QR code to get the short URL.
  3. The app requests the cloud API, and the cloud returns the device information.
  4. The app connects to the device and initiates pairing with the PIN and UUID.
  5. The device establishes local interaction with the app to complete device query and pairing information delivery.
  6. The device polls the cloud through a token to complete activation and binding, and the app receives the successful pairing result.

QR code pairing mainly applies to Wi-Fi devices.

QR code sources

  • Get the QR code during device production. You can print and attach QR code labels, or silkscreen them on the product surface. For more information, see Label Printing.
  • For devices with screens, you can register the active_shorturl callback function during device initialization to get the short URL information. Then, the device generates a QR code image and displays it on the screen.

Get a PIN

Currently, you can get a PIN only through Tuya production credential authorization. For more information, see Production Authorization.

Flowchart

AppCloudDevicePower onGet short URLRequest cloud API1Return device information through QR code scanning2Connect to device3Carry device information and start pairing4Listen for broadcast packetsReceive broadcast packets5Send pairing data6Poll cloud with token7Pairing succeeds8AppCloudDevice

Development guide

Enable the feature

Create a product on the Tuya Developer Platform and then enter the product development process. Under Function Definition > Product Advanced Functions, enable the Scan Code Pairing for the product. After you enable it, use this PID to purchase licenses for device authorization.

If you cannot find Scan Code Pairing in advanced functions, it is because the product solution is not bound to this advanced function. To request binding it with your product, contact your account manager or submit a service ticket.

Only licenses purchased after you enable Scan Code Pairing support this feature.

Example

#include "tuya_iot_com_api.h"
#include "tuya_iot_config.h"
#include "tuya_iot_wifi_api.h"
#include "tuya_wifi_netcfg.h"
#define UUID                        "f2*************b0"
#define AUTHKEY                     "6P**************************MX"
#define PID                         "U0**************Zy"
#define PIN                         "1******2"

int sample_main(int argc, char *argv[])
{
    int rt = OPRT_OK;
   /** Required SDK initialization interface. **/
    // The QR code pairing function adds PIN input in addition to the traditional UUID and AUTHKEY.
    WF_GW_PROD_INFO_S prod_info = {UUID, AUTHKEY, NULL,NULL,PIN};
    TUYA_CALL_ERR_RETURN(tuya_iot_set_wf_gw_prod_info(&prod_info));
    /** Required SDK callback interface. **/
    while (1)
    {
        sleep(10);
    }

    return 0;
}