IoT Central Direct Method aka Command response

Slawomir Wojtynek 1 Reputation point

I have an (non-legacy) IoT Central application that can submit the "reboot" command to the device.
And I have an IoT device that accepts that command.
The device communicates with the application using MQTT protocol.

What I'm interested in is to get the response from the device that could be presented in the IoT Central Command History panel.

At first I tried the synchronous commands with a "Response" capability enabled but as I read in the

> Currently, IoT Central doesn't use the response schema defined in the device capability model. For a synchronous command, the response payload can be any valid JSON.

So now I create an asynchronous command and read the docs further:

> For an asynchronous command, the device should return a 202 response immediately, followed by reported property update when the work is finished.

Now, when my device receives the command, e.g. $iothub/methods/POST/reboot/?$rid=1,
it responds with:
$iothub/methods/res/202/?$rid=1 with the payload: {"status": 202, "payload": {"message": "Rebooting"}}

And after the device is rebooted, it sends the command property update:
$iothub/twin/PATCH/properties/reported/?$rid=7 with the payload: {"reboot": {"value": "Device rebooted"}}

The IoT hub acknowledges the update: $iothub/twin/res/204/?$rid=7&$version=114

But when I open the command history panel I can't see the response - there are SENDING and SENT entries but no RESPONSE.

Where am I making a mistake?

Azure IoT Central
Azure IoT Central
An Azure hosted internet of things (IoT) application platform.
279 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Roman Kiss 2,136 Reputation points

    The asynchronously command response is not depended from the invoking a direct device method. The value for this response is taken from the existing reported property with a "hardcoded name" the same as the command name. Note, that the name is a case sensitive.

    In your scenario, be sure that this reported property such as a reboot is existed before executing a command, you can populated with some initialize value. To see this response (the value of the reported property reboot) in the Command history, just make a one command request.

    The following screen snippets show an example of this Reboot command:


    the PnP device has been created by my Azure IoT Hub Tester:


    where the reported property Reboot is:


    and the Command response:


    After this first executing a command, you can change many times the value of the reported property Reboot and refreshing the Command history to see the latest command response.

    Note, that executing a sync command is working well also, where the device sent the response payload to the IoTC App. In this case, the command response is generated by the direct method.


    The following screens demonstrated an example of the executing a sync command RebootSync from IoTC App.

    • Adding a new capability (Command RebootSync) to the device template:
    • the Command response object:


    • Run Command RebootSync:


    • Connected PnP device tester3 received the direct method RebootSync request and sent the response back to the invoker:


    • Command response on the IoT Central App:

    The Command history can be obtained also using the REST API, the following screen snippet shows Azure IoT Hub Tester to get this history:




    1 person found this answer helpful.