Manage topology relationships

更新时间:
复制 MD 格式

After a sub-device is registered, the gateway must report the topology relationship between the gateway and the sub-device to IoT Platform. This enables the sub-device to go online.

When a sub-device goes online, IoT Platform verifies the sub-device's identity and its topology relationship with the gateway. If all verifications pass, a logical channel for the sub-device is created and attached to the gateway's physical channel. The data communication protocol between the sub-device and IoT Platform is the same as that for directly connected devices. The protocol does not need to expose gateway information.

After a topology relationship is deleted, the sub-device can no longer go online through the gateway. The system reports errors such as "topology relationship does not exist" or "authentication failed".

Add a device topology relationship

A gateway device can use this topic to send an upstream request to add a topology relationship between itself and a sub-device. The response lists the sub-devices for which the topology relationship was successfully added.

Important You can request to add up to 30 sub-devices at a time.

Upstream data.

  • Request topic: /sys/${productKey}/${deviceName}/thing/topo/add
  • Response topic: /sys/${productKey}/${deviceName}/thing/topo/add_reply

Alink request data format:

{
  "id": "123",
  "version": "1.0",
  "sys":{
      "ack":0
  },
  "params": [
    {
      "deviceName": "deviceName1234",
      "productKey": "1234556554",
      "sign": "xxxxxx",
      "signmethod": "hmacSha1",
      "timestamp": "1524448722000",
      "clientId": "xxxxxx"
    }
  ],
  "method": "thing.topo.add"
}

Alink response data format:

{
  "id": "123",
  "code": 200,
  "data": [
    {
      "deviceName": "deviceName1234",
      "productKey": "1234556554"
    }
  ]
}

Request parameters:

ParameterTypeDescription
idStringThe message ID. It must be a string-type number from 0 to 4294967295. Each message ID must be unique for the current device.
versionStringThe protocol version number. The only valid value is 1.0.

sys

Object

Parameters for extended features. It contains fields for different features.

Note

If you use a device-side software development kit (SDK) for development and do not set extended features, this parameter is not included. The related features use default configurations.

ack

Integer

An extended feature field under sys. It specifies whether to return a response.

  • 1: The cloud returns a response.

  • 0: The cloud does not return a response.

Important

For information about how to configure this feature, see Thing Specification Language model usage examples.

If this feature is not configured, this parameter is not included. The cloud returns a response by default.

paramsListThe request parameters.
deviceNameStringThe name of the sub-device.
productKeyStringThe ProductKey of the product to which the sub-device belongs.
signString

The signature.

Signature algorithm:

  1. Sort all parameters submitted to the server (except for sign and signMethod) in alphabetical order. Then, concatenate the parameters and their values without any separators.
  2. Use the algorithm specified by signMethod and the device's DeviceSecret to calculate the signature for the concatenated content.
Signature calculation example:
sign= hmac_md5(deviceSecret, clientId123deviceNametestproductKey123timestamp1524448722000)
signmethodStringThe signature method. Supported methods include hmacSha1, hmacSha256, hmacMd5, and Sha256.
timestampStringThe timestamp in milliseconds.
clientIdStringA local device tag. This parameter is optional. You can set it to a specific productKey&deviceName.
methodStringThe request method. The value is thing.topo.add.

Response parameters:

ParameterTypeDescription
idStringThe message ID. It is a string-type number from 0 to 4294967295. Each message ID must be unique for the current device.
codeIntegerThe result code. 200 indicates success.
dataObjectThe sub-device information returned on a successful request. For more information about the parameters, see the following data table.
Table 1. data
ParameterTypeDescription
deviceNameStringThe device name of the sub-device.
productKeyStringThe ProductKey of the product to which the sub-device belongs.

Error messages:

Error codeMessageDescription
460request parameter errorThe request parameters are invalid.
6402topo relation cannot add by selfA device cannot be added as its own sub-device.
401request auth errorSignature verification failed.

Delete a device topology relationship

A gateway device can use this topic to send an upstream request to delete the topology relationship between itself and a sub-device. The response lists the sub-devices for which the topology relationship was successfully deleted.

Important You can request to delete up to 30 sub-devices at a time.

Upstream data.

  • Request topic: /sys/${productKey}/${deviceName}/thing/topo/delete
  • Response topic: /sys/${productKey}/${deviceName}/thing/topo/delete_reply

Alink request data format:

{
  "id": "123",
  "version": "1.0",
  "sys":{
      "ack":0
  },
  "params": [
    {
      "deviceName": "deviceName1234",
      "productKey": "1234556554"
    }
  ],
  "method": "thing.topo.delete"
}

