Link IoT Edge provides various features such as scene orchestration, function compute,
and streaming data analysis to help you create IoT applications. Link IoT Edge also
provides device simulators. It allows you to test applications without using physical
devices that may not be available.
A device simulator consists of the following two components:
- Driver: simulates all types of devices at the edge. The properties, events, services
of devices are defined by TSL.
- Control tool: changes the property values of the device simulator and triggers the
device simulator to submit events.
By performing the following operations, you can test applications without using physical
devices: 1. Bind devices with device simulator drivers. 2. Assign the devices to the
edge instance. 3. Use control tools to control the devices. The following sections
describe how to use device simulators.
Use a device simulator driver
- Upload the driver.
- In the left-side navigation pane of the IoT Platform console, choose .
- On the Drivers page, click the Custom Drivers tab. Click Create Driver.
- On the Create Driver page, configure the driver parameters and upload the driver file that you downloaded
in Prerequisites. For more information about how to create a driver, see Publish drivers to the cloud.
The following figure shows the parameters to be configured in this example. You can
specify values for other parameters based on your needs or leave parameters empty.
For more information about how to specify parameters, see
Publish drivers to the cloud.
- Configure the parameters, upload the driver file, and click OK. You can view the new driver in the driver list.
- Assign the driver to the edge instance.
- In the left-side navigation pane, choose . Find the edge instance that is created in Prerequisites and click View in the Actions column.
- On the Instance Details page, click the Devices & Drivers tab. In the All Drivers section, click the
+
icon. In the dialog box that appears, select Custom Drivers. Find the DeviceSimulator driver that is created in the previous step and click Assign.
- Optional. If you have created a Link IoT Edge Pro Edition edge instance, you must configure container parameters.
Select the
DeviceSimulator driver. Click
Container Configurations next to
Device List. Configure the parameters and click
Save.
The following table describes the parameters of a port mapping. For more information
about parameters, see Sample drivers.
Table 1. Parameters
Parameter |
Description |
Host Port |
Specifies a host port to which a container port is mapped. You must specify a host
port that is not being used. Example: 8999.
|
Container Port |
You can only specify 9000 for this parameter. |
Type |
Select TCP.
|
- Add a sub-device to the edge instance.
- In the All Drivers section, select DeviceSimulator. Click Assign Sub-device.
- In the Assign Sub-device dialog box that appears, click Add Sub-device.
- In the Add Device dialog box that appears, click Create Product.
- In the Create Product dialog box, click Complete.
- In the Add Device dialog box, click Configure to add TSL definitions.
- Go to the Add Device dialog box, specify the DeviceName parameter, and click OK.
- In the Assign Sub-device dialog box, select the temperatureSensor product. Find temperatureSensor01 and click Assign.
- Deploy the edge instance.
On the Instance Details page, click Deploy in the upper-right corner. In the Deployment Process dialog box that appears, you can click View Logs to view deployment details. If the edge instance is deployed, the following state
is displayed next to the instance name: Deployed.
Use the control tool of the device simulator
The control tool of the device simulator is similar to buttons of a physical device.
After performing the preceding steps in the Use a device simulator driver topic, you can use the control tool.
- Log on to your remote terminal. For more information about how to log on to a remote
terminal, see Remote service access.
- Optional. If you are using Link IoT Edge Pro Edition, you must run the following command
on the remote terminal to modify the configurations of the control tool.
echo Host_IP_Address:Host_Port > /linkedge/run/ds_ctrl.conf
Note Host IP Address specifies the host IP address of your edge gateway.
Host Port specifies the host port that is specified in
step 2 of the
Use a device simulator driver topic. In this example, port 8999 is specified.
- Use the control tool to control device behaviors.
Go to the
/linkedge/gateway/build/bin directory, and run the
./ds_ctrl
command to view the syntax.
Usage: ds_ctrl <command>
where <command> is one of:
property, event
ds_ctrl property productKey deviceName params Change property
ds_ctrl event productKey deviceName eventCode params Trigger event
For example(productKey = xxx, deviceName = yyy):
ds_ctrl property xxx yyy '{"temperature":30}'
ds_ctrl event xxx yyy alarm '{"temperature":90}'
- Change a device property
- Change the temperature.
Use the tool to change the sensor temperature to 30.
./ds_ctrl property a1WuxHr**** temperatureSensor01 '{"temperature":30}'
The system returns the following message, indicating that the temperature is changed.
Send property success!
- In the left-side navigation pane of the IoT Platform console, choose . Find the required device and click View in the Actions column.
On the Device Details page, click the tab to view the running status of the device.
- Optional. Simulate multiple temperature changes.
Run the following command five times, and add the value by 1 each time.
./ds_ctrl property a1WuxHr**** temperatureSensor01 '{"temperature":31}'
You can go to the tab to view data changes.
- Trigger a device event
- Submit an event if the temperature reaches a specified value.
./ds_ctrl event a1WuxHr**** temperatureSensor01 high_temperature '{"temperature":90}'
- In the left-side navigation pane of the IoT Platform console, choose . Find the required device and click View in the Actions column.
On the Device Details page, click the tab to view the event details.
Online device debugging
- In the left-side navigation pane of the IoT Platform console, choose . On the Online Debug page, select the required product and device.
- Retrieve device properties.
After specifying the Debug Feature and Method parameters, click
Dispatch Command. The current temperature 35 is displayed in the editor.
- Change device properties.
Change the temperature to 40 and click
Dispatch Command. Go to the Status tab to view the device temperature. The temperature is changed
to 40.
- If you debug user-defined device services, the system will print the relevant information
to driver logs and return the following message:
{"code":0,"message":"success"}