This article gives examples to introduce how to send commands and get responses through device synchronization commands via MQTT.fx.
Before uploading data points, complete the creation of products and devices, and perform device connection. Please refer to the Device Connection Instance for steps.
After establishing a connection with the device and before getting command from the device, you must subscribe to system command topic: $sys/{pid}/{device-name}/cmd/request/{cmdid}
In the topic, {cmdid} is a variable, which is a unique ID for each command, and you can make subscriptions using wildcards, e.g.: $sys/{pid}/{device-name}/cmd/request/+,或者$sys/{pid}/{device-name}/cmd/#
Please turn on the command debugger through Device List -> More Operations-> Send Command.
Set the command content and timeout, and click Send.
The MQTT simulator will receive a topic message, as shown below:
Topic in this example is: $sys/238322/mqtts-test-device/cmd/request/33ffea0a-e5f1-49d6-a626-ffee1bbd93ef
Publish a message to the corresponding topic using MQTT.fx, and simulate the device response (the content is abcd), as shown below:
In this example, the topic corresponding to the response is: $sys/238322/mqtts-test-device/cmd/response/33ffea0a-e5f1-49d6-a626-ffee1bbd93ef
After the device response is simulated with MQTT.fx, a message will be received from the system topic, indicating that the device response is successful, as shown below:
In this example, the topic is: $sys/238322/mqtts-test-device/cmd/response/33ffea0a-e5f1-49d6-a626-ffee1bbd93ef/accepted
After the device response is simulated with MQTT.fx, the command tool on the page will display the command response result, as shown below:
cmd_resp": "YWJjZA= = " refers to the Base64-encoded form of the device response message abcd.