Azure IoT C SDK
iothub_device_client.h
Go to the documentation of this file.
1 // Copyright (c) Microsoft. All rights reserved.
2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3 
15 #ifndef IOTHUB_DEVICE_CLIENT_H
16 #define IOTHUB_DEVICE_CLIENT_H
17 
18 #include <stddef.h>
19 #include <stdint.h>
20 
21 #include "umock_c/umock_c_prod.h"
22 #include "iothub_transport_ll.h"
23 #include "iothub_client_core_ll.h"
24 #include "iothub_client_core.h"
26 
27 #ifndef IOTHUB_DEVICE_CLIENT_INSTANCE_TYPE
33 typedef IOTHUB_CLIENT_CORE_HANDLE IOTHUB_DEVICE_CLIENT_HANDLE;
34 #define IOTHUB_DEVICE_CLIENT_INSTANCE_TYPE
35 #endif // IOTHUB_CLIENT_INSTANCE
36 
37 #ifndef DONT_USE_UPLOADTOBLOB
42 #endif // DONT_USE_UPLOADTOBLOB
43 
44 #ifdef __cplusplus
45 extern "C"
46 {
47 #endif
48 
65  IOTHUB_DEVICE_CLIENT_HANDLE IoTHubDeviceClient_CreateFromConnectionString( const char* connectionString, IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol);
104  IOTHUB_DEVICE_CLIENT_HANDLE IoTHubDeviceClient_CreateFromDeviceAuth( const char* iothub_uri, const char* device_id, IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol);
137  IOTHUB_CLIENT_RESULT IoTHubDeviceClient_SendEventAsync( IOTHUB_DEVICE_CLIENT_HANDLE iotHubClientHandle, IOTHUB_MESSAGE_HANDLE eventMessageHandle, IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK eventConfirmationCallback, void* userContextCallback);
201  IOTHUB_CLIENT_RESULT IoTHubDeviceClient_SetRetryPolicy( IOTHUB_DEVICE_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY retryPolicy, size_t retryTimeoutLimitInSeconds);
215  IOTHUB_CLIENT_RESULT IoTHubDeviceClient_GetRetryPolicy( IOTHUB_DEVICE_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY* retryPolicy, size_t* retryTimeoutLimitInSeconds);
241  IOTHUB_CLIENT_RESULT IoTHubDeviceClient_SetOption( IOTHUB_DEVICE_CLIENT_HANDLE iotHubClientHandle, const char* optionName, const void* value);
275  IOTHUB_CLIENT_RESULT IoTHubDeviceClient_SendReportedState( IOTHUB_DEVICE_CLIENT_HANDLE iotHubClientHandle, const unsigned char* reportedState, size_t size, IOTHUB_CLIENT_REPORTED_STATE_CALLBACK reportedStateCallback, void* userContextCallback);
312  IOTHUB_CLIENT_RESULT IoTHubDeviceClient_DeviceMethodResponse( IOTHUB_DEVICE_CLIENT_HANDLE iotHubClientHandle, METHOD_HANDLE methodId, const unsigned char* response, size_t response_size, int statusCode);
313 #ifndef DONT_USE_UPLOADTOBLOB
326  IOTHUB_CLIENT_RESULT IoTHubDeviceClient_UploadToBlobAsync( IOTHUB_DEVICE_CLIENT_HANDLE iotHubClientHandle, const char* destinationFileName, const unsigned char* source, size_t size, IOTHUB_CLIENT_FILE_UPLOAD_CALLBACK iotHubClientFileUploadCallback, void* context);
362  IOTHUB_CLIENT_RESULT IoTHubDeviceClient_AzureStorageInitializeBlobUpload( IOTHUB_DEVICE_CLIENT_HANDLE iotHubClientHandle, const char* destinationFileName, char** uploadCorrelationId, char** azureBlobSasUri);
408  IOTHUB_CLIENT_RESULT IoTHubDeviceClient_AzureStoragePutBlock( IOTHUB_CLIENT_AZURE_STORAGE_CLIENT_HANDLE azureStorageClientHandle, uint32_t blockNumber, const uint8_t* dataPtr, size_t dataSize);
480  IOTHUB_CLIENT_RESULT IoTHubDeviceClient_AzureStorageNotifyBlobUploadCompletion( IOTHUB_DEVICE_CLIENT_HANDLE iotHubClientHandle, const char* uploadCorrelationId, bool isSuccess, int responseCode, const char* responseMessage);#endif /* DONT_USE_UPLOADTOBLOB */
481 
520  IOTHUB_CLIENT_RESULT IoTHubDeviceClient_SendTelemetryAsync( IOTHUB_DEVICE_CLIENT_HANDLE iotHubClientHandle, IOTHUB_MESSAGE_HANDLE telemetryMessageHandle, IOTHUB_CLIENT_TELEMETRY_CALLBACK telemetryConfirmationCallback, void* userContextCallback);
553  IOTHUB_CLIENT_RESULT IoTHubDeviceClient_SendPropertiesAsync( IOTHUB_DEVICE_CLIENT_HANDLE iotHubClientHandle, const unsigned char* properties, size_t propertiesLength, IOTHUB_CLIENT_PROPERTY_ACKNOWLEDGED_CALLBACK propertyAcknowledgedCallback, void* userContextCallback);
587 #ifdef __cplusplus
588 }
589 #endif
590 
591 #endif /* IOTHUB_DEVICE_CLIENT_H */
void(* IOTHUB_CLIENT_PROPERTY_ACKNOWLEDGED_CALLBACK)(int statusCode, void *userContextCallback)
Function callback application implements to receive acknowledgements of properties sent from the clie...
Definition: iothub_client_core_common.h:381
void(* IOTHUB_CLIENT_FILE_UPLOAD_CALLBACK)(IOTHUB_CLIENT_FILE_UPLOAD_RESULT result, void *userContextCallback)
Deprecated callback mechanism for uploading data to a blob.
Definition: iothub_client_core_common.h:29
IOTHUB_CLIENT_FILE_UPLOAD_GET_DATA_RESULT(* IOTHUB_CLIENT_FILE_UPLOAD_GET_DATA_CALLBACK_EX)(IOTHUB_CLIENT_FILE_UPLOAD_RESULT result, unsigned char const **data, size_t *size, void *context)
Signature of the callback that the application implements to process IoT Hub client SDK requesting ad...
Definition: iothub_client_core_common.h:260
void(* IOTHUB_CLIENT_TELEMETRY_CALLBACK)(IOTHUB_CLIENT_CONFIRMATION_RESULT result, void *userContextCallback)
Function callback application implements to receive notifications when IoT Hub acknowledges telemetry...
Definition: iothub_client_core_common.h:370
void(* IOTHUB_CLIENT_DEVICE_TWIN_CALLBACK)(DEVICE_TWIN_UPDATE_STATE update_state, const unsigned char *payLoad, size_t size, void *userContextCallback)
Signature of the callback that the application implements to process data received from an IoT Hub de...
Definition: iothub_client_core_common.h:201
IOTHUB_CLIENT_RETRY_POLICY
Enumeration specifying the retry strategy the IoT Hub client should use.
Definition: iothub_client_core_common.h:63
void(* IOTHUB_CLIENT_COMMAND_CALLBACK_ASYNC)(const IOTHUB_CLIENT_COMMAND_REQUEST *commandRequest, IOTHUB_CLIENT_COMMAND_RESPONSE *commandResponse, void *userContextCallback)
Function callback application implements to process an incoming command from IoT Hub.
Definition: iothub_client_core_common.h:358
void(* IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK)(IOTHUB_CLIENT_CONFIRMATION_RESULT result, void *userContextCallback)
Signature of the callback that the application implements to process acknowledgement or failures when...
Definition: iothub_client_core_common.h:170
IOTHUBMESSAGE_DISPOSITION_RESULT
Enumeration returned by application callbacks that receive cloud-to-device messages.
Definition: iothub_client_core_common.h:81
void(* IOTHUB_CLIENT_REPORTED_STATE_CALLBACK)(int status_code, void *userContextCallback)
Signature of the callback that the application implements to receive notifications of device or modul...
Definition: iothub_client_core_common.h:209
int(* IOTHUB_CLIENT_DEVICE_METHOD_CALLBACK_ASYNC)(const char *method_name, const unsigned char *payload, size_t size, unsigned char **response, size_t *response_size, void *userContextCallback)
Signature of the callback that the application implements to receive incoming device or module method...
Definition: iothub_client_core_common.h:227
void(* IOTHUB_CLIENT_PROPERTIES_RECEIVED_CALLBACK)(IOTHUB_CLIENT_PROPERTY_PAYLOAD_TYPE payloadType, const unsigned char *payload, size_t payloadLength, void *userContextCallback)
Function callback application implements to process properties received from IoT Hub.
Definition: iothub_client_core_common.h:392
void(* IOTHUB_CLIENT_CONNECTION_STATUS_CALLBACK)(IOTHUB_CLIENT_CONNECTION_STATUS result, IOTHUB_CLIENT_CONNECTION_STATUS_REASON reason, void *userContextCallback)
Signature of the callback that the application implements to process connection status changes betwee...
Definition: iothub_client_core_common.h:179
IOTHUBMESSAGE_DISPOSITION_RESULT(* IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC)(IOTHUB_MESSAGE_HANDLE message, void *userContextCallback)
Signature of the callback that the application implements to process incoming cloud-to-device message...
Definition: iothub_client_core_common.h:189
struct IOTHUB_CLIENT_LL_UPLOADTOBLOB_CONTEXT_STRUCT * IOTHUB_CLIENT_LL_UPLOADTOBLOB_CONTEXT_HANDLE
Definition: iothub_client_core_common.h:38
IOTHUB_CLIENT_RESULT
Enumeration specifying the status of calls to IoT Hub client.
Definition: iothub_client_core_common.h:42
IOTHUB_CLIENT_STATUS
Enumeration returned by the GetSendStatus family of APIs (e.g. IoTHubDeviceClient_LL_GetSendStatus())...
Definition: iothub_client_core_common.h:73
IOTHUB_CLIENT_RESULT IoTHubDeviceClient_DeviceMethodResponse(IOTHUB_DEVICE_CLIENT_HANDLE iotHubClientHandle, METHOD_HANDLE methodId, const unsigned char *response, size_t response_size, int statusCode)
This API responds to an asnyc method callback identified the methodId.
IOTHUB_CLIENT_LL_UPLOADTOBLOB_CONTEXT_HANDLE IOTHUB_CLIENT_AZURE_STORAGE_CLIENT_HANDLE
Handle for Upload-to-Blob API Functions.
Definition: iothub_device_client.h:41
IOTHUB_CLIENT_RESULT IoTHubDeviceClient_GetPropertiesAsync(IOTHUB_DEVICE_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_PROPERTIES_RECEIVED_CALLBACK propertyCallback, void *userContextCallback)
Retrieves all device properties from IoT Hub.
IOTHUB_CLIENT_RESULT IoTHubDeviceClient_GetSendStatus(IOTHUB_DEVICE_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_STATUS *iotHubClientStatus)
This function returns the current sending status for IoTHubClient.
IOTHUB_CLIENT_RESULT IoTHubDeviceClient_SendMessageDisposition(IOTHUB_DEVICE_CLIENT_HANDLE iotHubClientHandle, IOTHUB_MESSAGE_HANDLE message, IOTHUBMESSAGE_DISPOSITION_RESULT disposition)
This API sends an acknowledgement to Azure IoT Hub that a cloud-to-device message has been received a...
IOTHUB_DEVICE_CLIENT_HANDLE IoTHubDeviceClient_CreateWithTransport(TRANSPORT_HANDLE transportHandle, const IOTHUB_CLIENT_CONFIG *config)
Creates a IoT Hub client for communication with an existing IoT Hub using the specified parameters.
void IoTHubDeviceClient_Destroy(IOTHUB_DEVICE_CLIENT_HANDLE iotHubClientHandle)
Disposes of resources allocated by the IoT Hub client. This is a blocking call.
IOTHUB_CLIENT_RESULT IoTHubDeviceClient_UploadToBlobAsync(IOTHUB_DEVICE_CLIENT_HANDLE iotHubClientHandle, const char *destinationFileName, const unsigned char *source, size_t size, IOTHUB_CLIENT_FILE_UPLOAD_CALLBACK iotHubClientFileUploadCallback, void *context)
IoTHubDeviceClient_UploadToBlobAsync uploads data from memory to a file in Azure Blob Storage.
IOTHUB_CLIENT_RESULT IoTHubDeviceClient_AzureStorageNotifyBlobUploadCompletion(IOTHUB_DEVICE_CLIENT_HANDLE iotHubClientHandle, const char *uploadCorrelationId, bool isSuccess, int responseCode, const char *responseMessage)
This API notifies Azure IoT Hub of the upload completion.
IOTHUB_CLIENT_RESULT IoTHubDeviceClient_SetMessageCallback(IOTHUB_DEVICE_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC messageCallback, void *userContextCallback)
Sets up the message callback to be invoked when IoT Hub issues a message to the device....
IOTHUB_CLIENT_RESULT IoTHubDeviceClient_SetRetryPolicy(IOTHUB_DEVICE_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY retryPolicy, size_t retryTimeoutLimitInSeconds)
Sets up the connection status callback to be invoked representing the status of the connection to IOT...
IOTHUB_CLIENT_RESULT IoTHubDeviceClient_SetDeviceTwinCallback(IOTHUB_DEVICE_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_DEVICE_TWIN_CALLBACK deviceTwinCallback, void *userContextCallback)
This API specifies a callback to be used when the device receives a state update.
IOTHUB_DEVICE_CLIENT_HANDLE IoTHubDeviceClient_CreateFromConnectionString(const char *connectionString, IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol)
Creates a IoT Hub client for communication with an existing IoT Hub using the specified connection st...
IOTHUB_CLIENT_RESULT IoTHubDeviceClient_SendPropertiesAsync(IOTHUB_DEVICE_CLIENT_HANDLE iotHubClientHandle, const unsigned char *properties, size_t propertiesLength, IOTHUB_CLIENT_PROPERTY_ACKNOWLEDGED_CALLBACK propertyAcknowledgedCallback, void *userContextCallback)
Sends device properties to IoT Hub.
IOTHUB_CLIENT_RESULT IoTHubDeviceClient_AzureStoragePutBlock(IOTHUB_CLIENT_AZURE_STORAGE_CLIENT_HANDLE azureStorageClientHandle, uint32_t blockNumber, const uint8_t *dataPtr, size_t dataSize)
This API uploads a single blob block to Azure Storage (performs a PUT BLOCK operation).
IOTHUB_CLIENT_RESULT IoTHubDeviceClient_GetTwinAsync(IOTHUB_DEVICE_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_DEVICE_TWIN_CALLBACK deviceTwinCallback, void *userContextCallback)
This API provides a way to retrieve the complete device Twin properties on-demand.
void IoTHubDeviceClient_AzureStorageDestroyClient(IOTHUB_CLIENT_AZURE_STORAGE_CLIENT_HANDLE azureStorageClientHandle)
This API destroys an instance previously created with IoTHubDeviceClient_AzureStorageCreateClient.
IOTHUB_CLIENT_RESULT IoTHubDeviceClient_GetRetryPolicy(IOTHUB_DEVICE_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY *retryPolicy, size_t *retryTimeoutLimitInSeconds)
Sets up the connection status callback to be invoked representing the status of the connection to IOT...
IOTHUB_CLIENT_RESULT IoTHubDeviceClient_SendTelemetryAsync(IOTHUB_DEVICE_CLIENT_HANDLE iotHubClientHandle, IOTHUB_MESSAGE_HANDLE telemetryMessageHandle, IOTHUB_CLIENT_TELEMETRY_CALLBACK telemetryConfirmationCallback, void *userContextCallback)
Asynchronous call to send the telemetry message specified by telemetryMessageHandle.
IOTHUB_CLIENT_RESULT IoTHubDeviceClient_SendEventAsync(IOTHUB_DEVICE_CLIENT_HANDLE iotHubClientHandle, IOTHUB_MESSAGE_HANDLE eventMessageHandle, IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK eventConfirmationCallback, void *userContextCallback)
Asynchronous call to send the message specified by eventMessageHandle.
IOTHUB_CLIENT_RESULT IoTHubDeviceClient_SendReportedState(IOTHUB_DEVICE_CLIENT_HANDLE iotHubClientHandle, const unsigned char *reportedState, size_t size, IOTHUB_CLIENT_REPORTED_STATE_CALLBACK reportedStateCallback, void *userContextCallback)
This API sends a report of the device's properties and their current values.
IOTHUB_CLIENT_RESULT IoTHubDeviceClient_SetConnectionStatusCallback(IOTHUB_DEVICE_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_CONNECTION_STATUS_CALLBACK connectionStatusCallback, void *userContextCallback)
Sets up the connection status callback to be invoked representing the status of the connection to IOT...
IOTHUB_CLIENT_RESULT IoTHubDeviceClient_GetPropertiesAndSubscribeToUpdatesAsync(IOTHUB_DEVICE_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_PROPERTIES_RECEIVED_CALLBACK propertyUpdateCallback, void *userContextCallback)
Retrieves all device properties from IoT Hub and also subscribes for updates to writable properties.
IOTHUB_CLIENT_RESULT IoTHubDeviceClient_UploadMultipleBlocksToBlobAsync(IOTHUB_DEVICE_CLIENT_HANDLE iotHubClientHandle, const char *destinationFileName, IOTHUB_CLIENT_FILE_UPLOAD_GET_DATA_CALLBACK_EX getDataCallbackEx, void *context)
Uploads a file to a Blob storage in chunks, fed through the callback function provided by the user.
IOTHUB_CLIENT_AZURE_STORAGE_CLIENT_HANDLE IoTHubDeviceClient_AzureStorageCreateClient(IOTHUB_DEVICE_CLIENT_HANDLE iotHubClientHandle, const char *azureBlobSasUri)
This API creates a client for a new blob upload to Azure Storage.
IOTHUB_CLIENT_RESULT IoTHubDeviceClient_AzureStoragePutBlockList(IOTHUB_CLIENT_AZURE_STORAGE_CLIENT_HANDLE azureStorageClientHandle)
This API performs an Azure Storage PUT BLOCK LIST operation.
IOTHUB_CLIENT_RESULT IoTHubDeviceClient_GetLastMessageReceiveTime(IOTHUB_DEVICE_CLIENT_HANDLE iotHubClientHandle, time_t *lastMessageReceiveTime)
This function returns in the out parameter lastMessageReceiveTime what was the value of the time func...
IOTHUB_CLIENT_RESULT IoTHubDeviceClient_SetOption(IOTHUB_DEVICE_CLIENT_HANDLE iotHubClientHandle, const char *optionName, const void *value)
This API sets a runtime option identified by parameter optionName to a value pointed to by value....
IOTHUB_CLIENT_CORE_HANDLE IOTHUB_DEVICE_CLIENT_HANDLE
Handle corresponding to a convenience layer device client instance.
Definition: iothub_device_client.h:33
IOTHUB_DEVICE_CLIENT_HANDLE IoTHubDeviceClient_Create(const IOTHUB_CLIENT_CONFIG *config)
Creates a IoT Hub client for communication with an existing IoT Hub using the specified parameters.
IOTHUB_CLIENT_RESULT IoTHubDeviceClient_SubscribeToCommands(IOTHUB_DEVICE_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_COMMAND_CALLBACK_ASYNC commandCallback, void *userContextCallback)
Subscribe to incoming commands from IoT Hub.
IOTHUB_DEVICE_CLIENT_HANDLE IoTHubDeviceClient_CreateFromDeviceAuth(const char *iothub_uri, const char *device_id, IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol)
Creates a IoT Hub client for communication with an existing IoT Hub using the device auth.
IOTHUB_CLIENT_RESULT IoTHubDeviceClient_SetDeviceMethodCallback(IOTHUB_DEVICE_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_DEVICE_METHOD_CALLBACK_ASYNC deviceMethodCallback, void *userContextCallback)
This API sets the callback for async cloud to device method calls.
IOTHUB_CLIENT_RESULT IoTHubDeviceClient_AzureStorageInitializeBlobUpload(IOTHUB_DEVICE_CLIENT_HANDLE iotHubClientHandle, const char *destinationFileName, char **uploadCorrelationId, char **azureBlobSasUri)
This API creates a new upload within Azure IoT Hub, getting back a correlation-id and a SAS URI for t...
APIs that allow a user (usually a device) to communicate with an Azure IoT Hub.
struct IOTHUB_MESSAGE_HANDLE_DATA_TAG * IOTHUB_MESSAGE_HANDLE
Handle representing an IoT Hub message.
Definition: iothub_message.h:32
This struct specifies IoT Hub client configuration.
Definition: iothub_client_core_common.h:264