IoT Platform allows you to simulate devices to facilitate the development and testing of IoT applications.

Background information

The following process describes how to implement an IoT Platform device: You develop a device. The device connects with and reports data to IoT Platform. Then, you can develop applications that are used on IoT Platform. This development process is time-consuming.

IoT Platform provides the device simulation feature that allows you to simulate a device and the connection between the device and IoT Platform. You can use this feature for debugging in the following scenarios:

  • Debug the following topics and procedures in the upstream:
    • Custom topics, including message reporting and message subscription
    • Procedure to report properties
    • Procedure to report events
  • Debug the following topics and procedures in the downstream:
    • Custom topics
    • Procedures that are related to properties, including the procedures that are used to retrieve and set property values
    • Procedure to invoke services

Limits

  • You can set the push policy. If you set the push policy multiple times, only the last settings take effect.
  • The minimum interval for pushing consecutive messages is 1 second.
  • The maximum duration for pushing consecutive messages is 3 hours.
  • The device simulation feature cannot be used to simulate devices that adopt pass-through transmission or devices that transmit data in a custom format.
  • If the selected physical device is online or disabled, you cannot start device simulation. After you leave the Device Simulation page, the simulated device goes offline.

Procedure

  1. Log on to the IoT Platform console.
  2. In the left-side navigation pane, choose Maintenance > Device Simulation.
  3. Select a product and then a device that you want to simulate. On the Device Simulation page, click Start Device Simulation.
  4. Select a debugging scenario and send the command for debugging. The following table describes the debugging scenarios and procedures for debugging.
    Custom upstream topics
    Scenario Procedure
    Debug a custom upstream topic Enable a simulated device to use a custom topic to send IoT Platform a message.
    1. Click the Upstream Debug tab and then the Topic Category tab.
    2. Select a custom topic that is used to report messages, enter payload data, and then set QoS to 0 or 1. Click Message Reporting.
    3. Select a topic that is used for message subscription. Click Subscribe.
    Report property values Enable a simulated device to report property values to IoT Platform.
    1. Click the Upstream Debug tab and then the Properties tab.
    2. Select a module of the Thing Specification Language (TSL) model from the Module 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.
    4. Push the data.

      Available buttons:

      • Send Command: Immediately push the data.
      • Push Policy: Set the push policy. Valid values:
        • At Specific Time: The data is pushed only once at a specified time.
        • At Specific Interval: The data is pushed at a fixed interval during a specified period. The interval is measured in seconds.
    Report events Enable a simulated device to report an event to IoT Platform.
    1. Click the Upstream Debug tab and then the Events tab.
    2. Select a module of the Thing Specification Language (TSL) model from the Module drop-down list.
    3. Select a feature and enter the event data in the JSON format, such as {"Power": "on"}.
    4. Push the data.

      Available buttons:

      • Send Command: Immediately push the data.
      • Push Policy: Set the push policy. Valid values:
        • At Specific Time: The data is pushed only once at a specified time.
        • At Specific Interval: The data is pushed at a fixed interval during a specified period. The interval is measured in seconds.
    Debug a custom downstream topic Enable IoT Platform to use a custom topic to send a simulated device a message.
    1. Click the Downstream Debug tab and then the Topic Category tab.
    2. Select a custom topic, enter payload data, and then set QoS to 0 or 1.
    3. Click Send Command.
    Set and retrieve a property value Enable IoT Platform to send a simulated device a command to set a property value and enable IoT Platform to retrieve a property value.
    1. Click the Downstream Debug tab and then the Property debugging tab.
    2. Select a module of the Thing Specification Language (TSL) model from the Module drop-down list.
    3. Enter a value in a property field and click Debugging. Then, click Set. After the simulated device receives the command, it sets the property to the new value.
    4. On the right side of a property field, click Debugging. Then, click Get.

      Then, the property displays the latest property value. If the data of the property is unavailable on the simulated device, no data is retrieved.

    Invoke a service
    1. Click the Downstream Debug tab and then the Invoke Service tab.
    2. Select a module of the Thing Specification Language (TSL) model from the Module 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 the Device Simulation page.

Device Simulation page

Click View Cloud Logs. You are directed to the Cloud run log tab on which you can view the related IoT Platform logs.

For more information, see IoT Platform logs.

Cloud run log tab