azure-iot-hubazure-iot-hub-device-managementdevice-management

Get list of direct methods registered with IotHub device


I am working on one sample IoT project. Where 1 IoT device is registered on IotHub. It is exposing 1 direct method to control device temperature. On, device startup it is registering callback on IoTHub to listen for method invocation requests.

As per my understanding and knowledge, there is no way on cloud side that we can know that particular device is exposing this many direct methods and what is name of that method. (Because of MQTT/AMQP use internally).

Still, to be sure of if there is any work around to get direct methods registered by end device. Is there any SDK function or REST API to get list of direct methods registered by end-device.


Solution

  • You're correct in assuming there is no built-in support that lists the direct methods of your device. A device doesn't publish what methods it has implemented by default.

    Options:

    IoT PnP

    Microsoft created IoT Plug and play, which focuses on "device models". When a Plug and Play device connects to the IoT Hub, it can make its device model known. Part of this model is the concept of "commands", which translates to a direct method for IoT Hub. Your device probably doesn't have this device model yet, as PnP is pretty new. A device manufacturer/developer can integrate this model into the device.

    Create your own index command

    If you are the one writing code for this device, and you don't want to do PnP, you could create a direct method that lists all the methods supported by your device. Of course, you would need to know the name of that direct method to call it.