
# Topic定义
设备使用MQTT协议接入平台时，平台和设备通过Topic进行通信。平台预置的topic列表如下：
| Topic分类                                                                                                                                       | Topic                                                                       | Publisher(发布者) | Subscriber(订阅者) | 用途                                                                                                                                                                                                                             |
|:---|:---|:---|:---|:---|
| 设备消息相关Topic  | $oc/devices/{device_id}/sys/messages/up                                     | 设备             | 平台              | [设备消息上报](https://support.huaweicloud.com/devg-ocsmartcampus/ocsmartcampus_04_0034.html)                                                                                                                                        |
| 设备消息相关Topic  | $oc/devices/{device_id}/sys/messages/down                                   | 平台             | 设备              | [平台下发消息](https://support.huaweicloud.com/devg-ocsmartcampus/ocsmartcampus_04_0035.html)                                                                                                                                        |
| 设备命令相关Topic                                                                                                                                   | $oc/devices/{device_id}/sys/commands/request_id={request_id}                | 平台             | 设备              | [平台下发命令](https://support.huaweicloud.com/devg-ocsmartcampus/ocsmartcampus_04_0032.html)                                                                                                                                        |
| 设备命令相关Topic                                                                                                                                   | $oc/devices/{device_id}/sys/commands/response/request_id={request_id}       | 设备             | 平台              | [设备返回命令响应](https://support.huaweicloud.com/devg-ocsmartcampus/ocsmartcampus_04_0032.html#ocsmartcampus_04_0032__zh-cn_topic_0000002069345277_zh-cn_topic_0000001426695400_zh-cn_topic_0208194431_section98871406444)           |
| 设备属性相关Topic                                                                                                                                   | $oc/devices/{device_id}/sys/properties/report                               | 设备             | 平台              | [设备上报属性](https://support.huaweicloud.com/devg-ocsmartcampus/ocsmartcampus_04_0037.html)                                                                                                                                        |
| 设备属性相关Topic                                                                                                                                   | $oc/devices/{device_id}/sys/gateway/sub_devices/properties/report           | 设备             | 平台              | [网关批量上报属性](https://support.huaweicloud.com/devg-ocsmartcampus/ocsmartcampus_04_0038.html)                                                                                                                                      |
| 设备属性相关Topic                                                                                                                                   | $oc/devices/{device_id}/sys/properties/set/request_id={request_id}          | 平台             | 设备              | [平台设置设备属性](https://support.huaweicloud.com/devg-ocsmartcampus/ocsmartcampus_04_0039.html)                                                                                                                                      |
| 设备属性相关Topic                                                                                                                                   | $oc/devices/{device_id}/sys/properties/set/response/request_id={request_id} | 设备             | 平台              | [属性设置的响应结果](https://support.huaweicloud.com/devg-ocsmartcampus/ocsmartcampus_04_0039.html#ocsmartcampus_04_0039__zh-cn_topic_0000002033304310_zh-cn_topic_0000001476455145_zh-cn_topic_0208194429_section98871406444)          |
| 设备属性相关Topic                                                                                                                                   | $oc/devices/{device_id}/sys/properties/get/request_id={request_id}          | 平台             | 设备              | [平台查询设备属性](https://support.huaweicloud.com/devg-ocsmartcampus/ocsmartcampus_04_0040.html)                                                                                                                                      |
| 设备属性相关Topic                                                                                                                                   | $oc/devices/{device_id}/sys/properties/get/response/request_id={request_id} | 设备             | 平台              | [属性查询响应结果](https://support.huaweicloud.com/devg-ocsmartcampus/ocsmartcampus_04_0040.html#ocsmartcampus_04_0040__zh-cn_topic_0000002069345285_zh-cn_topic_0000001476614913_zh-cn_topic_0208194430_section98871406444)           |
| 设备属性相关Topic                                                                                                                                   | $oc/devices/{device_id}/sys/shadow/get/request_id={request_id}              | 设备             | 平台              | [设备侧主动获取平台的设备影子数据](https://support.huaweicloud.com/devg-ocsmartcampus/ocsmartcampus_04_0041.html)                                                                                                                              |
| 设备属性相关Topic                                                                                                                                   | $oc/devices/{device_id}/sys/shadow/get/response/request_id={request_id}     | 平台             | 设备              | [设备侧主动获取平台设备影子数据的响应](https://support.huaweicloud.com/devg-ocsmartcampus/ocsmartcampus_04_0041.html#ocsmartcampus_04_0041__zh-cn_topic_0000002069223925_zh-cn_topic_0000001426536156_zh-cn_topic_0208194428_section98871406444) |
| 设备事件相关Topic                                                                                                                                   | $oc/devices/{device_id}/sys/events/up                                       | 设备             | 平台              | 设备事件上报与平台事件下发，可用于：[设备网关管理、软固件升级、文件上传/下载、设备时间同步、设备信息上报、设备日志收集、远程配置](https://support.huaweicloud.com/devg-ocsmartcampus/ocsmartcampus_04_0042.html)                                                                              |
| 设备事件相关Topic                                                                                                                                   | $oc/devices/{device_id}/sys/events/down                                     | 平台             | 设备              | 设备事件上报与平台事件下发，可用于：[设备网关管理、软固件升级、文件上传/下载、设备时间同步、设备信息上报、设备日志收集、远程配置](https://support.huaweicloud.com/devg-ocsmartcampus/ocsmartcampus_04_0042.html)                                                                              |
   
![](https://support.huaweicloud.com/devg-ocsmartcampus/public_sys-resources/note_3.0-zh-cn.png)
- {device_id}用于标识Topic路由的目标设备，设备侧订阅该topic或往topic推送消息时，该值需要替换为设备与平台建立MQTT连接时使用的设备ID参数值。
- {request_id}用于唯一标识这次请求。设备侧发起的消息带该参数时，需要保证设备侧该参数值的唯一性，可以用递增的数字或者UUID来实现。当设备收到平台下发的topic中包含request_id时，设备侧响应的request_id需要跟平台下发的保持一致。
- 设备侧订阅带{request_id}参数的topic时，可以使用通配#。如设备侧订阅命令下发请求的topic $oc/devices/{device_id}/sys/commands/request_id={request_id}时，可以用$oc/devices/{device_id}/sys/commands/#。
- 平台采用了隐式订阅的功能，对于下行的系统topic，设备无需订阅，平台默认该设备订阅了qos为0的系统topic。如果需要qos为1的下行系统topic，需要设备自行订阅。
- 除了device_id、request_id其他均为系统字段。
 
