Quick Start

Last Updated on : 2025-06-16 06:00:44download

This topic describes the directory structure of the development kit, with an explanation of folders and their content.

Directory

The directory of the development kit:

├── hardware                  # Hardware documentation.
├── pc
│    └── tools                # Development tools.
├── software
│    ├── packages             # SDK package.
│    ├── SDKInformation.json  # SDK information file.
│    └── TuyaOS               # SDK directory.
│        ├── apps             # The sample applications, which can be modified as needed.
│        ├── build
│        ├── build_app.sh     # The build script.
│        ├── CHANGELOG.md
│        ├── include          # SDK header files.
│        ├── libs             # SDK libraries. You can link them as needed.
│        ├── LICENSE          # Tuya MIT License
│        ├── Makefile
│        ├── output           # The build output.
│        ├── README.md
│        ├── scripts
│        └── vendor           # The toolchain. When you build a project, the toolchain is automatically downloaded to this directory.
└── tuya.json

TuyaOS > apps > tuyaos_demo_gw_ble_longrange directory:

├── include                      # The header file.
├── local.mk
├── output                       # The demo output.
├── README.md                    # The Readme file.
├── src                          # The source code.
└── tuyaos_adapter

Configurations

The RTOS gateway needs to generate a JSON configuration during initialization, as shown below:

STATIC OPERATE_RET __gen_config(ty_cJSON **cfg)
{
    ty_cJSON *root = NULL, *bt = NULL, *tuya = NULL;

    if (cfg == NULL) {
        PR_ERR("param is null");
        return OPRT_INVALID_PARM;
    }

    bt = ty_cJSON_CreateObject();
    ty_cJSON_AddNumberToObject(bt, "enable_hb", 1);
    ty_cJSON_AddNumberToObject(bt, "scan_timeout", 5);
    ty_cJSON_AddNumberToObject(bt, "subdev_type", 0xF);

    tuya = ty_cJSON_CreateObject();
    ty_cJSON_AddItemToObject(tuya, "bt", bt);

    root = ty_cJSON_CreateObject();
    ty_cJSON_AddStringToObject(root, "pid", PRODUCT_KEY);
    ty_cJSON_AddStringToObject(root, "uuid", UUID);
    ty_cJSON_AddStringToObject(root, "authkey", AUTHKEY);
    ty_cJSON_AddItemToObject(root, "tuya", tuya);

    *cfg = root;

    return OPRT_OK;
}

The fields are analyzed in detail as follows. Format:

{
    "pid": <xxx>,
    "uuid": <...>,
    "authkey_key": <...>,
    "ap_ssid": <... optional>,
    "ap_password": <... optional>,
    "log_level": <level>,
    "storage_path": <...>,
    "start_mode": <xxxx>,
    "tuya": {
        "bt": {
                "dev_name": <xxx, string>,
                "enable_hb": <xxx, number>,
                "scan_timeout": <xxx, number>,
                "subdev_type": <xxx, number>,
        },
    },
    "user": {
        [ { "tp": <DEV_ATTACH_MOD_X, number>, "sw_ver": <version, string> }, ... ]
    },
}

Common configurations

Field Required Description
PID Yes The SDK runs in non-OEM mode. pid specifies the product ID (PID) of the current device.
uuid No The universally unique identifier. The system reads UUID from the flash memory first. If no UUID is found, the UUID specified here is used.
authkey_key No The authorization key. The system reads the authorization key from the flash memory first. If no authorization key is found, the authorization key specified here is used.
ap_ssid No The SSID of the access point (AP) used for pairing in Wi-Fi AP mode. If not specified, the default value is SmartLife-<the last four characters of the WLAN MAC>.
ap_password No The password of the AP, defaulting to empty.
log_level No The log level, defaulting to debug level (level 4).
start_mode No The supported Wi-Fi pairing modes:
  • 0: WF_START_AP_ONLY. Wi-Fi AP mode only.
  • 1: WF_START_SMART_ONLY. Wi-Fi EZ mode (Wi-Fi Easy Connect) only.
  • 2: WF_START_AP_FIRST. Both Wi-Fi AP mode and Wi-Fi EZ mode are available, with Wi-Fi AP mode taking priority.
  • 3: WF_START_SMART_FIRST. Both Wi-Fi AP mode and Wi-Fi EZ mode are available, with Wi-Fi EZ mode taking priority.
  • 4: WF_START_SMART_AP_CONCURRENT. Wi-Fi AP mode and Wi-Fi EZ mode coexist.

Bluetooth configuration

Field Description
dev_name The name of the specified Bluetooth device.
enable_hb Enable the heartbeat checks.
scan_timeout The scan timeout in Bluetooth Low Energy mode, in seconds.
subdev_type The sub-device type. Valid value: TAL_BLE_ROLE_E.

Build

You need to install some system tools to build the board support package (BSP). For example, run the following command on Ubuntu.

sudo apt-get install whois patchelf meson bison flex libssl-dev

Follow the steps below to compile the CR3L BLE Long Range firmware on Visual Studio Code.

  1. Expand TuyaOS > apps. Right-click on the demo directory and choose Build Project. Enter a version number and press the Enter key.

    Quick Start

  2. You can see the output in the TERMINAL window. When the TERMINAL displays a message as shown below, it means the build is successful. The build output is stored in the output directory.

    Quick Start

Flash firmware

For firmware details and flashing methods, refer to Flash Firmware.

Run

Run the sample application to see how it behaves.

After flashing, restart the device.

CR3L supports Bluetooth pairing and AP pairing. You can use the Tuya Smart app to activate the gateway. For more information about the app, see User Guide.

Upload firmware

For more information, see Update Firmware.