Catalog

Docs

Quick Start (application Dimension)

Last Updated on2020-02-21 05:38:08

This guide is designed to help developers quickly understand how to create Apps and control devices through Tuya Cloud Platform to play smart. Let's start the application journey!

Operating procedures

Tuya Smart Global Smart Platform

Become a Developer

Log in to Tuya Smart Development Platform https://iot.tuya.com, unregistered users sign up for a tuya account, and pass the enterprise authentication to become a platform developer. Tuya Smart Global Smart Platform

Apply for cloud API authorization

Tuya Cloud supports third-party clouds to access Tuya Cloud through HTTPS. Before connecting, Tuya Cloud must first apply for cloud API authorization. It can only be used after obtaining the AccessId and AccessKey. After logging in to the platform, click on the user's avatar, enter the "Cloud API Authorization", and click apply. After submitting the application, it will be reviewed within 1-2 working days.

Cloud API Authorization

Follow-up device control depends on AccessId and AccessKey, please keep it safe!

Create OEM App

  • Enter the [App Workbench] section and click Create App Create App

  • Improve App Information

    • App name: The name of the App displayed on the desktop of the phone. The recommended length is 6 Chinese characters or 12 English characters.
    • App package name: As the unique identifier of the App, it is not allowed to be repeated. It is recommended that each paragraph be controlled within 3-20 letters, and only lowercase letters are supported.     Perfect App Information     
  • Configure App

    • App icon settings

      Only supports png format, the size is equal to 1024 * 1024px;     App Icon     

    • App startup map settings     App start map     No special requirements, directly "Next"     
    • App theme color settings     App launch map     No special requirements, directly "Next"     
    • Map positioning settings

      Click Get SHA1 to get App related values, check the help, configure the Map Key according to the operation manual guide, get the corresponding key and fill it in the box. (If the App needs to be on the shelf, this function must be equipped)

    • Network equipment list setting     App launch map     No special requirements, directly "Next"     

    • Apply for build     Build     
    • Build completed, scan code installation     Build     

Prepare Iot devices that can connect to Tuya Cloud

You can purchase Iot devices that can be connected to Tuya Cloud from service providers, such as WiFi sockets and WiFi lighting bulbs.     

Add devices and configure network in App

  • Add device

    There are two ways to add devices in the App: "Manual Add" and "Auto Discovery". Here we choose "Auto Discovery". Build

  • Equipment distribution

    After "auto-discovering" the device, configure the network according to the relevant instructions. - Power on the device

    • Long press the reset button (switch) for 5 seconds

    • Make sure the indicator flashes quickly                Build     

    Wi-Fi socket is used as an example for current network configuration. Different products have different network configurations. Please follow the corresponding network configuration instructions to configure the network.

  • After the device is successfully networked, you can operate the device through the App.

Use Postman to simulate OpenApi to control the device

The App created through the Tuya cloud platform has a built-in Tuya SDK, which can control the device interactively with Tuya cloud platform. Next, we call OpenApi through Postman to simulate the control device.

  • Environmental preparation

    • Meet Postman

      Postman is a powerful Chrome plugin for webpage debugging and sending HTTP requests for webpages.

      Portal: https://www.jianshu.com/p/0c247b351f08         

    • Set up Postman environment

      To be good at work, we must first sharpen our tools. Before we begin, we must prepare the postman and Tuya cloud-related environments. - Download postman: https://www.getpostman.com > Postman version is preferably 7.12.0 and above - Import Tuya Cloud API Interface Package:         Tuya Cloud API Interface          - Import Tuya Cloud API Environment Package:         Tuya Cloud API Environment - Set environment variables - url: Tuya cloud service, taking China as an example: https://openapi.tuyacn.com              - client_id: equivalent to accessId in the developer platform

      - secret: equivalent to accessKey in developer platform
      
      - device_id: device ID, you can check the corresponding information of the device in the App Device ID)
      
      - The schema is the channel identifier of the App application. Please obtain it based on the package name. For example, your App package name is: com.aa.bb, then your schema is: aabb.
      

        Set environment variable          - OpenApi settings        - Request method

        - Supported request methods are as follows:

             - GET - PUT - POST - DELETE              > Please note: When the request method is POST, Content-Type needs to useapplication / json         

    - Request header settings
    
    Any interface needs to add the following parameters to the header:
    
    |   Parameter  | Type | Parameter position | Description | Required |
    | ------------ | ------ | ------ | ---------------------------- | ---- |
    |  client_id  | String | header | client_id | Yes |
    |     sign | String | header | Signature calculated using the specified signature algorithm: token related interface, business related interface | Yes |
    | sign_method | String | header | Signature Digest Algorithm, HMAC-SHA256 | Yes |
    | t | Long | header | 13-bit standard timestamp | Yes |
    | lang | String | header | language, default en | No |

        
- Signature method

Tuya Cloud currently provides two sets of signature algorithms according to different application scenarios:

- Token related interface (v1.0 / token & v1.0 / token / {refresh_token}): sign = HMAC-SHA256 (client_id + t, secret) .toUpperCase ()
        
- Business interface (non-token interface): sign = HMAC-SHA256 (client_id + access_token + t, secret) .toUpperCase ()
  • Postman control equipment in action

    • Add products and network in the App

    Take Wi-Fi socket as an example, refer to the distribution network

    • Get token

      Apply for a token to Tuya Cloud first, and then use this token to request other APIs, otherwise there will be permission problems.         Simple mode token

      grant_type = 1 means use simple mode grant

    • Query the instruction set supported by the device

      Obtain instructions supported by the device, and subsequent control devices can use this result.         Simple mode token         

    • controlling device

      According to the instructions supported by the device, different effects can be achieved by issuing control devices.         Simple mode token