Last Updated on : 2025-06-09 08:58:35download
This topic describes the directory structure of the development kit, with an explanation of folders and their content.
The directory of the development kit:
├── 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 script for compilation.
│ ├── CHANGELOG.md
│ ├── include # The header file of the SDK.
│ ├── libs # SDK libraries. You can link them as needed.
│ ├── LICENSE # Tuya MIT License
│ ├── Makefile
│ ├── output # The build output.
│ ├── prepare_app.sh
│ ├── README.md
│ ├── scripts
│ ├── tmp
│ └── vendor # The toolchain. When you build a project, the toolchain is automatically downloaded to this directory.
├── T5
│ ├── hardware # Hardware documentation.
│ │ └── T5
│ └── pc
│ └── tools # Development tools.
└── tuya.json
TuyaOS > apps > T5AI_gateway-T5_zg_gw directory:
├── application_components # Source code of custom components.
├── application_drivers
├── bak-build.sh
├── build
├── build.conf
├── default_gpio_config.json
├── fs.bin # File system where temporarily stores the default audio. You can make your own file system.
├── include # The header file.
├── libs
├── local.mk
├── output # The build output.
├── package.json
├── README.md
└── src # The source code.
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": {
"enable_hb": <xxx, number>,
"scan_timeout": <xxx, number>,
"subdev_type": <xxx, number>,
},
},
"user": {
[ { "tp": <DEV_ATTACH_MOD_X, number>, "sw_ver": <version, string> }, ... ]
},
}
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 NVRAM first. If no UUID is found, the UUID specified here is used. For more information about NVRAM, see Flash Full Firmware. |
authkey_key | No | The authorization key. The system reads the authorization key from the NVRAM first. If no authorization key is found, the authorization key specified here is used. For more information about NVRAM, see Flash Full Firmware. |
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). |
storage_path | Yes | The file storage path. The file system must be read/write. |
start_mode | No | The supported Wi-Fi pairing modes:
|
Field | Required | Description |
---|---|---|
storage_path | Yes | The file storage path. The file system must be read/write. |
cache_path | Yes | A temporary directory to store cache files, such as OTA update files. |
dev_name | Yes | The name of the serial port. |
cts | Yes | Specifies whether to enable flow control. Tuya’s NCP has flow control enabled. |
thread_mode | Yes |
|
Follow the steps below to build on Visual Studio Code:
Expand TuyaOS > apps. Right-click on the demo directory and choose Build Project. Enter a version number and press the Enter
key.
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.
Firmware description:
T5AI_gateway-T5_zg_gw_QIO_<version>.bin
: full firmware, used for flashing of the entire chip.T5AI_gateway-T5_zg_gw_UG_<version>.bin
: OTA firmware, used for firmware updates. It can be uploaded to the Tuya Developer Platform for remote OTA updates.Run the sample application to see how it behaves.
You can flash the QIO firmware to the T5 gateway development board. For more information, see Flash Firmware. After flashing, restart the device.
The T5-AI gateway supports Bluetooth and Wi-Fi pairing. You can use the Tuya Smart app to activate the gateway. For more information about the app, see User Guide.
For more information, see Update Firmware.
Use the USB to UART converter to connect the development board, as shown below.
Pin | Description |
---|---|
TX1/RX1 | Log output |
GND | Ground |
Baud rate: 460800
The gateway development board features three buttons.
In the demo provided by Tuya, the functions of KEY1
and KEY2
have been pre-defined. You can modify their functionality by referring to the implementation in the demo.
Key | Description |
---|---|
RST | Power cycling. It cannot be modified. |
KEY1 | User key 1. It has been defined as the voice wake-up key in the demo. |
KEY2 | User key 2. It has been defined as the gateway function key in the demo. Press this key to enable a Zigbee device to join the network, and press and hold it to reset the gateway. |
The code to define the key functions:
The macros to define the keys:
#define GW_RESET_KEY TUYA_GPIO_NUM_43
#define GW_VOICE_KEY TUYA_GPIO_NUM_42
When using the demo provided by Tuya, you must connect P43 to KEY1 and P42 to KEY2 for proper operation.
The gateway development board features one LED bead.
Lighting status | Description |
---|---|
Blinking orange light | The gateway is pairing. |
Steady on blue light | Pairing is completed. |
Blinking blue light | Start pairing over Zigbee. |
Red breathing light | Voice wake-up is in progress. |
In the demo provided by Tuya, the LED functions have been pre-defined. You can modify the functionality by referring to the implementation in the demo.
The code to define the LED functions:
The macros to define the LED:
#define NET_BLED_PORT_PIN TUYA_IO_PIN_32
#define NET_RLED_PORT_PIN TUYA_IO_PIN_34
#define NET_GLED_PORT_PIN TUYA_IO_PIN_36
When using the demo provided by Tuya, you must connect P32 and BLUE, P34 and RED, and P36 and GREEN for proper operation.
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback