Manage topology relationships
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.
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:
| Parameter | Type | Description |
| id | String | The message ID. It must be a string-type number from 0 to 4294967295. Each message ID must be unique for the current device. |
| version | String | The 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.
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. |
| params | List | The request parameters. |
| deviceName | String | The name of the sub-device. |
| productKey | String | The ProductKey of the product to which the sub-device belongs. |
| sign | String | The signature. Signature algorithm:
Signature calculation example: |
| signmethod | String | The signature method. Supported methods include hmacSha1, hmacSha256, hmacMd5, and Sha256. |
| timestamp | String | The timestamp in milliseconds. |
| clientId | String | A local device tag. This parameter is optional. You can set it to a specific productKey&deviceName. |
| method | String | The request method. The value is thing.topo.add. |
Response parameters:
| Parameter | Type | Description |
| id | String | The message ID. It is a string-type number from 0 to 4294967295. Each message ID must be unique for the current device. |
| code | Integer | The result code. 200 indicates success. |
| data | Object | The sub-device information returned on a successful request. For more information about the parameters, see the following data table. |
| Parameter | Type | Description |
| deviceName | String | The device name of the sub-device. |
| productKey | String | The ProductKey of the product to which the sub-device belongs. |
Error messages:
| Error code | Message | Description |
| 460 | request parameter error | The request parameters are invalid. |
| 6402 | topo relation cannot add by self | A device cannot be added as its own sub-device. |
| 401 | request auth error | Signature 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.
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
| Parameter | Type | Description |
| id | String | The message ID. It must be a string-type number from 0 to 4294967295. Each message ID must be unique for the current device. |
| version | String | The 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.
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. |
| params | List | Request parameters. |
| deviceName | String | The sub-device name. |
| productKey | String | The ProductKey of the product to which the sub-device belongs. |
| method | String | The request method. The value is thing.topo.delete. |
Response Parameters:
| Parameter | Type | Description |
| id | String | The message ID. It is a string-type number from 0 to 4294967295. Each message ID must be unique for the current device. |
| code | Integer | The result code. 200 indicates success. |
| data | Object | The sub-device information returned on a successful request. For more information about the parameters, see the following data table. |
| Parameter | Type | Description |
| deviceName | String | The device name of the sub-device. |
| productKey | String | The ProductKey of the product to which the sub-device belongs. |
Error messages:
| Error code | Message | Description |
| 460 | request parameter error | The request parameters are invalid. |
| 6100 | device not found | The 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:
| Parameter | Type | Description |
| id | String | The message ID. It must be a string-type number from 0 to 4294967295. Each message ID must be unique for the current device. |
| version | String | The 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.
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. |
| params | Object | Request parameters. This can be empty. |
| method | String | The request method. The value is thing.topo.get. |
Response parameters:
| Parameter | Type | Description |
| id | String | The message ID. It is a string-type number from 0 to 4294967295. Each message ID must be unique for the current device. |
| code | Integer | The result code. 200 indicates success. |
| data | Object | The response returned for a successful request. |
| deviceName | String | The sub-device name. |
| productKey | String | The 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 code | Message | Description |
| 460 | request parameter error | The 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:
| Parameter | Type | Description |
| id | String | The message ID. It must be a string-type number from 0 to 4294967295. Each message ID must be unique for the current device. |
| version | String | The 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.
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. |
| params | Object | The request parameter can be empty. |
| method | String | The request method. The value is thing.list.found. |
| deviceName | String | The sub-device name. |
| productKey | String | The ProductKey of the product associated with the sub-device. |
Response parameters:
| Parameter | Type | Description |
| id | String | The message ID. It is a string-type number from 0 to 4294967295. Each message ID must be unique for the current device. |
| code | Integer | The result code. 200 indicates success. |
| data | Object | The result returned on a successful request. |
Error messages:
| Error code | Message | Description |
| 460 | request parameter error | The request parameters are invalid. |
| 6250 | product not found | The product of the reported sub-device does not exist. |
| 6280 | devicename not meet specs | The 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:
| Parameter | Type | Description |
| id | String | 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. |
| version | String | The protocol version number. The only valid value is 1.0. |
| params | Object | The request parameter is optional. |
| method | String | The request method. The value is thing.topo.add.notify. |
| deviceName | String | The sub-device name. |
| productKey | String | The ProductKey of the product associated with the sub-device. |
Response parameters:
| Parameter | Type | Description |
| id | String | The message ID. It is a string-type number from 0 to 4294967295. Each message ID must be unique for the current device. |
| code | Integer | The result code. 200 indicates success. |
| data | Object | The 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
| Operation | Behavior | Notification method |
| Add a sub-device to a gateway | Adds the topology relationship between the gateway and the sub-device. | Notifies the gateway. |
| Delete a sub-device | Deletes the topology relationship between the sub-device and the corresponding gateway. | |
| Disable a sub-device | Disables the sub-device and its topology relationship with the corresponding gateway. | |
| Enable a sub-device | Enables 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:
| Parameter | Type | Description |
| id | String | 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. |
| version | String | The protocol version number. The only valid value is 1.0. |
| method | String | The request method. The value is thing.topo.change. |
| params | Object | Request parameters. Includes the status (topology relationship status) and sublist (sub-device list) parameters. |
| status | Integer | The status of the topology relationship.
|
| deviceName | String | The name of the sub-device. |
| productKey | String | The ProductKey of the product to which the sub-device belongs. |
Alink response data format:
{
"id":"123",
"code":200,
"message":"success",
"data":{}
}