Quick Start

This topic aims to help developers quickly understand the use process of the Tuya Cloud Development Platform, and immediately open the smart world of the Internet of Everything.

Cloud Development Platform is a set of technical services for Tuya developers. By opening the cloud OpenAPI and device SDK, Cloud Development Platform provides developers with better additional services of hardware devices. An IoT platform with its own characteristics can be developed. At the same time, SaaS developers can also use Tuya’s rich IoT hardware ecosystem to develop a competitive industry SaaS.

Prerequisites

Operation process

It only takes five steps to use the Tuya Cloud Development Platform. The operation process is as follows.

Create a project

  1. Log in to Tuya IoT Console.

  2. Click Cloud Development in the top navigation bar.

  3. On the Cloud Development page, click Create.
    image.png

  4. On the Create Project page, configure the project name, description, and industry.
    image.png

  5. Click Create to complete project creation.

Note: After a project is created, you can view the Authorization Key of the project. The key is the authorization credential to request OpenAPI. Keep it properly.

image.png

Scan QR code to authorize

With Tuya Smart app, scan the QR code and link the devices to your project.

  1. On the Cloud Development > Default Project > Device Management > Linked Device page, click Link devices by App account.

    image.png

  2. On the Link devices by App account page, click Add App Account.

  3. A QR code pops up. You can scan the QR code with Tuya Smart app or OEM app to get the authorization.

    image.png

Unlock development capability

You can apply for OpenAPI permission and subscribe to messages on Cloud Development Platform of Tuya IoT Console.

Simulated call

The app created through the Tuya IoT Console has built-in Tuya SDK, which can interact with the Tuya IoT Console and control the devices. This topic uses Postman as an example to show you how to simulate the device control by calling OpenAPI.

Environmental preparation

Postman is a powerful Chrome plug-in for web page debugging and sending web page HTTP requests. The environment configuration steps related to Postman and Tuya Cloud are as follows.

  1. Click to Download Postman.

    Note: It is recommended to download 7.12.0 and above version.

  2. Import the Tuya Cloud API interface package.

    image.png

  3. Import the Tuya Cloud API environment package.

    image.png

  4. Set environment variables.

    image.png

    Parameter name Description
    url Tuya cloud service, such as https://openapi.tuyacn.com in China.
    client_id The username. It is equivalent to the accessId in the developer platform.
    secret The password. It is equivalent to the accessKey in the developer platform.
    device_id Device ID. You can view the information corresponding to the device in the app.
    schema The channel identifier of the app. Set it according to the app package name. For example, if your app package name is com.aa.bb, then your schema value is aabb.

Note: Click the device you added in the app, and click the pencil icon in the top right corner to view the device ID in the Device information section.

Control the devices through Postman

Take the Wi-Fi socket as an example to show you how to use Postman to control the device. For detailed operation steps, see Wi-Fi paring practice.

  1. Get token
    Get the token through AccessID, and then use this token to request other APIs. Otherwise, there will be permission problems.

    image.png

    Note: grant_type=1 means to use simple mode authorization.

  2. Query command set supported by device

    Get the commands supported by the device. Then, you can control the devices according to the result.

    image.png

  3. Control the device
    According to the commands supported by the device, different effects can be achieved during device control.

    image.png

    Note: See the developer documentation for the usage of other interfaces.

Data statistics

You can view your data statistics in Tuya IoT Console > Cloud Development. Tuya provides a statistical display of two data dimensions.

FAQ

Q: How long is the validity period of the token?

Tuya: The validity period of the token is two hours. You must apply again after the token expires.

Q: What are clientId and secret, and how can I get them?

Tuya: clientId is the AccessId, and the secret is the AccessKey in the Cloud Development Platform.

Q: What is the schema and how can I get it?

Tuya: schema is the channel identifier of the app. You can get it according to the app package name. For example, if your app package name is com.aa.bb, then your schema value is aabb.

Q: What are the data operation permissions in the application scene?

Tuya: In the application scene, the developer has permission to operate the devices in the app.

Q: Why does the platform prompt “permission deny” when getting access to the interface?

Tuya:

  1. Check whether the device has been removed.
  2. Check whether the device is linked with the current developer clientId.

Summary

Through the above simple tutorial, you have a general picture of the capabilities provided by Tuya Cloud OpenAPI. Then, you can code to implement Tuya Cloud API and carry out corresponding business development.

For more interfaces, see the API list. If you have more customization requirements, contact Tuya business personnel.

If you still have questions about the interface calling, you can submit a ticket to ask technical questions and provide interface request parameters.