Using MQTT.fx to Simulate Communication Between the Smart Street Light and the Platform
Connecting the Simulated Street Light to the Platform
Use MQTT.fx to activate the device registered on IoTDA.
- Download MQTT.fx (64-bit OS) or MQTT.fx (32-bit OS) and install it.
- Go to the device details page, find MQTT Connection Parameter, and click View to check the clientId, username, password, and hostname.
Figure 1 Device - Device details
Figure 2 Device - Device details - MQTT connection parameters
- Open MQTT.fx and click the setting icon.
Figure 3 MQTT.fx Settings
- Click the User Credentials tab and set authentication parameters by referring to the following table.
Figure 4 Configuring authentication parameters
Table 1 Parameter description Parameter
Description
Broker Address
Host name, which is obtained in 2. The access address is a domain name. For devices that cannot be connected to the platform using a domain name, run the ping Domain name command in the CLI to obtain the IP address. The IP address is variable and needs to be set using a configuration item.
Broker Port
8883. In this example, port 8883 is used for secure connection.
Client ID
Enter the device client ID obtained in 2.
User Name
Enter the device ID obtained in 2.
Password
Enter the encrypted device secret obtained in 2.
- Click the SSL/TLS tab and then select Enable SSL/TLS. Recommended: Set Protocol to TLSv1.2. Click CA certificate file, go to the certificate resources page to download the certificate file of the corresponding region and instance version, and enter the complete local path of the certificate file in the text box. Click Apply, and then click Cancel to exit the configuration page.
Figure 5 Setting SSL/TLS parameters
- Click Connect. If the icon in the upper right corner turns green, the device simulator has been authenticated and connected. The device status displayed on the platform is Online.
Figure 6 Device simulator connected
Figure 7 Device online status
Reporting Light Intensity Data
Use MQTT.fx to report light intensity data to the IoT platform. If a device reports data through the MQTT channel, the data needs to be sent to a specific topic in the format $oc/devices/{device_id}/sys/properties/report. For devices that each has a different secret, set device_id to the device ID returned upon successful device registration.
- Enter the API URL, for example, $oc/devices/{device_id}/sys/properties/report.
Figure 8 Entering the API address
- Enter the data to report in the blank area in the middle of the tool and click Publish.
Table 2 Service data list Field
Mandatory/Optional
Type
Description
services
Mandatory
List<ServiceProperty>
Service data list. (For details, see the ServiceProperty structure below.)
Table 3 ServiceProperty structure Field
Mandatory/Optional
Type
Description
service_id
Mandatory
String
Service ID.
properties
Mandatory
Object
Service properties, which are defined in the product model associated with the device.
eventTime
Optional
String
UTC time when the device reports data. The format is yyyyMMddTHHmmssZ, for example, 20161219T114920Z.
If this parameter is not carried in the reported data or is in incorrect format, the time when IoTDA receives the data is used.
Request example:
{ "services": [{ "service_id": "BasicData", "properties": { "luminance": 30 } } ] }
- Check whether the device successfully reports data on the device details page. As shown in the following figure, the luminance is updated to 30.
Figure 9 Viewing reported data - MQTT
Remotely Delivering Commands for Turning On the Light
Deliver a command on the console to remotely control smart street lights.
- In the navigation pane, choose View to access its details page. , locate the target device, and click
- Click the Cloud Delivery tab, click Deliver Command, set Command to LightControl: Switch, and set Value to ON to deliver a command for turning on the light.
Figure 10 Command delivery - Synchronous command delivery
Figure 11 Command delivery - LightControl
MQTT devices support only synchronous command delivery. NB-IoT devices support only asynchronous command delivery.
- In the MQTT.fx simulator, click the Subscribe tab and enter the command delivery topic. After the subscription, check the delivered command parameters. The format of the command delivery topic is $oc/devices/{device_id}/sys/commands/#. As shown in the following figure, the MQTT.fx simulator has received the command whose command_name is Switch and value is ON.
Figure 12 Checking the delivered command parameters
The device needs to respond to the delivered synchronous command in a timely manner. However, MQTT.fx does not automatically report the command response. Therefore, the console page may display a message indicating that the command request times out. For details about the command response, see Platform Delivering a Command.
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