Help Center> IoT Device Access> Best Practices> Device Access> Using a Custom Topic for Communication
Updated on 2023-11-08 GMT+08:00

Using a Custom Topic for Communication

Scenarios

Custom topics apply to MQTT devices connected to IoTDA. Topics for message reporting and message delivery can be customized. Applications can implement different service logic processing based on topics. Custom topics can also be used in the scenario where a device cannot report properties or receive delivered commands defined in the product model.

In this example, an application receives data reported by a device and determines whether to turn on or off the indoor air conditioner.

Prerequisites

Customizing a Topic

For details, see Custom Topic Communications.

Message Reporting

  1. Visit the IoTDA product page and click Access Console.
  2. In the navigation pane, choose Devices > All Devices, find the corresponding device, and click View to access its details.
  3. Click the Message Trace tab, click Start Trace, and set the trace duration as required.
  4. Use the MQTT.fx simulator to simulate a device to report a custom topic message. For details, see Quick Device Access.

    For devices connected using the IoT Device SDK or native MQTT protocol, you need to set the custom topic name reported by the device in the device program.

  5. On the Message Trace page, view the custom topic messages reported by the device.

  6. An application obtains the custom topic message reported by the device through data forwarding. For details, see Data Forwarding. You can also refer to Forwarding Device Data to OBS for Long-Term Storage.

Message Delivery

In this example, the Postman is used to deliver an instruction for starting the indoor air conditioner.

  1. Use the MQTT.fx simulator to subscribe to a custom topic.

    • Ensure that the device operation permissions contain the subscription function when you create a custom topic. For details, see Custom Topic Communications.
    • For devices connected using the IoT Device SDK or native MQTT protocol, you need to set the name of the custom topic to which the device subscribes in the device program.
  2. Use the Postman to simulate the application to call the API Delivering a Message to a Device to deliver a command for starting the indoor air conditioner.

  3. Call the API Querying Device Messages to check whether the command is delivered. If the command is delivered, the indoor air conditioner will be started.