All Products
Search
Document Center

IoT Platform:Device simulation

最終更新日:Sep 04, 2023

A device simulator is provided by the device simulation feature of IoT Platform to simulate the connection between a physical device and IoT Platform. You can use the simulator and test data to check the connectivity between devices and IoT Platform and troubleshoot connection-related issues. This topic describes how to simulate a device and connect the simulated device to IoT Platform.

Features

The device simulator allows you to debug the connections between devices and IoT Platform. The following table describes the debugging features.

Feature

Description

Upstream Debug

A device sends messages to IoT Platform in the following scenarios:

  • Use custom topics to submit messages and subscribe to messages

  • Submit properties

  • Submit events

Downstream Debug

IoT Platform sends messages to a device in the following scenarios:

  • Use custom topics to send messages

  • Manage properties, such as querying or modifying properties

  • Call services

Limits

  • You can configure a policy to submit properties and events on a regular basis.

    • If you modify the policy settings multiple times, only the most recent modification takes effect.

    • The minimum interval between consecutive messages is 1 second.

    • The maximum period of time for which consecutive messages can be sent is 3 hours.

  • You cannot use the device simulator for devices whose Data Type parameter is set to Custom.

  • You cannot use the device simulator for physical devices that are online or disabled.

  • After you leave the Device Simulation page, the device simulator is disabled.

  • If you specify custom Message Queuing Telemetry Transport (MQTT) endpoints and certificates for an Exclusive instance, you cannot use the device simulation feature on the instance. For more information about custom certificates, see Create a custom certificate for the MQTT endpoint of the Exclusive instance.

Procedure

  1. Log on to the IoT Platform console.

  2. On the Overview page, select an environment, find the instance that you want to manage, and click the instance ID or instance name.

  3. In the left-side navigation pane, choose Devices > Device Simulation.

  4. Select a product, and then select a device that you want to simulate. On the Device Simulation page, click Start Device Simulation.

  5. In the MQTT Connection Parameters dialog box, select an MQTT protocol version and click OK.

    For more information about MQTT, see MQTT protocol.

    MQTT协议版本
  6. Select a feature and send data to debug the feature. The following table describes the features.

    Upstream Debug

    Custom topics

    • Message Reporting: The device simulator uses a custom topic to send a message to IoT Platform.

      1. Choose Upstream Debug > Topic Category

      2. Select a custom topic to send the message, and configure the Payload Data parameter.

      3. Set the Qos parameter to 0 or 1.

      4. If you set the MQTT Protocol Version parameter to 5.0, you can configure the Retained Message and Message Validity Period (Seconds) parameters.

        Note

        If you set the Qos parameter to 0, the maximum value of the Message Validity Period (Seconds) parameter is 86,400. If you set the Qos parameter to 1, the maximum value of the Message Validity Period (Seconds) parameter is 604,800. If you do not configure the Message Validity Period (Seconds) parameter, the maximum value is used. The maximum value varies based on the value of the Qos parameter.

      5. Click Message Reporting.

    • Message Subscription: The device simulator subscribes to a custom topic to receive a message from IoT Platform.

      1. Choose Upstream DebugTopic Category.

      2. Select a topic for message subscription.

      3. If you set the MQTT Protocol Version parameter to 5.0, you can configure the following parameters.

        • Qos. Valid values: 0 and 1.

        • No Local (Receive Device Messages). Valid values: true and false. The value true specifies that the device does not receive its own messages. The value false specifies that the device receives its own messages.

        • Retain Handling (Send Retained Messages to Device During Subscription). Valid values:

          • 0: If a subscription is configured between the server and a client, the server sends a retained message.

          • 1: If a new subscription is configured between the server and a client, the server sends a retained message.

          • 2: The server does not send a retained message to a client regardless of whether a subscription is configured between the server and the client.

      4. Click Subscribe.

    Property submission

    The device simulator submits a property to IoT Platform.

    1. Choose Upstream Debug Properties.

    2. Select a Thing Specification Language (TSL) module from the Debugging Device drop-down list.

    3. Select or enter a value in a property field. The value must match the data type and value range of the property. You can set a property of the numeric type to a random value. random(a,b) specifies a random value between Integer a and Integer b.

    4. Send the data. Options:

      • Send Command: immediately send the data.

      • Push Policy: configure a messaging policy. Valid values:

        Important

        After the device simulator is disabled, the messaging policy becomes invalid.

        • At Specific Time: The data is sent only once at a specific point in time.

        • At Specific Interval: The data is repeatedly sent at a fixed interval during a specific period of time. The interval is measured in seconds.

    Event submission

    The device simulation feature submits an event to IoT Platform.

    1. Choose Upstream Debug > Events

    2. Select a TSL module from the Debugging Features drop-down list.

    3. Select a feature and enter the event data in the JSON format, such as {"Power": "on"}.

    4. Send the data. Options:

      • Send Command: immediately send the data.

      • Push Policy: configure a messaging policy. Valid values:

        Important

        After the device simulator is disabled, the messaging policy becomes invalid.

        • At Specific Time: The data is sent only once at a specific point in time.

        • At Specific Interval: The data is repeatedly sent at a fixed interval during a specific period of time. The interval is measured in seconds.

    Downstream Debug

    Custom topics

    IoT Platform sends a message to a device by using a custom topic.

    1. Choose Downstream Debug > Topic Category

    2. Select a custom topic to send the message, and configure the Payload Data parameter.

    3. Set the Qos parameter to 0 or 1.

    4. If you set the MQTT Protocol Version to 5.0, you can configure the Retained Message and Message Validity Period (Seconds) parameters.

      Note

      If you set the Qos parameter to 0, the maximum value of the Message Validity Period (Seconds) parameter is 86,400. If you set the Qos parameter to 1, the maximum value of the Message Validity Period (Seconds) parameter is 604,800. If you do not configure the Message Validity Period (Seconds) parameter, the maximum value is used. The maximum value varies based on the value of the Qos parameter.

    5. Click Send Command.

    Property query and configuration

    IoT Platform sends the command to the device simulator to change or query a property value.

    1. Choose Downstream Debug > Property debugging

    2. Enter a value in a property field and click Debugging. Then, click Set. You can set a property of the numeric type to a random value. random(a,b) specifies a random value between Integer a and Integer b.

      Important

      The success message only indicates that the device received the command for changing the property value from IoT Platform. The device may not run the command. After the Link SDK that is used to configure the device responds to the property configuration request, the device must submit the latest property value to prove that the property value is changed.

    3. On the right side of a property field, click Debugging. Then, click Get.

      The latest property value is displayed in the field. If the property value does not exist on the device simulator, no data is displayed.

    Service calls

    1. Choose Downstream Debug > Invoke Service

    2. Select the TSL module and the service from the Debugging Features drop-down list.

Result

After data is pushed, you can view device logs in the Device log section on the right side of the page.

The following figure shows an example.

image.png

Click View Cloud Logs. On the Cloud run log tab, you can view the related IoT Platform logs.

For more information, see IoT Platform logs.

云端运行日志