Gateway Sub-device

Last Updated on : 2024-05-14 08:00:15download

The core capability of a gateway is to manage sub-devices.

This topic describes how to add and delete a sub-device and control the connection status of a sub-device.

Add a sub-device

A gateway is designed to convert communication protocols among different devices and connect the devices without the networking capability as sub-devices to the cloud.
For this purpose, a sub-device can be added to a gateway.

The first section describes how to add a sub-device to a gateway.

Perform the following steps:

Set the gateway to the mode that allows adding a sub-device > Add a sub-device > Set the gateway to the mode that disallows adding a sub-device

Before you request to add the sub-device to the gateway, you must set the module to the mode that allows adding the sub-device. Otherwise, the module will reject the request.

The sub-device can be added to the gateway in the following ways:

  • Use the app
  • Use the microcontroller unit (MCU)

Use the app to add the sub-device

  1. The app sends the request to set the module to the mode that allows adding the sub-device. Then, the module notifies the MCU with the command 0x06 to run in the mode that allows adding the sub-device to the gateway.

  2. In this mode, the MCU receives the sub-device data and sends the command 0x08 to the module.

  3. The module receives the sub-device data including the data point (DP) data and registers the sub-device to the cloud. Thus, the registered sub-device appears on the app.

  4. The module sends the command 0x13 to the MCU to notify the successful registration result. Now, the sub-device is added to the gateway.

  5. The app exits the page of adding the sub-device and notifies the module of this status. The module sends the command 0x07 to disallow adding a sub-device.

    Gateway Sub-device

Use the MCU to add the sub-device

  1. The MCU sends the command 0x1A to set the module to the mode that allows adding the sub-device.
  2. After the module receives the command, it sends the command 0x06 to notify the MCU to run in the mode that allows adding the sub-device.
  3. In this mode, the MCU receives the sub-device data and sends the command 0x08 to the module.
  4. The module receives the sub-device data including the DP data and registers the sub-device to the cloud. Thus, the registered sub-device appears on the app.
  5. The module sends the command 0x13 to the MCU to notify the successful registration result. Now, the sub-device is added to the gateway.
  6. At the time as specified by the command 0x1A in Step 1, the module sends the command 0x07 to notify the MCU to disallow adding a sub-device. You can also use the MCU to proactively send the 0x1A command and notify the module to disallow adding a sub-device. Then, the module sends the 0x07 command and notifies the MCU to disallow adding a sub-device.

Gateway Sub-device

After the MCU sends the command 0x06, if the module stays in the disconnected state, the sub-device cannot be added to the gateway. However, in this case, the module will cache the sub-device data, and after network recovery, resume registration of the sub-device to the cloud.

Delete a sub-device

  • Use the app
    In this method, the app sends the delete command to the module. Then, the module deletes the specified sub-device data and sends the command 0x09 to the MCU. For more information, see the documents on the integration protocols.
  • Use the MCU
    In this method, the MCU proactively sends the command 0x19 and notifies the module to delete the specified sub-device. Then, the module runs the deletion task and returns the result. For more information, see the documents on the integration protocols.

Manage connection status of sub-devices

The gateway can be used to manage the connection status of sub-devices.
In general, the gateway performs heartbeat checks to determine the status of each sub-device. You can also use the MCU to proactively set the connection status of a sub-device.

Manage heartbeat checks

The module performs heartbeat checks to determine the connection status of the connected sub-devices.
After a sub-device is added to the gateway, the module regularly performs heartbeat checks with the command 0x0A to determine the connection status of the sub-device. After the MCU receives the heartbeat check command, if the target sub-device is online, the sub-device returns the required frames. If no response is returned after two consecutive heartbeat checks, the gateway declares the target sub-device as offline.

Status reporting with the command 0x0D refreshes the heartbeat check result. If the sub-device status is frequently reported during two consecutive heartbeat checks, this sub-device will not be declared as offline.

The interval of heartbeat checks depends on the number of target sub-devices. A higher number of sub-devices increases the frequency of heartbeat checks. The following table lists the heartbeat data that varies depending on the different numbers of sub-devices.

Number of devices Interval (seconds) Number of polls The offline duration of the first device (s) The offline duration of the last device (s)
1 5 3 10 10
2 3.333 2 10 13.333
3 2.5 2 10 15
4 2 2 10 16
5 1.667 2 10 16.667
6 1.429 2 10 17.143
7 1.25 2 10 17.5
8 1.111 2 10 17.777
9 1 2 10 18
10 0.909 1
Note: The interval of less than 1s is taken as 1s.
2 10 11
Note: If the number of devices is greater than or equal to 10, the offline duration of the first device is calculated as N+1 seconds.
18.182 20
Note: If the number of devices is greater than or equal to 10, the offline duration of the last device is calculated as 2N seconds.
11 1 2 12 22
32 1 2 33 64
64 1 2 65 128
128 1 2 129 256
N 1 2 N+1 2N

The module proactively sends heartbeat packets only to the sub-device that is set to be a standard power device. This type of device returns "lp":0 in the command 0x0A. If the MCU sets the sub-device as a low power sub-device in the heartbeat check command, the module does not proactively send heartbeat packets to the sub-device. A low power sub-device returns "lp":1 in the command 0x0A. In the latter case, the online sub-device needs to regularly report the heartbeat status with the command 0x0A.
If the sub-device does not send a heartbeat packet or report status with the command 0x0D, the gateway declares the sub-device as offline.

Use the MCU to update sub-device status

In most cases, the MCU is more sensitive to the connection status of a sub-device. If a sub-device gets offline, the module can detect the offline status only after at least two consecutive heartbeat checks. In contrast, the MCU can detect this status within a fewer period. The MCU can also be used to send the command 0x2A and set the sub-device to the online or offline state. For more information, see the documents on integration protocols.

Non-pro gateways allow you to disable heartbeat checks.
If the MCU is used to manage the connection status of the sub-device, the bit7 value can be set to 1 with the product information command 0x01. Then, heartbeat checks are disabled. The MCU can send only the command 0x2A to set the connection status of the sub-device.