Microsoft Azure IoTHub client libraries

Dependents:   sht15_remote_monitoring RobotArmDemo iothub_client_sample_amqp f767zi_mqtt ... more

This library implements the Microsoft Azure IoTHub client library. The code is replicated from https://github.com/Azure/azure-iot-sdks

Committer:
Azure.IoT Build
Date:
Fri Mar 25 16:00:25 2016 -0700
Revision:
37:18310e4d888d
Parent:
36:67300d5a4c1f
Child:
40:1a94db9139ea
Release 1.0.3

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AzureIoTClient 16:deba40344375 1 // Copyright (c) Microsoft. All rights reserved.
AzureIoTClient 16:deba40344375 2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
AzureIoTClient 16:deba40344375 3
AzureIoTClient 16:deba40344375 4 /** @file iothub_client.h
AzureIoTClient 16:deba40344375 5 * @brief Extends the IoTHubCLient_LL module with additional features.
AzureIoTClient 16:deba40344375 6 *
AzureIoTClient 16:deba40344375 7 * @details IoTHubClient is a module that extends the IoTHubCLient_LL
AzureIoTClient 16:deba40344375 8 * module with 2 features:
AzureIoTClient 16:deba40344375 9 * - scheduling the work for the IoTHubCLient from a
AzureIoTClient 16:deba40344375 10 * thread, so that the user does not need to create their
AzureIoTClient 16:deba40344375 11 * own thread
AzureIoTClient 16:deba40344375 12 * - thread-safe APIs
AzureIoTClient 16:deba40344375 13 */
AzureIoTClient 16:deba40344375 14
AzureIoTClient 16:deba40344375 15 #ifndef IOTHUB_CLIENT_H
AzureIoTClient 22:b8732db970af 16 #define IOTHUB_CLIENT_H
AzureIoTClient 16:deba40344375 17
Azure.IoT Build 37:18310e4d888d 18 typedef struct IOTHUB_CLIENT_INSTANCE_TAG* IOTHUB_CLIENT_HANDLE;
Azure.IoT Build 37:18310e4d888d 19
AzureIoTClient 16:deba40344375 20 #include "iothub_client_ll.h"
Azure.IoT Build 37:18310e4d888d 21 #include "iothubtransport.h"
AzureIoTClient 16:deba40344375 22
AzureIoTClient 16:deba40344375 23 #ifdef __cplusplus
AzureIoTClient 16:deba40344375 24 extern "C"
AzureIoTClient 16:deba40344375 25 {
AzureIoTClient 16:deba40344375 26 #endif
AzureIoTClient 16:deba40344375 27
AzureIoTClient 16:deba40344375 28
AzureIoTClient 32:6e9d81a62085 29 /**
AzureIoTClient 32:6e9d81a62085 30 * @brief Creates a IoT Hub client for communication with an existing
AzureIoTClient 32:6e9d81a62085 31 * IoT Hub using the specified connection string parameter.
AzureIoTClient 32:6e9d81a62085 32 *
AzureIoTClient 32:6e9d81a62085 33 * @param connectionString Pointer to a character string
AzureIoTClient 32:6e9d81a62085 34 * @param protocol Function pointer for protocol implementation
AzureIoTClient 32:6e9d81a62085 35 *
AzureIoTClient 32:6e9d81a62085 36 * Sample connection string:
AzureIoTClient 32:6e9d81a62085 37 * <blockquote>
AzureIoTClient 32:6e9d81a62085 38 * <pre>HostName=[IoT Hub name goes here].[IoT Hub suffix goes here, e.g., private.azure-devices-int.net];DeviceId=[Device ID goes here];SharedAccessKey=[Device key goes here];</pre>
AzureIoTClient 32:6e9d81a62085 39 * </blockquote>
AzureIoTClient 32:6e9d81a62085 40 *
AzureIoTClient 32:6e9d81a62085 41 * @return A non-NULL @c IOTHUB_CLIENT_HANDLE value that is used when
AzureIoTClient 32:6e9d81a62085 42 * invoking other functions for IoT Hub client and @c NULL on failure.
AzureIoTClient 32:6e9d81a62085 43 */
AzureIoTClient 16:deba40344375 44 extern IOTHUB_CLIENT_HANDLE IoTHubClient_CreateFromConnectionString(const char* connectionString, IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol);
AzureIoTClient 16:deba40344375 45
AzureIoTClient 32:6e9d81a62085 46 /**
AzureIoTClient 32:6e9d81a62085 47 * @brief Creates a IoT Hub client for communication with an existing IoT
AzureIoTClient 32:6e9d81a62085 48 * Hub using the specified parameters.
AzureIoTClient 32:6e9d81a62085 49 *
AzureIoTClient 32:6e9d81a62085 50 * @param config Pointer to an @c IOTHUB_CLIENT_CONFIG structure
AzureIoTClient 32:6e9d81a62085 51 *
AzureIoTClient 32:6e9d81a62085 52 * The API does not allow sharing of a connection across multiple
AzureIoTClient 32:6e9d81a62085 53 * devices. This is a blocking call.
AzureIoTClient 32:6e9d81a62085 54 *
AzureIoTClient 32:6e9d81a62085 55 * @return A non-NULL @c IOTHUB_CLIENT_HANDLE value that is used when
AzureIoTClient 32:6e9d81a62085 56 * invoking other functions for IoT Hub client and @c NULL on failure.
AzureIoTClient 32:6e9d81a62085 57 */
AzureIoTClient 16:deba40344375 58 extern IOTHUB_CLIENT_HANDLE IoTHubClient_Create(const IOTHUB_CLIENT_CONFIG* config);
AzureIoTClient 16:deba40344375 59
AzureIoTClient 32:6e9d81a62085 60 /**
Azure.IoT Build 37:18310e4d888d 61 * @brief Creates a IoT Hub client for communication with an existing IoT
Azure.IoT Build 37:18310e4d888d 62 * Hub using the specified parameters.
Azure.IoT Build 37:18310e4d888d 63 *
Azure.IoT Build 37:18310e4d888d 64 * @param transportHandle TRANSPORT_HANDLE which represents a connection.
Azure.IoT Build 37:18310e4d888d 65 * @param config Pointer to an @c IOTHUB_CLIENT_CONFIG structure
Azure.IoT Build 37:18310e4d888d 66 *
Azure.IoT Build 37:18310e4d888d 67 * The API allows sharing of a connection across multiple
Azure.IoT Build 37:18310e4d888d 68 * devices. This is a blocking call.
Azure.IoT Build 37:18310e4d888d 69 *
Azure.IoT Build 37:18310e4d888d 70 * @return A non-NULL @c IOTHUB_CLIENT_HANDLE value that is used when
Azure.IoT Build 37:18310e4d888d 71 * invoking other functions for IoT Hub client and @c NULL on failure.
Azure.IoT Build 37:18310e4d888d 72 */
Azure.IoT Build 37:18310e4d888d 73 extern IOTHUB_CLIENT_HANDLE IoTHubClient_CreateWithTransport(TRANSPORT_HANDLE transportHandle, const IOTHUB_CLIENT_CONFIG* config);
Azure.IoT Build 37:18310e4d888d 74
Azure.IoT Build 37:18310e4d888d 75 /**
AzureIoTClient 32:6e9d81a62085 76 * @brief Disposes of resources allocated by the IoT Hub client. This is a
AzureIoTClient 32:6e9d81a62085 77 * blocking call.
AzureIoTClient 32:6e9d81a62085 78 *
AzureIoTClient 32:6e9d81a62085 79 * @param iotHubClientHandle The handle created by a call to the create function.
AzureIoTClient 32:6e9d81a62085 80 */
AzureIoTClient 16:deba40344375 81 extern void IoTHubClient_Destroy(IOTHUB_CLIENT_HANDLE iotHubClientHandle);
AzureIoTClient 16:deba40344375 82
AzureIoTClient 32:6e9d81a62085 83 /**
AzureIoTClient 32:6e9d81a62085 84 * @brief Asynchronous call to send the message specified by @p eventMessageHandle.
AzureIoTClient 32:6e9d81a62085 85 *
AzureIoTClient 32:6e9d81a62085 86 * @param iotHubClientHandle The handle created by a call to the create function.
AzureIoTClient 32:6e9d81a62085 87 * @param eventMessageHandle The handle to an IoT Hub message.
AzureIoTClient 32:6e9d81a62085 88 * @param eventConfirmationCallback The callback specified by the device for receiving
AzureIoTClient 32:6e9d81a62085 89 * confirmation of the delivery of the IoT Hub message.
AzureIoTClient 32:6e9d81a62085 90 * This callback can be expected to invoke the
AzureIoTClient 32:6e9d81a62085 91 * ::IoTHubClient_SendEventAsync function for the
AzureIoTClient 32:6e9d81a62085 92 * same message in an attempt to retry sending a failing
AzureIoTClient 32:6e9d81a62085 93 * message. The user can specify a @c NULL value here to
AzureIoTClient 32:6e9d81a62085 94 * indicate that no callback is required.
AzureIoTClient 32:6e9d81a62085 95 * @param userContextCallback User specified context that will be provided to the
AzureIoTClient 32:6e9d81a62085 96 * callback. This can be @c NULL.
AzureIoTClient 32:6e9d81a62085 97 *
AzureIoTClient 32:6e9d81a62085 98 * @b NOTE: The application behavior is undefined if the user calls
AzureIoTClient 32:6e9d81a62085 99 * the ::IoTHubClient_Destroy function from within any callback.
AzureIoTClient 32:6e9d81a62085 100 *
AzureIoTClient 32:6e9d81a62085 101 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
AzureIoTClient 32:6e9d81a62085 102 */
AzureIoTClient 16:deba40344375 103 extern IOTHUB_CLIENT_RESULT IoTHubClient_SendEventAsync(IOTHUB_CLIENT_HANDLE iotHubClientHandle, IOTHUB_MESSAGE_HANDLE eventMessageHandle, IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK eventConfirmationCallback, void* userContextCallback);
AzureIoTClient 16:deba40344375 104
AzureIoTClient 32:6e9d81a62085 105 /**
AzureIoTClient 32:6e9d81a62085 106 * @brief This function returns the current sending status for IoTHubClient.
AzureIoTClient 32:6e9d81a62085 107 *
AzureIoTClient 32:6e9d81a62085 108 * @param iotHubClientHandle The handle created by a call to the create function.
AzureIoTClient 32:6e9d81a62085 109 * @param iotHubClientStatus The sending state is populated at the address pointed
AzureIoTClient 32:6e9d81a62085 110 * at by this parameter. The value will be set to
AzureIoTClient 32:6e9d81a62085 111 * @c IOTHUBCLIENT_SENDSTATUS_IDLE if there is currently
AzureIoTClient 32:6e9d81a62085 112 * no item to be sent and @c IOTHUBCLIENT_SENDSTATUS_BUSY
AzureIoTClient 32:6e9d81a62085 113 * if there are.
AzureIoTClient 32:6e9d81a62085 114 *
AzureIoTClient 32:6e9d81a62085 115 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
AzureIoTClient 32:6e9d81a62085 116 */
AzureIoTClient 16:deba40344375 117 extern IOTHUB_CLIENT_RESULT IoTHubClient_GetSendStatus(IOTHUB_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_STATUS *iotHubClientStatus);
AzureIoTClient 16:deba40344375 118
AzureIoTClient 32:6e9d81a62085 119 /**
AzureIoTClient 32:6e9d81a62085 120 * @brief Sets up the message callback to be invoked when IoT Hub issues a
AzureIoTClient 32:6e9d81a62085 121 * message to the device. This is a blocking call.
AzureIoTClient 32:6e9d81a62085 122 *
AzureIoTClient 32:6e9d81a62085 123 * @param iotHubClientHandle The handle created by a call to the create function.
AzureIoTClient 32:6e9d81a62085 124 * @param messageCallback The callback specified by the device for receiving
AzureIoTClient 32:6e9d81a62085 125 * messages from IoT Hub.
AzureIoTClient 32:6e9d81a62085 126 * @param userContextCallback User specified context that will be provided to the
AzureIoTClient 32:6e9d81a62085 127 * callback. This can be @c NULL.
AzureIoTClient 32:6e9d81a62085 128 *
AzureIoTClient 32:6e9d81a62085 129 * @b NOTE: The application behavior is undefined if the user calls
AzureIoTClient 32:6e9d81a62085 130 * the ::IoTHubClient_Destroy function from within any callback.
AzureIoTClient 32:6e9d81a62085 131 *
AzureIoTClient 32:6e9d81a62085 132 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
AzureIoTClient 32:6e9d81a62085 133 */
AzureIoTClient 16:deba40344375 134 extern IOTHUB_CLIENT_RESULT IoTHubClient_SetMessageCallback(IOTHUB_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC messageCallback, void* userContextCallback);
AzureIoTClient 16:deba40344375 135
AzureIoTClient 32:6e9d81a62085 136 /**
AzureIoTClient 32:6e9d81a62085 137 * @brief This function returns in the out parameter @p lastMessageReceiveTime
AzureIoTClient 32:6e9d81a62085 138 * what was the value of the @c time function when the last message was
AzureIoTClient 32:6e9d81a62085 139 * received at the client.
AzureIoTClient 32:6e9d81a62085 140 *
AzureIoTClient 32:6e9d81a62085 141 * @param iotHubClientHandle The handle created by a call to the create function.
AzureIoTClient 32:6e9d81a62085 142 * @param lastMessageReceiveTime Out parameter containing the value of @c time function
AzureIoTClient 32:6e9d81a62085 143 * when the last message was received.
AzureIoTClient 32:6e9d81a62085 144 *
AzureIoTClient 32:6e9d81a62085 145 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
AzureIoTClient 32:6e9d81a62085 146 */
AzureIoTClient 16:deba40344375 147 extern IOTHUB_CLIENT_RESULT IoTHubClient_GetLastMessageReceiveTime(IOTHUB_CLIENT_HANDLE iotHubClientHandle, time_t* lastMessageReceiveTime);
AzureIoTClient 16:deba40344375 148
AzureIoTClient 32:6e9d81a62085 149 /**
AzureIoTClient 32:6e9d81a62085 150 * @brief This API sets a runtime option identified by parameter @p optionName
AzureIoTClient 32:6e9d81a62085 151 * to a value pointed to by @p value. @p optionName and the data type
AzureIoTClient 32:6e9d81a62085 152 * @p value is pointing to are specific for every option.
AzureIoTClient 32:6e9d81a62085 153 *
AzureIoTClient 32:6e9d81a62085 154 * @param iotHubClientHandle The handle created by a call to the create function.
AzureIoTClient 32:6e9d81a62085 155 * @param optionName Name of the option.
AzureIoTClient 32:6e9d81a62085 156 * @param value The value.
AzureIoTClient 32:6e9d81a62085 157 *
AzureIoTClient 32:6e9d81a62085 158 * The options that can be set via this API are:
AzureIoTClient 32:6e9d81a62085 159 * - @b timeout - the maximum time in milliseconds a communication is
AzureIoTClient 32:6e9d81a62085 160 * allowed to use. @p value is a pointer to an @c unsigned @c int with
AzureIoTClient 32:6e9d81a62085 161 * the timeout value in milliseconds. This is only supported for the HTTP
AzureIoTClient 32:6e9d81a62085 162 * protocol as of now. When the HTTP protocol uses CURL, the meaning of
AzureIoTClient 32:6e9d81a62085 163 * the parameter is <em>total request time</em>. When the HTTP protocol uses
AzureIoTClient 32:6e9d81a62085 164 * winhttp, the meaning is the same as the @c dwSendTimeout and
AzureIoTClient 32:6e9d81a62085 165 * @c dwReceiveTimeout parameters of the
AzureIoTClient 32:6e9d81a62085 166 * <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa384116(v=vs.85).aspx">
AzureIoTClient 32:6e9d81a62085 167 * WinHttpSetTimeouts</a> API.
AzureIoTClient 32:6e9d81a62085 168 * - @b CURLOPT_LOW_SPEED_LIMIT - only available for HTTP protocol and only
AzureIoTClient 32:6e9d81a62085 169 * when CURL is used. It has the same meaning as CURL's option with the same
AzureIoTClient 32:6e9d81a62085 170 * name. @p value is pointer to a long.
AzureIoTClient 32:6e9d81a62085 171 * - @b CURLOPT_LOW_SPEED_TIME - only available for HTTP protocol and only
AzureIoTClient 32:6e9d81a62085 172 * when CURL is used. It has the same meaning as CURL's option with the same
AzureIoTClient 32:6e9d81a62085 173 * name. @p value is pointer to a long.
AzureIoTClient 32:6e9d81a62085 174 * - @b CURLOPT_FORBID_REUSE - only available for HTTP protocol and only
AzureIoTClient 32:6e9d81a62085 175 * when CURL is used. It has the same meaning as CURL's option with the same
AzureIoTClient 32:6e9d81a62085 176 * name. @p value is pointer to a long.
AzureIoTClient 32:6e9d81a62085 177 * - @b CURLOPT_FRESH_CONNECT - only available for HTTP protocol and only
AzureIoTClient 32:6e9d81a62085 178 * when CURL is used. It has the same meaning as CURL's option with the same
AzureIoTClient 32:6e9d81a62085 179 * name. @p value is pointer to a long.
AzureIoTClient 32:6e9d81a62085 180 * - @b CURLOPT_VERBOSE - only available for HTTP protocol and only
AzureIoTClient 32:6e9d81a62085 181 * when CURL is used. It has the same meaning as CURL's option with the same
AzureIoTClient 32:6e9d81a62085 182 * name. @p value is pointer to a long.
Azure.IoT Build 36:67300d5a4c1f 183 * - @b messageTimeout - the maximum time in milliseconds until a message
Azure.IoT Build 36:67300d5a4c1f 184 * is timeouted. The time starts at IoTHubClient_SendEventAsync. By default,
Azure.IoT Build 36:67300d5a4c1f 185 * messages do not expire.
AzureIoTClient 32:6e9d81a62085 186 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
AzureIoTClient 32:6e9d81a62085 187 */
AzureIoTClient 16:deba40344375 188 extern IOTHUB_CLIENT_RESULT IoTHubClient_SetOption(IOTHUB_CLIENT_HANDLE iotHubClientHandle, const char* optionName, const void* value);
AzureIoTClient 16:deba40344375 189
AzureIoTClient 16:deba40344375 190 #ifdef __cplusplus
AzureIoTClient 16:deba40344375 191 }
AzureIoTClient 16:deba40344375 192 #endif
AzureIoTClient 16:deba40344375 193
AzureIoTClient 16:deba40344375 194 #endif /* IOTHUB_CLIENT_H */