Gateway and Gateway Sub-Device Connectivity

Last Updated on : 2024-06-19 09:22:21download

This topic describes how to connect gateways and gateway sub-devices to the Tuya Developer Platform through TuyaLink.

Term

  • Gateway device: refers to devices that can directly connect to the internet and provide a connection between sub-devices on the network and the cloud. A gateway can manage sub-devices, maintain the topological relationships with the sub-devices, and synchronize the topology information to the cloud.
  • Gateway sub-devices: refers to devices that cannot directly connect to the internet. They must connect to a gateway as a sub-device to connect to the cloud.

Process flow

Gateway and Gateway Sub-Device Connectivity

Procedure

Step 1: Create a gateway product

  1. Log in to the Tuya Developer Platform. Click Create.

    Gateway and Gateway Sub-Device Connectivity

  2. On the Standard Category tab, Choose Gateway Control > Gateway. Choose TuyaLink for smart mode.

    Gateway and Gateway Sub-Device Connectivity

  3. Choose Gateway Device for device type. If you choose other options, sub-device management cannot be implemented. For more information, see Product Creation.

    Gateway and Gateway Sub-Device Connectivity

    Add standard functions or create custom functions as needed. For more information, see Function Definition.

Step 2: Create a sub-device product

  1. Log in to the Tuya Developer Platform. Click Create.

    Gateway and Gateway Sub-Device Connectivity

  2. On the Standard Category tab, Choose Gateway Control > Gateway. Choose TuyaLink for smart mode. Choose Gateway Sub-Device for device type.

    Gateway and Gateway Sub-Device Connectivity

    Add standard functions or create custom functions as needed. For more information, see Function Definition.

Step 3: Activate gateway device

You can integrate with the gateway application either through the Tuya MQTT Standard Protocol or the Tuya IoT Core SDK. Before activation, purchase licenses or request free licenses and assign the license to your gateway product. Get the device certificate (including PruductID, DeviceID, and DeviceSecret) after device registration and flash the certificate to your gateway device. Then, the gateway can connect to the internet and come online.

Gateway and Gateway Sub-Device Connectivity

For more information, see Device Management.

Step 4: Gateway activates sub-devices dynamically or manually

This step will connect a sub-device to a gateway device that has been connected to the Tuya Developer Platform. Before activation, purchase licenses or request free licenses and assign the license to your sub-device product. For more information, see License Management.

You have two options for registering and managing sub-devices, namely dynamic registration and manual registration.

Option 1: Dynamic registration

The gateway acts as a proxy to activate and bind sub-devices and manage topology. This frees you from flashing certificates to sub-devices and manual device registration.

When the gateway activates sub-devices, it publishes messages to the topic Gateway Dynamically Registers Sub-devices to pass parameters to sub-devices for activation and registration. One license is consumed for each registered sub-device. Meanwhile, the topological relationship between the sub-device and the gateway is automatically established. By default, the registered sub-device will be bound to the asset or home that the gateway has been bound to. For more information, see Step 5: Usage scenarios.

Parameters Description
clientid Required field. The registration ID, which is unique under one product. It is used for the topological management of devices. You can view the client ID in Device Management > Registration ID.

Option 2: Manual registration

In the Device Management step for the sub-device product, register devices to get sub-device certificates (including ProductID, DeviceID, and DeviceSecret). One license is consumed for each registered sub-device. The gateway imports the deviceid of sub-devices. When sub-devices are connected to the gateway, the gateway calls the sub-device topology to subscribe to the topic so that it can bind to sub-devices. By default, the registered sub-device will be bound to the asset or home that the gateway has been bound to.

After sub-device registration and topology creation are completed, you can view the sub-device list in the Device Management of the gateway product.

Gateway and Gateway Sub-Device Connectivity

To remove a registered sub-device, reset this device or delete it in Device Management. Before deletion, make sure you have unbound the sub-device from the gateway. After deletion, the license that was consumed for this sub-device will be released and available for use.

Step 5: Usage scenarios

To proceed with this step, you must have activated your gateway device and obtained the QR code and bind code from Device Details > QR Code Binding.

Gateway and Gateway Sub-Device Connectivity

In this step, two usage scenarios are provided to illustrate how you can use the connected gateway and sub-devices for IoT projects.

Scenario 1: Cloud development project

Bind gateway devices to a cloud development project for SaaS application and system integration.

The gateway acts as a proxy to activate and register sub-devices. The registered sub-devices are automatically bound to the asset associated with the gateway. You can view these sub-devices on the Smart Industry app or in the Asset of your cloud development project.

Gateway and Gateway Sub-Device Connectivity

For more information about application development and device binding, see Application Development.

Scenario 2: Smart Life app

Bind the gateway to a home by using the Smart Life app. All the sub-devices connected to the gateway are automatically bound to this home.

Gateway and Gateway Sub-Device Connectivity

Then, the gateway and sub-devices can be controlled by using the app.

Next step

See Best Practices.