English
English
简体中文
Contact Us
Register
Log In
layoutIndex
Tuya IoT Development PlatformCloud DevelopmentBest PracticeDevelop IoT Projects on Assets, Users and App

Develop IoT Projects on Assets, Users and App

Last Updated on : 2022-01-04 07:21:36download

With custom development solutions on the Tuya IoT Development Platform, you can build IoT 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

On the Tuya IoT Development Platform, simulate the remote management of smart lights on the first floor of Building A of the East Lake Square. For example, turn on and off the smart lights and switch the working modes.

Procedure

The 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 IoT Projects on Assets, Users and App

Create a project

  1. Log in to the Platform.

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

  3. On the page that appears, click Create.

  4. On the Create Project page, configure Project Name, Description, Industry, Development Method, and Availability Zone. From the drop-down list of Development Method, select Custom Development.

    Note: Tuya has deployed six data centers around the world to provide more stable IoT cloud services. You can select one or multiple desired zones, which can be modified in the future.

    Develop IoT Projects on Assets, Users and App
  5. Click Create to complete project creation.

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

    Develop IoT Projects on Assets, Users and App

    Note: IoT Core and Authorization API products have been selected by default.

  7. Enter the asset and account information, and the asset will be automatically created and authorized to the account. In this example, the East Lake Building is set as the asset name.

    Note: For more information about assets, see Manage Assets.

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

Create an Android app

  1. Download the Sample project to the local.

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

    Note: Currently, the suffix of the generated file is .jks, instead of the previous .keyStore.

    1. Import the Sample file through Android Studio.

    2. Click Build.
      Develop IoT Projects on Assets, Users and App

    3. Select Generate Signed Bundle / APK from the drop-down box.

    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 IoT 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 IoT Projects on Assets, Users and App
  6. Create an application.

    1. In the left-side navigation pane of the Tuya IoT Platform, choose Cloud > Projects > My Project, and click a project.
    2. In the top navigation bar, choose Applications > App > Add Application.
      Develop IoT Projects on Assets, Users and App
    3. In the Add Application window, configure the application information.
      • Application Type: Tuya IoT SDK (Android).
      • SHA1: See the SHA1 key in the .jks file.
      • Application ID: the package name, for example, com.tuya.iotapp.sample.
      • Application Name: custom.
      • Description: custom.
        Develop IoT Projects on Assets, Users and App
  7. Choose Applications > App, and on the page that appears, get the values of Client ID and Client Secret of the created Andriod application.

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

    Develop IoT Projects on Assets, Users and App

Add a device

For example, add a white and colored light (RGBW).

Prerequisites

  • The device is in the access point (AP) pairing status. Turn on and off the light for three times, and the light will flicker quickly. Turn on and off the light for 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.
    The East Lake Square where the smart device is located is divided into Building A and Building B, with one floor and two floors respectively. The process of building the asset structure is as follows.

    1. Click Assets in the top navigation bar.
    2. In the Action column of the created asset, click Manage.
      Develop IoT Projects on Assets, Users and App
    3. Build the specific asset structure in the Asset Structure section. Develop IoT 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/F1 node, click AP Pairing and follow the prompts to add devices.

  5. After adding, refresh the page to view the added device.

  6. On the Devices page of the East Lake Square/Building A/F1 node on the Tuya IoT Platform, view the synced device and note down the Device ID.

    Note: The device ID is required for subsequent API requests.

    Develop IoT Projects on Assets, Users and App

Control a device

After you add the device, 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. Click Cloud > API Explorer.

  2. From the drop-down list of subscribed APIs, select IoT Core.

    Develop IoT Projects on Assets, Users and App

  3. On the API Explorer page, call the Send commands API, enter device_id and commands to implement different operations.

    Note: For more information, 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
    }