Using a Custom Topic for Communication
Scenarios
Custom topics apply to MQTT devices connected to the IoT platform. 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 data based on the properties or 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
- You have registered a HUAWEI CLOUD account.
- You have subscribed to the IoTDA service.
- You have created an MQTT product, developed a product model, and registered a device on the IoTDA console. For details, see Creating a Product, Developing a Product Model, Registering an Individual Device, and Registering a Batch of Devices.
- The connection between the device and platform has been established. For details, see Performing Connection Authentication.
Customizing a Topic
For details, see Custom Topic Communications.
Message Reporting
- Log in to the IoTDA console.
- In the navigation pane, choose , find the corresponding device, and click View to access its details.
- On the Message Trace tab page, click Start Trace.
- In the dialog box displayed, select Device message for Message Type and set Duration as required.
- Use the MQTT.fx simulator to simulate a device to report a custom topic message. For details, see Connecting MQTT Devices.

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.
- On the Message Trace page, view the custom topic messages reported by the device.

- 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.
- 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 Creating a Custom Topic.
- 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.
- Use the Postman to simulate the application to call the API Delivering a Device Message to deliver a command for starting the indoor air conditioner.

- 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.

Last Article: Forwarding Device Data to OBS for Long-Term Storage
Next Article: Device Linkage

Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.