Data format for Alink responses:

{
  "id": "123",
  "code": 200,
  "data": [
    {
      "deviceName": "deviceName1234",
      "productKey": "1234556554"
    }
  ]
}

Request parameters

ParameterTypeDescription
idStringThe message ID. It must be a string-type number from 0 to 4294967295. Each message ID must be unique for the current device.
versionStringThe protocol version number. The only valid value is 1.0.

sys

Object

Parameters for extended features. It contains fields for different features.

Note

If you use a device-side software development kit (SDK) for development and do not set extended features, this parameter is not included. The related features use default configurations.

ack

Integer

An extended feature field under sys. It specifies whether to return a response.

  • 1: The cloud returns a response.

  • 0: The cloud does not return a response.

Important

For information about how to configure this feature, see Thing Specification Language model usage examples.

If this feature is not configured, this parameter is not included. The cloud returns a response by default.

paramsListRequest parameters.
deviceNameStringThe sub-device name.
productKeyStringThe ProductKey of the product to which the sub-device belongs.
methodStringThe request method. The value is thing.topo.delete.

Response Parameters:

ParameterTypeDescription
idStringThe message ID. It is a string-type number from 0 to 4294967295. Each message ID must be unique for the current device.
codeIntegerThe result code. 200 indicates success.
dataObjectThe sub-device information returned on a successful request. For more information about the parameters, see the following data table.
Table 2. Data
ParameterTypeDescription
deviceNameStringThe device name of the sub-device.
productKeyStringThe ProductKey of the product to which the sub-device belongs.

Error messages:

Error codeMessageDescription
460request parameter errorThe request parameters are invalid.
6100device not foundThe device does not exist.

Get a device topology relationship

Upstream data.

  • Request topic: /sys/${productKey}/${deviceName}/thing/topo/get
  • Response topic: /sys/${productKey}/${deviceName}/thing/topo/get_reply

A gateway device can use this topic to retrieve the topology relationship between itself and its sub-devices.

Alink request data format:

{
  "id": "123",
  "version": "1.0",
  "sys":{
      "ack":0
  },
  "params": {},
  "method": "thing.topo.get"
}

Alink response data format:

{
  "id": "123",
  "code": 200,
  "data": [
    {
      "deviceName": "deviceName1234",
      "productKey": "1234556554"
    }
  ]
}

Request parameters:

ParameterTypeDescription
idStringThe message ID. It must be a string-type number from 0 to 4294967295. Each message ID must be unique for the current device.
versionStringThe protocol version number. The only valid value is 1.0.

sys

Object

Parameters for extended features. It contains fields for different features.

Note

If you use a device-side software development kit (SDK) for development and do not set extended features, this parameter is not included. The related features use default configurations.

ack

Integer

An extended feature field under sys. It specifies whether to return a response.

  • 1: The cloud returns a response.

  • 0: The cloud does not return a response.

Important

For information about how to configure this feature, see Thing Specification Language model usage examples.

If this feature is not configured, this parameter is not included. The cloud returns a response by default.

paramsObjectRequest parameters. This can be empty.
methodStringThe request method. The value is thing.topo.get.

Response parameters:

ParameterTypeDescription
idStringThe message ID. It is a string-type number from 0 to 4294967295. Each message ID must be unique for the current device.
codeIntegerThe result code. 200 indicates success.
dataObjectThe response returned for a successful request.
deviceNameStringThe sub-device name.
productKeyStringThe ProductKey of the product to which the sub-device belongs. This parameter is a field in each object of the data array.

Error messages:

Error codeMessageDescription
460request parameter errorThe request parameters are invalid.

Report a list of discovered devices

Upstream data.

  • Request topic: /sys/${productKey}/${deviceName}/thing/list/found
  • Response topic: /sys/${productKey}/${deviceName}/thing/list/found_reply

In some scenarios, a gateway can discover newly connected sub-devices. After discovery, the gateway must report the information of these sub-devices to the cloud. The information can then be forwarded to a third-party application through data forwarding. The third-party application can then select which sub-devices to connect to the gateway.

Alink request data format:

{
  "id": "123",
  "version": "1.0",
  "sys":{
      "ack":0
  },
  "params": [
    {
      "deviceName": "deviceName1234",
      "productKey": "1234556554"
    }
  ],
  "method": "thing.list.found"
}

Alink response data format:

{
  "id": "123",
  "code": 200,
  "data":{}
}

Request parameters:

