MQTT.fx
This section uses MQTT.fx as an example to describe how to connect devices to the platform using the native MQTT protocol. MQTT.fx is a widely used MQTT client that makes it easy to verify whether devices can interact with the platform to publish or subscribe to messages.
Prerequisites
- You have registered a HUAWEI CLOUD account.
- You have completed real-name authentication on HUAWEI CLOUD.
- You have subscribed to the IoTDA service.
Obtaining Device Access Information
Perform the following procedure to obtain device access information on the IoTDA console:
- Log in to the IoTDA console.
- Click Overview in the navigation pane, view the device access information, and record the domain names and ports.

For devices that cannot be connected to the platform using a domain name, run the ping Domain name command in the CLI to obtain the corresponding IP address. Then you can connect the devices to the platform using the IP address. The IP address is variable and needs to be set using a configuration item.
Creating a Product and Registering a Device
- (Optional) Create a product that uses MQTT. If an MQTT product already exists, skip this step.
- Choose Products in the navigation pane and click in the upper right corner.
- Set the parameters as prompted and click Create.
Set Basic Info
Resource Space
The platform automatically allocates the created product to the default resource space. If you want to allocate the product to another resource space, select the resource space from the drop-down list. If a resource space does not exist, create it first.
Product Name
Customize the product name. The value can contain letters, numbers, underscores (_), and hyphens (-).
Protocol
Select MQTT.
Data Type
Select JSON.
Manufacturer
Customize the manufacturer name. The value can contain letters, numbers, underscores (_), and hyphens (-).
Define Product Model
Product Model
You are advised to use a product model preset on the platform to experience device access.
This section uses WaterMeter as an example. You can also select other product models.
Industry
Select the industry to which the product model belongs.
Device Type
If a product model preset on the platform is used, the device type is automatically matched and does not need to be manually specified.
- Register a device.
- Choose , and click Individual Register in the upper right corner.
- Set the parameters as prompted and click OK.
Parameter
Description
Resource Space
Ensure that the device and the product created in 1 belong to the same resource space.
Product
Select the product created in 1.
Node ID
This parameter specifies the unique physical identifier of the device. The value can be customized and consists of letters and numbers.
Device Name
Customize the device name.
Authentication Type
Select Secret.
Secret
Customize the secret used for device access. If the secret is left blank, the platform automatically generates one.

After the device is registered, the platform automatically generates a device ID and secret. Save the device ID and secret for device access.

Performing Connection Authentication
You can use the MQTT.fx tool to connect devices to the platform by referring to Device Connection Authentication in the API Reference.
- Visit the MQTT.fx website and download and install the latest version of MQTT.fx.
- Go to the IoTDA client ID generator page, enter the device ID and secret generated after registering a device to generate connection information (including ClientId, Username, and Password).

Parameter
Mandatory
Type
Description
ClientId
Yes
String(256)
The value of this parameter consists of a device ID, device type, password signature type, and timestamp, which are separated by underscores (_).
- Device ID: A device ID uniquely identifies a device and is generated when the device is registered with the platform. The value usually consists of a device's product ID and node ID which are separated by an underscore (_).
- Device type: The value is fixed at 0, indicating a device ID.
- Password signature type: The length is 1 byte, and the value can be 0 or 1.
- 0 indicates that the timestamp is not verified using the HMAC-SHA256 algorithm.
- 1 indicates that the timestamp is verified using the HMAC-SHA256 algorithm.
- Timestamp: The UTC time when the device connects to the platform. The format is "YYYYMMDDHH". For example, if the UTC time is 2018/7/24 17:56:20, the timestamp is 2018072417.
Username
Yes
String(256)
Device ID.
Password
Yes
String(256)
Device secret encrypted using the HMAC-SHA256 algorithm based on the timestamp.
The device secret is returned by the platform upon successful device registration.
Each device performs authentication using the MQTT CONNECT message, which must contain all information of the clientId. After receiving a CONNECT message, the platform checks the authentication type and password digest algorithm of the device.
The generated client ID is in the format "Device ID_0_0_Timestamp". By default, the timestamp is not verified.
- If the timestamp is verified using the HMAC-SHA256 algorithm, the platform checks whether the message timestamp is consistent with the platform time and then checks whether the password is correct.
- If the timestamp is not verified using the HMAC-SHA256 algorithm, the timestamp must also be contained in the CONNECT message, but the platform does not check whether the time is correct. In this case, only the password is checked.
If the authentication fails, the platform returns an error message and automatically disconnects the MQTT connections.
- Open the MQTT.fx tool and click the setting icon.

- Configure authentication parameters and click Apply.

Parameter
Description
Broker Address
Enter the device connection address (domain name) obtained from the IoTDA console. If the device cannot be connected using a domain name, enter the IP address obtained in 2.
Broker Port
The default value is 1883.
Client ID
Device ClientId obtained in 2.
User Name
DeviceId obtained in 2.
Password
Encrypted device secret obtained in 2.
If you choose secure access, set Broker Port to 8883, download the certificate, and load the Java certificate in .pem format.

- Click Connect. If the device authentication is successful, the device is displayed online on the platform.

Reporting Data
You can use the MQTT.fx tool to report data to the platform by referring to Reporting Device Properties in the API Reference.
If the device reports data through the MQTT channel, the data needs to be sent to a specific topic in the format $oc/devices/{device_id}/sys/properties/report. For devices that each has a different secret, specify device_id as the device ID returned upon successful device registration.
- Enter the API address in the format of "$oc/devices/{device_id}/sys/properties/report", for example, $oc/devices/5e4e2e92ac-164aefa8fouquan1/sys/properties/report.

- Enter the data to report.
Request parameters
Field
Mandatory
Type
Description
services
Yes
List<ServiceProperty>
Service data list. (For details, see the ServiceProperty structure in the following table.)
ServiceProperty structure
Field
Mandatory
Type
Description
service_id
Yes
String
Service ID.
properties
Yes
Object
Service properties, which are defined in the product model associated with the device.
eventTime
No
String
Indicates the UTC time when the device collects data. The format is yyyyMMddTHHmmssZ, for example, 20161219T114920Z.
If this parameter is not carried in the reported data or is in incorrect format, the time when the platform receives the data is used.
Example request
{ "services": [{ "service_id": "Connectivity", "properties": { "dailyActivityTime": 57 }, "event_time": "20151212T121212Z" }, { "service_id": "Battery", "properties": { "batteryLevel": 80 }, "event_time": "20151212T121212Z" } ] }
- Click Publish. Then you can check whether the device successfully reports data on the platform.

Advanced Experience
After using MQTT.fx to connect a simulated MQTT device to the platform, you may understand how the MQTT device interacts with the platform through open APIs over MQTTS.
To better experience the IoTDA service, develop real-world applications and devices and connect them to the platform. For details, see IoTDA Developer Guide.
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.