TuyaOS Central Control activation with QR Code

Gateway equipment, voice control devices, etc.


Post Reply
luoji
Posts: 105

TuyaOS central control SDK uses QR code scanning to activate and access Tuya Cloud. The detailed process is as follows.

Preparation

Configuration file example

Subsequent activation-related configuration information can be found in the sample config.json, as shown below:

Code: Select all

{
    "pid": "xxxx",
    "uuid": "xxxx",
    "authkey": "xxxxx",
    "storage_path": "/tuya/data/",
    "log_level": 4,
    "sw_ver": "1.0.0",
    "oem": true,
    "tuya": {
        "zigbee": {
            "storage_path": "/tuya/data/",
            "cache_path": "/tmp/",
            "dev_name": "/dev/ttyS0", 
            "cts": 1,
            "thread_mode": 1
        }
    }
}

Authorization information introduction

Create a product on the Tuya developer platform and obtain authorization information, including: pid, uuid, and authkey.

● Product pid: After each product is created in the Tuya IOT front desk, a unique ID (product id) will be generated. This ID can identify the product;
● Firmware key: After IOT front-end hardware development adds new hardware, a firmware key will be generated, representing the unique identification of the firmware;
● OEM: Indicates whether the firmware developed by the customer supports OEM. For example, the same central control program developed by developers can be adapted to different models of central control. Although the pid is different, the firmware key can be the same, which facilitates subsequent unified ota upgrades.

Therefore, the config.json file configuration can be as follows:

  1. OEM is not required. Fill in the pid information in the pid field and set OEM to false.

    Code: Select all

    {
        "pid": "pidxxxxxx",
        "uuid": "xxxxxx",
        "authkey": "xxxxxx",
        "oem": false,
    }
  2. OEM and pid fields are required to fill in the firmware key information, and OEM is set to true.

    Code: Select all

    {
        "pid": "keyxxxxxx",
        "uuid": "xxxxxx",
        "authkey": "xxxxxx",
        "oem": true,
    }
    Developers can use it flexibly as needed.

Introduction to other configuration information

storage_path: storage directory. TuyaOS central control SDK needs to store data when running. Please allocate an independent storage path to avoid conflicts between the internal data of the SDK and the developer's own data.
log_level: log level, it is best to set it to 4, which is more suitable for troubleshooting. If not set, the default is 4.
sw_ver: Firmware version number. This version number is used to manage firmware upgrades. If you adapt ota-related interfaces, you can use the Tuya IOT platform to upgrade the firmware.
Zigbee field: If you need to develop the gateway function of the central control, you need to pay attention to it and configure the relevant information of the zigbee module.

After filling in the above relevant information correctly, you can enter the process of central control activation stage.

Central control activation process

Interface Description

The SDK provides a shortURL for activating the device. You can convert it into a QR code, and the user can scan the code through the App to activate the device.
Usage examples:

Code: Select all

static void active_shourturl_cb(char *shorturl)
{
    if (NULL == shorturl) {
        return;
    }

    PR_DEBUG("shorturl : %s", shorturl);

    return;
}

TY_GW_INFRA_CBS_S gw_cbs = {
    .gw_reset_cb       = __gw_reset_cb,
    .gw_upgrade_cb     = __gw_upgrade_cb,
    .gw_active_stat_cb = __gw_active_stat_cb,
    .gw_reboot_cb      = __gw_reboot_cb,
    .gw_active_url_cb  = active_shourturl_cb,
};

op_ret = user_svc_init(&gw_cbs);
if (op_ret != OPRT_OK) {
    PR_ERR("user_svc_init err: %d", op_ret);
    return op_ret;
}

QR code generation

In the development stage, if the QR code function has not been developed well, you can use the online QR code platform.
Enter the shorturl in the log above to generate a QR code, and then use Tuya Smart APP to scan the code to activate.

Post Reply