ParameterTypeDescription
idStringThe message ID. It must be a string-type number from 0 to 4294967295. Each message ID must be unique for the current device.
versionStringThe protocol version number. The only valid value is 1.0.

sys

Object

Parameters for extended features. It contains fields for different features.

Note

If you use a device-side software development kit (SDK) for development and do not set extended features, this parameter is not included. The related features use default configurations.

ack

Integer

An extended feature field under sys. It specifies whether to return a response.

  • 1: The cloud returns a response.

  • 0: The cloud does not return a response.

Important

For information about how to configure this feature, see Thing Specification Language model usage examples.

If this feature is not configured, this parameter is not included. The cloud returns a response by default.

paramsObjectThe request parameter can be empty.
methodStringThe request method. The value is thing.list.found.
deviceNameStringThe sub-device name.
productKeyStringThe ProductKey of the product associated with the sub-device.

Response parameters:

ParameterTypeDescription
idStringThe message ID. It is a string-type number from 0 to 4294967295. Each message ID must be unique for the current device.
codeIntegerThe result code. 200 indicates success.
dataObjectThe result returned on a successful request.

Error messages:

Error codeMessageDescription
460request parameter errorThe request parameters are invalid.
6250product not foundThe product of the reported sub-device does not exist.
6280devicename not meet specsThe name of the reported sub-device does not meet specifications.

Notify a gateway to add a device topology relationship

Downstream data.

  • Request topic: /sys/${productKey}/${deviceName}/thing/topo/add/notify
  • Response topic: /sys/${productKey}/${deviceName}/thing/topo/add/notify_reply

This topic notifies a gateway device to add a topology relationship for a sub-device. This feature can be used with the feature for reporting a list of discovered devices. You can retrieve the result returned by the device through data forwarding. The data forwarding topic is /${productKey}/${deviceName}/thing/downlink/reply/message.

Alink request data format:

{
  "id": "123",
  "version": "1.0",
  "params": [
    {
      "deviceName": "deviceName1234",
      "productKey": "1234556554"
    }
  ],
  "method": "thing.topo.add.notify"
}

Alink response data format:

{
  "id": "123",
  "code": 200,
  "data": {}
}

Request parameters:

ParameterTypeDescription
idString

The ID of the downstream message. It is generated by IoT Platform and must be a string-type number from 0 to 4294967295. Each message ID must be unique for the current device.

versionStringThe protocol version number. The only valid value is 1.0.
paramsObjectThe request parameter is optional.
methodStringThe request method. The value is thing.topo.add.notify.
deviceNameStringThe sub-device name.
productKeyStringThe ProductKey of the product associated with the sub-device.

Response parameters:

ParameterTypeDescription
idStringThe message ID. It is a string-type number from 0 to 4294967295. Each message ID must be unique for the current device.
codeIntegerThe result code. 200 indicates success.
dataObjectThe result returned on a successful request.

Notify a gateway of a topology relationship change

This topic notifies the gateway about changes in the topology relationship.

Gateway subscription topic: /sys/${productKey}/${deviceName}/thing/topo/change

OperationBehaviorNotification method
Add a sub-device to a gatewayAdds the topology relationship between the gateway and the sub-device.Notifies the gateway.
Delete a sub-deviceDeletes the topology relationship between the sub-device and the corresponding gateway.
Disable a sub-deviceDisables the sub-device and its topology relationship with the corresponding gateway.
Enable a sub-deviceEnables the sub-device and resumes its topology relationship with the corresponding gateway.

Downstream message Alink data format:

{
    "id":"123",
    "version":"1.0",
    "params":{
        "status":0,  // 0: Create, 1: Delete, 2: Resume from disabled, 8: Disable
        "subList":[{
            "productKey":"a1hRrzD****",
            "deviceName":"abcd"
        }]
    }, 
  "method":"thing.topo.change"  
}

Parameters:

ParameterTypeDescription
idString

The ID of the downstream message. It is generated by IoT Platform and must be a string-type number from 0 to 4294967295. Each message ID must be unique for the current device.

versionStringThe protocol version number. The only valid value is 1.0.
methodStringThe request method. The value is thing.topo.change.
paramsObjectRequest parameters. Includes the status (topology relationship status) and sublist (sub-device list) parameters.
statusIntegerThe status of the topology relationship.
  • 0: Create
  • 1: Delete
  • 2: Resume from disabled (enable)
  • 8: Disable
deviceNameStringThe name of the sub-device.
productKeyStringThe ProductKey of the product to which the sub-device belongs.

Alink response data format:

{
    "id":"123",
    "code":200,
    "message":"success",
    "data":{}
}