Help Center> IoT Device Access> Best Practices> Device Access> Connecting a Device Simulator to IoTDA
Updated on 2023-02-02 GMT+08:00

Connecting a Device Simulator to IoTDA

This topic uses a device simulator as an example to describe how to connect devices to IoTDA using the native MQTT protocol. The simulator is an MQTT client that enables you to easily verify whether devices can interact with the platform to publish or subscribe to messages.

Prerequisites

  • You have registered a Huawei Cloud account. If you have not registered, click here to complete the registration.
  • You have subscribed to the IoTDA service. If you have not subscribed to the service, go to the IoTDA service page, and click Access Console to subscribe to the service.

Obtaining Device Access Information

Perform the following procedure to obtain device access information on the IoTDA console:

  1. Visit the IoTDA product page and click Access Console.
  2. In the navigation pane, choose Overview and click Access Details in the Instance Information area to view device access information and record 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

  1. Create an MQTT product. (If an MQTT product already exists, skip this step.)
  2. Log in to the console, choose Products in the navigation pane, and click Create Product in the upper right corner.
  3. Set the parameters as prompted and click OK.

    Basic Information

    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 value. The name can contain letters, numbers, underscores (_), and hyphens (-).

    Protocol

    Select MQTT.

    Data Type

    Select JSON.

    Manufacturer

    Customize the value. The name can contain letters, numbers, underscores (_), and hyphens (-).

    Industry

    Select the industry to which the product model belongs.

    Device Type

    If the product model preset on the platform is used, the device type is automatically matched.

    Advanced Settings

    Product ID

    Set a unique identifier for the product. If this parameter is specified, the platform uses the specified product ID. If this parameter is not specified, the platform allocates a product ID.

    Description

    Provide a description for the product. Set this parameter based on the site requirements.

    Figure 1 Creating a product

Registering a Device

  1. On the management console, choose Devices > All Devices in the navigation pane, and click Individual Register in the upper right corner.
  2. Set the parameters as prompted and click OK.

    Parameter

    Description

    Resource Space

    Ensure that the device and the product created in Creating a Product belong to the same resource space.

    Product

    Select the product created in Creating a Product.

    Node ID

    Customize a unique physical identifier for 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 a secret.

    Figure 2 Registering a device

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

Connecting a Device Simulator to IoTDA

  1. Download the simulator (for 64-bit operating system by default) and start it.

  2. Perform operations on the UI.

    1. On the simulator UI, enter the server address, device ID, and device secret. Set the parameters based on the actual device information.
    2. Use the corresponding certificates together with different server addresses during SSL-encrypted access. Obtain certificates by referring to Obtaining Resources and replace certificates in the certificate folder.

    3. Select SSL encryption or no encryption when establishing a connection on the device side and set the QoS mode to 0 or 1. Currently, QoS 2 is not supported. For details, see Constraints.

  3. Establish a connection.

    To connect a device or gateway to the platform, upload the device information to bind the device or gateway to the platform. Click Connect. If the domain name, device ID, and secret are correct, a device connection success is displayed in the log. Check the device status on IoTDA, as shown in the following figure.

  4. Subscribe to a topic.

    Only devices that subscribe to a specific topic can receive messages about the topic published by the broker. For details on the preset topics, see Topics.

    After the connection is established and a topic is subscribed, the following information is displayed in the log area on the home page of the demo:

  5. Publish a topic.

    Publishing a topic means that a device proactively reports its properties or messages to the platform. For details, see the API Device Reporting Properties.

    The simulator implements the property reporting topic and property reporting.

    After a topic is published, the following information is displayed on the demo page:

    If the reporting is successful, the reported device properties are displayed on the device details page.

  6. Receive a command.

    The simulator can receive commands delivered by the platform. After an MQTT connection is established and a topic is subscribed, you can deliver a command on the device details page of the IoTDA console. After the command is delivered, the MQTT callback receives the command delivered by the platform.

    For example, deliver a command carrying the parameter name smokeDetector: SILENCE and parameter value 50.

    After the synchronous command is delivered, the following information is displayed on the demo page: