Developing a Product on the Console
This topic uses a smart street lamp as an example to describe how to use the device and application simulators provided by the IoTDA console to experience data reporting and command delivery.
In this topic, it is assumed that a street lamp reports a data message carrying the light intensity (light_intensity) and status (light_status). The data message is in binary format. The command (SWITCH_LIGHT) can be used to remotely control the street lamp switch status.
Prerequisites
- You have registered a HUAWEI CLOUD account.
- You have subscribed to the IoTDA service.
(Optional) Creating a Resource Space
A resource space is the commissioning space provided by the platform for applications and devices. You can create different resource spaces for different scenarios.
The system provides a preset resource space, where you can develop product models and codecs for devices online. To create a resource space, perform the following steps:
- Log in to the IoTDA console.
- On the navigation pane, click Resource Spaces, and then click Create Resource Space in the upper right corner. On the page displayed, enter a resource space name and click OK.
Creating a Product
You can develop product models and codecs online. The platform provides device and application simulators for you to debug the product models and codecs.
- Log in to the IoTDA console.
- In the navigation pane, click Products. Click the drop-down list box above the product list, and select the resource space to which the new product belongs.

- Click Create Product in the upper right corner to create a product using LwM2M over CoAP. Set the parameters and click Create.

Set Basic Info
Resource Space
Select the resource space to which the product to create belongs.
Product Name
Customize a name, for example, StreetLight.
Protocol
Select LwM2M over CoAP.
Data Type
Select Binary.
NOTE:If Data Type is Binary, codec development is required for the product. If Data Type is JSON, codec development is not required.
Manufacturer
Customize the value.
Define Product Model
Product Model
Do not select Use product model. Customize a product model in subsequent steps.
Industry
Select Smart City.
Device Type
Enter streetlight.
Defining a Product Model
- In the row of the product created in 3 and click View to access its details.
- On the Model Definition tab page, click Custom Model to add a service for the product.
- Service: Enter StreetLight.
- Description: Provide a description, for example, "Define the properties of light intensity and status."

- In the Properties/Commands list, click Add Property to define a property as follows: Set Property Name to light_intensity, Data Type to integer, and Value Range to 0 - 100. Click OK.

- Click Add Property to define another property as follows: Set Property Name to light_status, Data Type to integer, and Value Range to 0 - 1. Click OK.

- Define the command used to remotely control the street lamp switch status.
- Click Add Command. In the dialog box displayed, set Command Name to SWITCH_LIGHT.
- Click Add Input Parameter. Set Parameter Name to SWITCH_LIGHT, Data Type to string, Length to 3, and Enumerated Value to ON,OFF. Click OK.

- Click Add Output Parameter. Set Parameter Name to result and Data Type to integer.
- Click OK. The product model of the street lamp is created.
Developing a Codec Online
For purposes of power conservation, devices generally report binary data. The codec converts the binary data into JSON data based on properties defined in the product model so that the platform and application can identify the data. When an application remotely delivers a command, the platform converts the command in JSON format into binary and delivers the binary data to the device.
If a device reports data in JSON format, you do not need to define a codec.
- On the product details page of the street lamp, select Codec Development and click Online Develop.
- Click Add Message and configure a data reporting message as follows to report street lamp data:
- Message Name: Enter LightData.
- Message Type: Select Data reporting.
- Add Response Field: Select this option. After a response field is added, the platform delivers the configured response data to the device when receiving data reported by the device.
- Response: Retain the default value AAAA0000.

- Click Add Field to add the messageId field, which indicates the message type.

- Add the LightIntensity field to indicate the light intensity. Set Data Type to int8u (8-bit unsigned integer) and Length is 1.

- Added the LightStatus field to indicate the street lamp switch status. Set Data Type to int8u (8-bit unsigned integer) and Length is 1.

- Click Add Message again to develop a codec for command delivery messages.
- Message Name: Enter SwitchStatus.
- Message Type: Select Command delivery.
- Add Response Field: Select this option. After a response field is added, the device reports the command execution result when receiving the command.

- Click Add Field to add the messageId field, which indicates the message type.

- Add the mid field to associate the delivered command with the command execution result.

- Add the SwitchStatus field. Set Data Type to string and Length is 3.

- Click Add Response Field to configure command delivery responses.
- Add the messageId field to indicate the message type. The command execution result is an upstream message, which is differentiated from the data reporting message by the messageId field.

- Add the mid field to associate the delivered command with the command execution result.

- Add the errcode field to indicate the command execution status. 00 indicates success and 01 indicates failure. If this field is not carried, the command is executed successfully by default.

- Add the result field to indicate the command execution result.

- Add the messageId field to indicate the message type. The command execution result is an upstream message, which is differentiated from the data reporting message by the messageId field.
- Drag the property and command fields (defined in the product model) in the Product Model area on the right to map the fields in the data reporting and command delivery messages defined by the codec.

- Click Save in the upper right corner and click Deploy to complete codec deployment.
Debugging the Codec Online Using a Physical Device
Simulators debug the functions of devices and applications. You can debug the defined product model and codec by simulating data reporting and command delivery.
- On the product details page of the street lamp, click Online Debugging and click Add Test Device.
- In the dialog box displayed, set the parameters and click OK.
- Device Type: Select Physical device.
- Device Name: Customize a name.
- Node ID: Enter the IMEI of the device. The node ID will be carried by the device for device access authentication. You can view the node ID on the NB-IoT module.
- Registration Mode: Select Unencrypted. Note: If DTLS is used for device access, select Encrypted and keep the secret properly.

The newly added device is in the inactive state, and online debugging cannot be performed. You need to connect the device to the platform first. For details, see Performing Connection Authentication.
- Click Debug to access the debugging page.

- Simulate a scenario where a control command is remotely delivered. Specifically, under Application Simulator, select StreetLight for Service, SWITCH_LIGHT for Command, ON for SWITCH_LIGHT, and click Send. The street lamp is turned on.
Debugging the Codec Online Using a Virtual Device
- On the product details page of the street lamp, click Online Debugging and click Add Test Device.
- In the dialog box displayed, select Virtual device and click OK. The virtual device name contains Simulator. Only one virtual device can be created for each product.

- Click Debug to access the debugging page.

- Simulate a data reporting scenario. Specifically, under Device Simulator, enter the hexadecimal code stream 002000, and click Send. (The first byte 00 indicates the messageId, the second byte 20 indicates the light intensity, and the third byte 00 indicates the switch status.) Under Application Simulator, "Light_Intensity": 32, "Light_Status": 0 should be displayed.

- Simulate a command delivery scenario. Specifically, under Application Simulator, select StreetLight for Service, SWITCH_LIGHT for Command, ON for SWITCH_LIGHT, and click Send. Under Device Simulator, 0100184F4E should be displayed.

Debugging Using an Offline Simulator
The NB-IoT device simulator is used to simulate the access of NB-IoT devices (devices using LwM2M over CoAP) to the platform for data reporting and command delivery.
- Obtain the node ID and secret generated during device registration in 2.
- Download and decompress the NB-IoT device simulator, and double-click NB-IoTDeviceSimulator_zh.jar to run the simulator.
- The simulator can run on Windows, but not macOS.
- Ensure that the JDK has been installed. Otherwise, the JAR file cannot be executed.

The package contains the following files:
- NB-IoTDeviceSimulator_en.jar: simulator
- Californium.properties: simulator configuration file
- setting.properties: configuration file for connecting the simulator to the platform
- When a message is displayed requesting you to confirm whether to enable DTLS encrypted transmission, click No if a secret is not entered during device registration, or Yes if a secret is entered.

- Enter IP address, VerifyCode, and psk, and click Register Device to bind the simulator to the platform.
Note: If DTLS encryption transmission is disabled, you do not need to enter a PSK.
Set the three parameters as follows:- IP address: access domain name displayed on the IoTDA console. (You can also use the IP address. You can run the ping [domain name] command to obtain the IP address.)
- VerifyCode: device ID, for example, aaaaa11111.
- psk: secret set during device registration, for example, aaaaa11111aaaaa.

On the IoTDA console, choose and view the device status. If the device is displayed as Online, the simulator is bound to the platform.
- Simulate a data reporting scenario. Specifically, under the NB-IoT device simulator, enter the hexadecimal code stream 001400, and click Send Data. (The first byte 00 indicates the messageId, the second byte 14 indicates the light intensity, and the third byte 00 indicates the switch status.)

After the data is reported, go back to the IoTDA console. On the Historical Data page of the device aaaaa11111, the data converted into the JSON format is "Light_Intensity": 20, "Light_Status": 0.

- Simulate a command delivery scenario.
Under Application Simulator, select StreetLight for Service, SWITCH_LIGHT for Command, ON for SWITCH_LIGHT, and click Send.
The data delivered by the CIG is ON in the log area, and the simulator displays a message indicating that the downstream message from the platform is received and asking whether to respond. Click Yes. On the Application Simulator page of the IoTDA console, you can see that the command is in the Delivered state.

Last Article: Introduction
Next Article: Device Access
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.