🏆 Join the TuyaOpen AI Hardware Contest! 100 days to build the future of AI devicesLearn More →
Skip to main content

Develop Applications

Create product and get PID

First, create a product on the Tuya Developer Platform and get the product ID (PID). For more information, see TuyaOS > Create Product.

Then, replace the TUYA_PRODUCT_KEY macro in the tuya_config.h file in the project directory with the specific PID.

TuyaOpen license

TuyaOpen Framework includes:

To connect to Tuya IoT Cloud, dedicated TuyaOpen licenses are required. Licenses from other sources will not work for connecting to the Tuya IoT Cloud.

[tuya_main.c:220] Replace the TUYA_DEVICE_UUID and TUYA_DEVICE_AUTHKEY contents, otherwise the demo cannot work
[tuya_main.c:220] uuid uuidxxxxxxxxxxxxxxxx, authkey keyxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

You can obtain a dedicated license through the following methods:

  • Method 1: Purchase a module with the pre-flashed license. This license is permanently written into the module during manufacturing and cannot be lost. TuyaOpen automatically reads the license via the tuya_iot_license_read() interface during startup. Verify whether your purchased modules already contain TuyaOpen licenses.

  • Method 2: If your module does not have a pre-flashed license, purchase a TuyaOpen license on the Production page or the license purchase page. Then, replace the TUYA_DEVICE_UUID and TUYA_DEVICE_AUTHKEY values in the apps/tuya_cloud/switch_demo/src/tuya_config.h file with the obtained UUID and AuthKey. Make sure you select the correct tuya_config.h file based on the actual project being compiled.

License

tuya_iot_license_t license;
if (OPRT_OK != tuya_iot_license_read(&license)) {   license.uuid = TUYA_DEVICE_UUID;
   license.authkey = TUYA_DEVICE_AUTHKEY;
   PR_WARN("Replace the TUYA_DEVICE_UUID and TUYA_DEVICE_AUTHKEY contents, otherwise the demo cannot work");
}

If the tuya_iot_license_read() interface returns OPRT_OK, it indicates that the current device has been pre-flashed with a TuyaOpen license. Otherwise, it means the current module does not contain a pre-flashed TuyaOpen license.

Build and flash

  1. Run the tos config_choice command to select the target development board or platform.
  2. If you need to modify the configuration, run the tos menuconfig command first.
  3. Run tos build to build the project.
  4. Run the tos flash command for flashing.

For more information about tos, see the tos.py User Guide.

Pair and activate the device

On the Tuya app, pair and activate the device in Bluetooth or Wi-Fi access point mode.