This API specifies a callback to be used when the device receives a state update.


#include "azure-iot-sdk-c/iothub_client/inc/iothub_device_client.h"

IOTHUB_CLIENT_RESULT IoTHubDeviceClient_SetDeviceTwinCallback(
  IOTHUB_DEVICE_CLIENT_HANDLE         iotHubClientHandle,
  void *                              userContextCallback


  • iotHubClientHandle The handle created by a call to the create function.

  • deviceTwinCallback The callback specified by the device client to be used for updating the desired state. The callback will be called in response to a request send by the IoTHub services. The payload will be passed to the callback, along with two version numbers:

  • Desired:

  • LastSeenReported:

  • userContextCallback User specified context that will be provided to the callback. This can be NULL.

NOTE: The application behavior is undefined if the user calls the IoTHubDeviceClient_Destroy function from within any callback.

Return Value

IOTHUB_CLIENT_OK upon success or an error code upon failure.