Bidirectional Communications Between Virtual Devices and IoTDA
Scenarios
This section uses a smart street light as an example to describe how to connect a device to the platform, enable the device to report luminance data, and deliver commands to the device.
Prerequisites
Service Process
Based on the online debugging function of IoTDA, you can use a virtual device to experience device data reporting and platform command delivery for remote control.
The procedure is as follows:
Step 1 Create an MQTT product.
Step 2 Develop a product model. Define the luminance property reported by a street light to the platform and the command for remote control of the street light.
Step 3 Register a virtual device to experience data reporting.
Step 4 Report data. Report data in the device simulator area.
Step 5 Deliver a command. Deliver a command in the application simulator area.
Creating a Product
A product is a collection of devices with the same capabilities or features.
- Log in to the console, choose Products in the navigation pane, and click Create Product on the left.
- Set the parameters as prompted and click OK.
Figure 1 Creating an MQTT product
Basic Information
Resource Space
Select a resource space from the drop-down list box. If a resource space does not exist, create one.
Product Name
Customize a name, for example, SmartStreetlight. The value can contain up to 64 characters. Only letters, digits, and special characters (_?'#().,&%@!-) are allowed.
Protocol
Select MQTT.
Data Type
Select JSON.
Industry
Select Default.
Device Type
Enter SmartStreetlight.
Developing a Product Model
- Click the product created in Creating a Product. The product details page is displayed.
- On the Model Definition tab page of the product details page, click Customize Model to add services of the product.
- Add the BasicData service.
- On the Add Service page, configure Service ID, Service Type, and Description, and click OK.
- Service ID: Enter BasicData.
- Service Type: You are advised to set this parameter to the same value as Service ID.
- Description: Enter Reports street light data.
- Click Add Property, enter related information, and click OK.
- Property Name: Enter luminance.
- Data Type: Select Integer.
- Access Permissions: Select Read and Write.
- Value Range: Set it to 0–65535.
- Step: Enter 0.
- Unit: Leave it blank.
- On the Add Service page, configure Service ID, Service Type, and Description, and click OK.
- Click Add Command and enter the command name lightControl.On the Add Command page, click Add Command Parameter, enter related information, and click OK.Figure 2 Adding the command parameter switch
- Parameter Name: Enter switch.
- Description: Enter Delivers the command for turning on/off the street light.
- Data Type: Select String.
- Length: Enter 15.
- Enumerated Values: Enter ON,OFF.
Registering a Virtual Device
- Click the product created in Creating a Product. The product details page is displayed.
- On the Online Debugging tab page, click Add Test Device. In the displayed dialog box, select Virtual device and click OK.
The virtual device name contains Simulator. Select the new virtual device and click Debug on the right. The debugging page is displayed, and the device status changes to online.
Reporting Data
In Device Simulator, enter a luminance value and click Send. View the reporting result in Application Simulator.
Delivering a Command
In Application Simulator, select the command, enter a parameter value, and deliver the command for remote control of the street light. View the received command in Device Simulator.
Advanced Experience
By following the instructions in this section, you may have understood the basic functions and development process of the platform.
To better experience IoTDA, develop real applications and devices and connect them to the platform. For details, see Sample Code for Bidirectional Communications.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot