Device simulation

更新时间:
复制 MD 格式

IoT Platform provides Device Simulation, a feature that simulates a physical device to connect to IoT Platform. You can use simulated data to test device-to-platform communication and troubleshoot issues.

Features

Device Simulation allows you to debug device communication and offers the following features:

Feature

Description

Upstream debug

A device reports messages to IoT Platform, including:

  • Message reporting and message subscription using custom topics

  • Property submission

  • Event submission

Downstream debug

IoT Platform sends commands to a device, including:

  • Sending messages using custom topics

  • Property debugging (including Get and Set)

  • Service calls

After you start Device Simulation, the simulated device automatically subscribes to basic communication topics and Thing Specification Language (TSL) topics. For more information, see Use message communication topics.

Limitations

  • Device Simulation is not supported for devices in Enterprise Edition instances that use MQTT.

  • Property submission and event submission support push policies.

    • If you configure a push policy multiple times, only the last configuration is retained and executed.

    • The minimum interval for a continuous push is 1 second.

    • The maximum duration for a continuous push is 3 hours.

  • You cannot start Device Simulation for devices whose data type is set to transparent transmission or Custom.

  • You cannot start Device Simulation if the physical device is online or disabled.

  • The device simulator automatically disconnects when you leave the Device Simulation page.

  • If you have configured a custom MQTT certificate and domain name for an Exclusive instance, you cannot use the Device Simulation feature for that instance. For more information about custom certificates, see Customize MQTT access certificates for an Exclusive instance.

Procedure

  1. Log on to the IoT Platform console.

  2. On the Overview page, 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 the target device and click Start Device Simulation.

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

    For more information about the MQTT protocol, see MQTT protocol specifications.

    The available MQTT protocol versions are 3.1.1 and 5.0.

  6. Select a feature type and send debug commands, as described in the following sections.

    Upstream debug

    Custom topics

    • Message Reporting: Use the device simulator to send a custom topic message to IoT Platform.

      1. Choose Upstream Debug > Custom Topics.

      2. Select a custom topic for message reporting and enter the payload.

      3. Set QoS to 0 or 1.

      4. If you use MQTT 5.0, you can set Retained Message and Message Expiry Interval (Seconds).

        Note

        The maximum Message Expiration (seconds) for QoS 0 is 86,400 seconds. The maximum Message Expiration (seconds) for QoS 1 is 604,800 seconds. If you do not set the Message Expiration (seconds), the maximum duration for the corresponding QoS level is used by default.

      5. Click Report Message.

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

      1. Choose Upstream Debug > Custom Topics.

      2. Select a custom topic for message subscription.

      3. If you use MQTT 5.0, you can configure the following parameters:

        • QoS: 0 or 1.

        • No Local (Specifies whether the client receives messages that it publishes): true (do not receive) or false (receive).

        • Retain Handling (Specifies whether to send retained messages upon subscription):

          • 0: The server sends retained messages as long as the client subscription is successful.

          • 1: The server sends retained messages only if the client subscription is new and did not exist before.

          • 2: The server does not send retained messages, even if the client subscription is successful.

      4. Click Subscribe.

    Property submission

    Use the device simulator to send simulated property values to IoT Platform.

    1. Choose Upstream Debug > Property Submission.

    2. Select a TSL Module.

    3. In the input box for a property, select or enter a value that matches the property's data type and value range. For numeric properties, you can set a random number. random(a,b) represents a random integer between a and b.

    4. Send the command.

      • Send Command: Pushes the data immediately.

      • Push Policy: Configures a push policy.

        Important

        The push policy stops executing after you close the device simulator.

        • Scheduled push: Pushes the data once at a configured time.

        • Continuous push: Pushes data at a fixed interval within a configured time period. The interval is measured in seconds.

    Event submission

    Use the device simulator to send simulated events to IoT Platform.

    1. Choose Upstream Debug > Event Submission.

    2. In the Debugging Features section, select a TSL module.

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

    4. Send the command.

      • Send Command: Pushes the data immediately.

      • Push Policy: Configures a push policy.

        Important

        The push policy stops executing after you close the device simulator.

        • Scheduled push: Pushes the data once at a configured time.

        • Continuous push: Pushes data at a fixed interval within a configured time period. The interval is measured in seconds.

    Downstream debug

    Custom topics

    Send custom topic messages from IoT Platform to the device simulator.

    1. Choose Downstream Debug > Custom Topics.

    2. Select a custom topic and enter the payload.

    3. Set QoS to 0 or 1.

    4. If you use MQTT 5.0, you can set Retained Message and Message Expiry Interval (Seconds).

      Note

      The maximum Message expiration time (seconds) for QoS 0 is 86,400 seconds, and the maximum Message expiration time (seconds) for QoS 1 is 604,800 seconds. If the Message expiration time (seconds) is not set, the system uses the maximum duration for the corresponding QoS message by default.

    5. Click Send Command.

    Property debugging

    Set or get property values by sending commands from IoT Platform to the device simulator.

    1. Choose Downstream Debug > Property Debugging.

    2. Enter a value in the property input box, click Debug, and select Set. For numeric properties, you can set a random number. random(a,b) represents a random integer between a and b.

      Important

      A success message indicates only that IoT Platform sent the request, not that the device has executed it. The device confirms the change by reporting the new property value after its SDK responds to the request.

    3. To the right of the property input box, click Debug and select Get.

      The retrieved property value is displayed in the input box. If the device simulator does not have data for this property, the field is empty.

    Service calls

    1. Choose Downstream Debug > Service Calls.

    2. In the Debugging Features section, select the TSL module and the corresponding service.

    3. In the input field, enter the parameters for the service call, and then click Send Command.

      The input parameters must be in a valid JSON format, such as {"Switch":0}.

Result

After you send data, you can view information such as the push policy status, log time, and log content in the Device Log area on the right side of the page.

After a property is submitted, two messages appear in the Device Log: the device-to-cloud message contains the submitted parameters (for example, {"params":{"temperature":10},"method":"thing.event.property.post"}), and the cloud-to-device message returns code:200 and message:success, which indicates that the property submission was successful.

Click View Cloud Logs to go to the Cloud-side Run Log tab, where you can query the run logs.

For more information, see Cloud-side run logs.

FAQ