Skip to main content

Commands

To send command to the device, you should publish message to topic commands/v2/<device-id>/requests. To see execution result you should be subscribed to another topic. commands/v2/<device-id>/responses. Every execution have a unique id to identify request-response pair.

For example, we want to enable a load on channel r5. We can do it via Cloud UI, but now we try to do it via MQTT API.

At first, subscribe to command responses:

mosquitto_sub -v -p 9883 -h <GATEWAY_IP_ADDRESS> -u public -P public -t "commands/v2/<device-id>/responses"

In another terminal send command:

mosquitto_pub -p 9883 -h <GATEWAY_IP_ADDRESS> -u public -P public -t "commands/v2/<device-id>/requests" -m '{"id":"<EXECUTION_ID>", "name":"enable_load", "arguments": {"load":"r5"}}'

In the terminal with responses subscription, you should see, that command executed successfully:

commands/v2/<device-id>/responses {"id":"<EXECUTION_ID>","state":"completed","payload":{"message":null}}

Also you can check telemetry on Dashboard or via MQTT API to see, that r5 changed from false to true.

All Rights Reserved © 2024 Enapter AG.