Manage Devices on Tuya Edge Gateway

Last Updated on : 2024-06-20 07:04:06download

This topic describes how to create a smart product on the Tuya Developer Platform and add a product and a sub-device to Tuya Edge Gateway (TEdge).

Create a sub-device

  1. Log in to the Tuya Developer Platform.

  2. In the left-side navigation pane, choose Product > Development and click Create. On the Standard Category tab, choose Electrical > Socket. You can also select another category.

  3. Click the Custom Solution tab and select Plug.

  4. Enter the product name, keep the default settings of Protocol and Power Type, and then click Create.

    Manage Devices on Tuya Edge Gateway

  5. In the dialog box that appears, select the required data points (DPs). In this example, Switch 1 and Countdown 1 are selected.

    Manage Devices on Tuya Edge Gateway

  6. After you create the product, the product ID (PID) appears in the product details section. Save the PID for later use.

    Manage Devices on Tuya Edge Gateway

Manage sub-devices on Tuya Edge Gateway

Add a product

  1. Add the socket product to Tuya Edge Gateway: Visit the URL http://localhost:3000. In the left-side navigation pane of Tuya Edge Gateway, choose Devices > Products and click Add.

    Manage Devices on Tuya Edge Gateway

  2. Enter the details of the product that is newly created on the platform.

    • PID: Copy the saved PID and paste it to this field.
    • Name: Enter a preferred product name such as My Socket.
    • Description: Enter the product description.
    • Driver Library: Select a driver library. Fuzzy matching is supported. For example, to support the Modbus protocol, enter the keyword modbus and select the driver that appears.

Add DPs to the product

Go back to the deployed edge gateway. In the left-side navigation pane, choose Devices > Products. Click DP for the newly added product and click Create. The created DPs must be the same as those specified on the platform.

Manage Devices on Tuya Edge Gateway

The DPs on the platform can vary based on different types of products. You can specify the required DPs. The following figure shows the DPs that are specified on the platform. These DPs must be added to the same product on the edge gateway.

Manage Devices on Tuya Edge Gateway

In this example, the following DPs are added:

  • Switch 1
    Manage Devices on Tuya Edge Gateway
  • Countdown 1
    Manage Devices on Tuya Edge Gateway

Add a sub-device

Create a sub-device: In the left-side navigation pane of Tuya Edge Gateway, choose Devices > Sub-devices and click Add Sub-device.

Manage Devices on Tuya Edge Gateway

In the dialog box that appears, to add a Modbus sub-device, perform the following steps:

  • Search the newly created socket by name in the Product Type field. Fuzzy matching is supported.

  • Select Modbus from the Driver Instance drop-down list that is automatically loaded after you select a product type.

  • Select the protocol type modbus-tcp.

  • In the IP Address field, enter the Docker IP address of the simulated Modbus device. This IP address is generated by the Modbus device simulator that is described in Manage Devices on Tuya Edge Gateway.

  • Set Port to 1502.

  • Set UnitID to the address of the simulated Modbus device.

  • After the sub-device is added, click Activate Online to activate the sub-device on the platform.

Run a device simulator

Start the Modbus device simulator

  1. Pull and install the modbus-simulator image.
    docker run --name "modbus-simulator" --restart=always \
    -p 1502:1502 \
    -d tuya/tedge-simulator-modbus:latest
    
  2. Get the IP address of the simulated device Docker.
    # Get the IP address of the simulated device Docker.
    docker inspect --format '{{ .NetworkSettings.IPAddress }}' The image ID.