Develop Projects on Assets, Users and App

Last Updated on : 2024-06-20 07:00:12download

With custom development solutions in the cloud development section of Tuya Developer Platform, you can build projects for most industry scenarios in which assets and users can be managed. You can create multiple applications for a custom development project to share the assets and users. This topic describes how to create a cloud development project with custom development methods. In the following example, a smart office project is created.

Operation purpose

In the cloud development section of Tuya Developer Platform, simulate the remote management of smart lights on the first floor of Building A of East Lake Square. For example, turn on and off the smart lights and switch the working modes.

Procedure

Cloud development projects support a variety of ways to link devices. This topic describes the whole process of project creation, taking Link Devices by Android App for example. The following figure shows the procedure.

Develop Projects on Assets, Users and App

Create a project

  1. Log in to the platform.

  2. In the left-side navigation bar, choose Cloud > Development.

  3. On the Cloud Management page, click Create Cloud Project.

    Develop Projects on Assets, Users and App

  4. On the Create Cloud Project window, configure Project Name, Description, Industry, Development Method, and Data Center. From the Development Method drop-down list, select Custom.

    Tuya has deployed six data centers around the world to provide more stable cloud services. You can select one or more desired zones, which can be modified later in your project management.

    Develop Projects on Assets, Users and App
  5. Click Create to continue with project configuration.

  6. On the page of Authorize API Services, add Device OTA Update and Industry Project Client Service, and click Authorize.

    Develop Projects on Assets, Users and App

    The IoT Core and Authorization API services have been selected by default.

  7. Enter the asset and account information. Then, the asset will be automatically created and the account will be granted access to the asset. In this example, East Lake Square is set as the asset name.

    For more information about assets, see Manage Assets.

    Develop Projects on Assets, Users and App
  8. Click Create.

Create an Android app

  1. Download the Sample project to a local directory.

  2. Generate your own keyStore file for Sample and note down the file password. Take the following steps:

    Currently, the extension of the generated file is .jks, instead of the previous .keyStore.

    1. Import the Sample file through Android Studio.
    2. Click Build. Develop Projects on Assets, Users and App
    3. Select Generate Signed Bundle / APK from the drop-down list.
    4. Select APK and follow the prompts to create a keyStore file.
    5. According to the keyStore file, configure signingConfigs in the build.gradle of the project. In storeFile, set the storage location of .jks. Develop Projects on Assets, Users and App
  3. Run the following command in the .jks storage path to filter the generated .jks files.

    keytool -list -v -keystore  xx.jks
    {Enter a password}
    
  4. Get the value of SHA1 key in the file.

    Valid from Tue Mar 16 10:22:14 CST 2021 to Sun Mar 06 10:22:14 CST 2061
    Certificate fingerprint:
    MD5: 6B:8C:94:15:35:7C:2E:E8:6E:76:7F:8C:F9:4B:05:BC
    SHA1: 8F:AC:5D:50:65:22:C2:2A:E4:96:3D:8F:9E:DC:5B:43:11:49:55:B1
    SHA256: 0B:98:89:D8:D5:FC:B1:23:9A:76:B1:2B:8F:4C:5E:24:BF:E7:60:E8:FF:EF:E9:40: 48:14:60:D3:62:00:5C:5F
    Signature algorithm name: SHA256withRSA
    Subject public key algorithm: 2048-bit RSA key
    Version: 3
    
  5. Get the package name. You can customize the package name.

    Develop Projects on Assets, Users and App
  6. Create an application.

    1. In the left-side navigation pane of the platform, choose Cloud > Development > My Cloud Projects, and click a project.

    2. In the top navigation bar, choose Authorization > App Authorization and click Add Authorization.

      Develop Projects on Assets, Users and App

    3. In the Add Authorization window, complete the required information.

      • Authorization Type: Tuya Smart App SDK (Android).
      • SHA1: See the SHA1 key in the .jks file.
      • Application ID: the package name, for example, com.tuya.iotapp.sample.
      • Authorization Name: custom.
      • Description: custom.
        Develop Projects on Assets, Users and App
  7. Choose Authorization > App Authorization, and on the page that appears, get the values of Client ID and Client Secret of the created Andriod application.
    Develop Projects on Assets, Users and App

  8. Copy them to the location of the BaseApplication.java file in the Sample code, as shown in the figure below.
    Develop Projects on Assets, Users and App

Add a device

For example, add a smart strip light.

Prerequisites

  • The device runs in the access point (AP) pairing status. Turn on and off the light three times, and the light will flicker quickly. Turn on and off the light another three times, and the light will flicker slowly and enter the AP pairing mode.
  • Your mobile phone and the light are connected to the same Wi-Fi network.
  1. Create assets.
    Building A of East Lake Square where the smart device is located has two floors. The process of building the asset structure is as follows.

    1. Click Assets in the top navigation bar.

    2. In the Asset Structure section, click + Add Asset to add East Lake Square and build the specific asset structure.

      Develop Projects on Assets, Users and App

  2. Run the Sample file through Android Studio.

  3. Select the time zone, enter the username and password of the app account, and log in to the app.

  4. On the Devices page of the East Lake Square/Building A/Floor 1 node, click AP Pairing and follow the prompts to add the device.

  5. After the device is added refresh the page to view it.

  6. On the Devices page of the East Lake Square/Building A/Floor 1 node, view the synced device and note down the device ID.

    The device ID is required for subsequent API requests.

    Develop Projects on Assets, Users and App

Control devices

After you add the device to the platform, you can call API operations to remotely turn on and off the light, and switch the working mode. On the API Explorer page, you can make an API request to control the devices.

  1. Choose Cloud > API Explorer.

  2. In the left-side navigation pane, choose General Devices Control > Send Commands.

    Develop Projects on Assets, Users and App

  3. Enter device_id and commands to implement different operations.

    For more information about control instructions of lights, see Standard Instruction Set.

    • Turn on the light

      {
        "code": "switch_led",
        "value": true
      }
      

    • Enable colored working mode

          {
              "code":"work_mode",
              "value":"colour"
          }
      

    • Enable gradient mode

      {
          "code":"flash_scene_1",
          "value":{
              "bright":100,
              "frequency":76,
              "hsv":[
                  {
                      "h":210.0,
                      "s":169.0,
                      "v":146.0
                  }
              ],
              "temperature":84
          }
      }
      

    • Turn off the light

      {
        "code": "switch_led",
        "value": false
      }