Azure IoT middleware for FreeRTOS
|
The middleware IoT Hub Client used to connect a device to Azure IoT Hub. More...
#include "azure_iot.h"
#include "azure_iot_message.h"
#include "azure_iot_result.h"
#include "azure_iot_mqtt_port.h"
#include "azure_iot_transport_interface.h"
#include "azure/az_core.h"
#include "azure/iot/az_iot_common.h"
#include "azure/iot/az_iot_hub_client.h"
#include "azure/core/_az_cfg_prefix.h"
#include "azure/core/_az_cfg_suffix.h"
Go to the source code of this file.
Data Structures | |
struct | AzureIoTHubClientCloudToDeviceMessageRequest |
IoT Hub Cloud Message Request struct. More... | |
struct | AzureIoTHubClientCommandRequest |
IoT Hub Command Request struct. More... | |
struct | AzureIoTHubClientPropertiesResponse |
IoT Hub Properties Response struct. More... | |
struct | AzureIoTHubClientReceiveContext |
Receive context to be used internally for the processing of messages. More... | |
struct | AzureIoTHubClientOptions |
Options list for the hub client. More... | |
struct | AzureIoTHubClient |
Macros | |
#define | azureiothubSUBSCRIBE_FEATURE_COUNT ( 3 ) |
Total number of features which could be subscribed to. | |
#define | azureiothubCREATE_COMPONENT(x) ( AzureIoTHubClientComponent_t ) AZ_SPAN_LITERAL_FROM_STR( x ) |
Macro which should be used to create an array of AzureIoTHubClientComponent_t. | |
Typedefs | |
typedef struct AzureIoTHubClient | AzureIoTHubClient_t |
typedef az_span | AzureIoTHubClientComponent_t |
Type for Azure IoT Plug and Play component. The list of component names can be set as an option for the Azure IoT Hub Client. | |
typedef enum AzureIoTHubMessageQoS | AzureIoTHubMessageQoS_t |
MQTT quality of service values used for messages. | |
typedef enum AzureIoTHubMessageType | AzureIoTHubMessageType_t |
Enumeration to dictate Azure IoT message types. | |
typedef enum AzureIoTHubMessageStatus | AzureIoTHubMessageStatus_t |
Status codes for Azure IoT Hub responses. | |
typedef struct AzureIoTHubClientCloudToDeviceMessageRequest | AzureIoTHubClientCloudToDeviceMessageRequest_t |
IoT Hub Cloud Message Request struct. | |
typedef struct AzureIoTHubClientCommandRequest | AzureIoTHubClientCommandRequest_t |
IoT Hub Command Request struct. | |
typedef struct AzureIoTHubClientPropertiesResponse | AzureIoTHubClientPropertiesResponse_t |
IoT Hub Properties Response struct. | |
typedef void(* | AzureIoTHubClientCloudToDeviceMessageCallback_t) (AzureIoTHubClientCloudToDeviceMessageRequest_t *pxMessage, void *pvContext) |
Cloud message callback to be invoked when a cloud message is received in the call to AzureIoTHubClient_ProcessLoop(). More... | |
typedef void(* | AzureIoTHubClientCommandCallback_t) (AzureIoTHubClientCommandRequest_t *pxMessage, void *pvContext) |
Command callback to be invoked when a command request is received in the call to AzureIoTHubClient_ProcessLoop(). More... | |
typedef void(* | AzureIoTHubClientPropertiesCallback_t) (AzureIoTHubClientPropertiesResponse_t *pxMessage, void *pvContext) |
Properties callback to be invoked when a property message is received in the call to AzureIoTHubClient_ProcessLoop(). More... | |
typedef struct AzureIoTHubClientReceiveContext | AzureIoTHubClientReceiveContext_t |
Receive context to be used internally for the processing of messages. More... | |
typedef void(* | AzureIoTTelemetryAckCallback_t) (uint16_t ulTelemetryPacketID) |
Callback to send notification that puback was received for specific packet ID. More... | |
typedef struct AzureIoTHubClientOptions | AzureIoTHubClientOptions_t |
Options list for the hub client. | |
Enumerations | |
enum | AzureIoTHubMessageQoS { eAzureIoTHubMessageQoS0 = 0 , eAzureIoTHubMessageQoS1 = 1 } |
MQTT quality of service values used for messages. More... | |
enum | AzureIoTHubMessageType { eAzureIoTHubCloudToDeviceMessage = 1 , eAzureIoTHubCommandMessage , eAzureIoTHubPropertiesRequestedMessage , eAzureIoTHubPropertiesReportedResponseMessage , eAzureIoTHubPropertiesWritablePropertyMessage } |
Enumeration to dictate Azure IoT message types. More... | |
enum | AzureIoTHubMessageStatus { eAzureIoTStatusUnknown = 0 , eAzureIoTStatusOk = 200 , eAzureIoTStatusAccepted = 202 , eAzureIoTStatusNoContent = 204 , eAzureIoTStatusBadRequest = 400 , eAzureIoTStatusUnauthorized = 401 , eAzureIoTStatusForbidden = 403 , eAzureIoTStatusNotFound = 404 , eAzureIoTStatusNotAllowed = 405 , eAzureIoTStatusNotConflict = 409 , eAzureIoTStatusPreconditionFailed = 412 , eAzureIoTStatusRequestTooLarge = 413 , eAzureIoTStatusUnsupportedType = 415 , eAzureIoTStatusThrottled = 429 , eAzureIoTStatusClientClosed = 499 , eAzureIoTStatusServerError = 500 , eAzureIoTStatusBadGateway = 502 , eAzureIoTStatusServiceUnavailable = 503 , eAzureIoTStatusTimeout = 504 } |
Status codes for Azure IoT Hub responses. | |
Functions | |
AzureIoTResult_t | AzureIoTHubClient_OptionsInit (AzureIoTHubClientOptions_t *pxHubClientOptions) |
Initialize the Azure IoT Hub Options with default values. More... | |
AzureIoTResult_t | AzureIoTHubClient_Init (AzureIoTHubClient_t *pxAzureIoTHubClient, const uint8_t *pucHostname, uint16_t ulHostnameLength, const uint8_t *pucDeviceID, uint16_t ulDeviceIDLength, AzureIoTHubClientOptions_t *pxHubClientOptions, uint8_t *pucBuffer, uint32_t ulBufferLength, AzureIoTGetCurrentTimeFunc_t xGetTimeFunction, const AzureIoTTransportInterface_t *pxTransportInterface) |
Initialize the Azure IoT Hub Client. More... | |
void | AzureIoTHubClient_Deinit (AzureIoTHubClient_t *pxAzureIoTHubClient) |
Deinitialize the Azure IoT Hub Client. More... | |
AzureIoTResult_t | AzureIoTHubClient_SetSymmetricKey (AzureIoTHubClient_t *pxAzureIoTHubClient, const uint8_t *pucSymmetricKey, uint32_t ulSymmetricKeyLength, AzureIoTGetHMACFunc_t xHMACFunction) |
Set the symmetric key to use for authentication. More... | |
AzureIoTResult_t | AzureIoTHubClient_Connect (AzureIoTHubClient_t *pxAzureIoTHubClient, bool xCleanSession, bool *pxOutSessionPresent, uint32_t ulTimeoutMilliseconds) |
Connect via MQTT to the IoT Hub endpoint. More... | |
AzureIoTResult_t | AzureIoTHubClient_Disconnect (AzureIoTHubClient_t *pxAzureIoTHubClient) |
Disconnect from the IoT Hub endpoint. More... | |
AzureIoTResult_t | AzureIoTHubClient_SendTelemetry (AzureIoTHubClient_t *pxAzureIoTHubClient, const uint8_t *pucTelemetryData, uint32_t ulTelemetryDataLength, AzureIoTMessageProperties_t *pxProperties, AzureIoTHubMessageQoS_t xQOS, uint16_t *pusTelemetryPacketID) |
Send telemetry data to IoT Hub. More... | |
AzureIoTResult_t | AzureIoTHubClient_ProcessLoop (AzureIoTHubClient_t *pxAzureIoTHubClient, uint32_t ulTimeoutMilliseconds) |
Receive any incoming MQTT messages from and manage the MQTT connection to IoT Hub. More... | |
AzureIoTResult_t | AzureIoTHubClient_SubscribeCloudToDeviceMessage (AzureIoTHubClient_t *pxAzureIoTHubClient, AzureIoTHubClientCloudToDeviceMessageCallback_t xCloudToDeviceMessageCallback, void *prvCallbackContext, uint32_t ulTimeoutMilliseconds) |
Subscribe to cloud to device messages. More... | |
AzureIoTResult_t | AzureIoTHubClient_UnsubscribeCloudToDeviceMessage (AzureIoTHubClient_t *pxAzureIoTHubClient) |
Unsubscribe from cloud to device messages. More... | |
AzureIoTResult_t | AzureIoTHubClient_SubscribeCommand (AzureIoTHubClient_t *pxAzureIoTHubClient, AzureIoTHubClientCommandCallback_t xCommandCallback, void *prvCallbackContext, uint32_t ulTimeoutMilliseconds) |
Subscribe to commands. More... | |
AzureIoTResult_t | AzureIoTHubClient_UnsubscribeCommand (AzureIoTHubClient_t *pxAzureIoTHubClient) |
Unsubscribe from commands. More... | |
AzureIoTResult_t | AzureIoTHubClient_SendCommandResponse (AzureIoTHubClient_t *pxAzureIoTHubClient, const AzureIoTHubClientCommandRequest_t *pxMessage, uint32_t ulStatus, const uint8_t *pucCommandPayload, uint32_t ulCommandPayloadLength) |
Send a response to a received command message. More... | |
AzureIoTResult_t | AzureIoTHubClient_SubscribeProperties (AzureIoTHubClient_t *pxAzureIoTHubClient, AzureIoTHubClientPropertiesCallback_t xPropertiesCallback, void *prvCallbackContext, uint32_t ulTimeoutMilliseconds) |
Subscribe to device properties. More... | |
AzureIoTResult_t | AzureIoTHubClient_UnsubscribeProperties (AzureIoTHubClient_t *pxAzureIoTHubClient) |
Unsubscribe from device properties. More... | |
AzureIoTResult_t | AzureIoTHubClient_SendPropertiesReported (AzureIoTHubClient_t *pxAzureIoTHubClient, const uint8_t *pucReportedPayload, uint32_t ulReportedPayloadLength, uint32_t *pulRequestID) |
Send reported device properties to Azure IoT Hub. More... | |
AzureIoTResult_t | AzureIoTHubClient_RequestPropertiesAsync (AzureIoTHubClient_t *pxAzureIoTHubClient) |
Request to get the device property document. More... | |
The middleware IoT Hub Client used to connect a device to Azure IoT Hub.
typedef void( * AzureIoTHubClientCloudToDeviceMessageCallback_t) (AzureIoTHubClientCloudToDeviceMessageRequest_t *pxMessage, void *pvContext) |
Cloud message callback to be invoked when a cloud message is received in the call to AzureIoTHubClient_ProcessLoop().
[in] | pxMessage | The AzureIoTHubClientCloudToDeviceMessageRequest_t associated with the message. |
[in] | pvContext | The context passed back to the caller. |
typedef void( * AzureIoTHubClientCommandCallback_t) (AzureIoTHubClientCommandRequest_t *pxMessage, void *pvContext) |
Command callback to be invoked when a command request is received in the call to AzureIoTHubClient_ProcessLoop().
[in] | pxMessage | The AzureIoTHubClientCommandRequest_t associated with the message. |
[in] | pvContext | The context passed back to the caller. |
typedef void( * AzureIoTHubClientPropertiesCallback_t) (AzureIoTHubClientPropertiesResponse_t *pxMessage, void *pvContext) |
Properties callback to be invoked when a property message is received in the call to AzureIoTHubClient_ProcessLoop().
[in] | pxMessage | The AzureIoTHubClientPropertiesResponse_t associated with the message. |
[in] | pvContext | The context passed back to the caller. |
typedef struct AzureIoTHubClientReceiveContext AzureIoTHubClientReceiveContext_t |
Receive context to be used internally for the processing of messages.
typedef void(* AzureIoTTelemetryAckCallback_t) (uint16_t ulTelemetryPacketID) |
Callback to send notification that puback was received for specific packet ID.
[in] | ulTelemetryPacketID | The packet id for the telemetry message which was received. You may use this to match messages with the optional packet id parameter in AzureIoTHubClient_SendTelemetry(). |
Enumeration to dictate Azure IoT message types.
AzureIoTResult_t AzureIoTHubClient_Connect | ( | AzureIoTHubClient_t * | pxAzureIoTHubClient, |
bool | xCleanSession, | ||
bool * | pxOutSessionPresent, | ||
uint32_t | ulTimeoutMilliseconds | ||
) |
Connect via MQTT to the IoT Hub endpoint.
[in] | pxAzureIoTHubClient | The AzureIoTHubClient_t * to use for this call. |
[in] | xCleanSession | A boolean dictating whether to connect with a clean session or not. |
[in] | pxOutSessionPresent | Whether a previous session was present. Only relevant if not establishing a clean session. |
[in] | ulTimeoutMilliseconds | The maximum time in milliseconds to wait for a CONNACK. |
void AzureIoTHubClient_Deinit | ( | AzureIoTHubClient_t * | pxAzureIoTHubClient | ) |
Deinitialize the Azure IoT Hub Client.
pxAzureIoTHubClient | The AzureIoTHubClient_t * to use for this call. |
AzureIoTResult_t AzureIoTHubClient_Disconnect | ( | AzureIoTHubClient_t * | pxAzureIoTHubClient | ) |
Disconnect from the IoT Hub endpoint.
[in] | pxAzureIoTHubClient | The AzureIoTHubClient_t * to use for this call. |
AzureIoTResult_t AzureIoTHubClient_Init | ( | AzureIoTHubClient_t * | pxAzureIoTHubClient, |
const uint8_t * | pucHostname, | ||
uint16_t | ulHostnameLength, | ||
const uint8_t * | pucDeviceID, | ||
uint16_t | ulDeviceIDLength, | ||
AzureIoTHubClientOptions_t * | pxHubClientOptions, | ||
uint8_t * | pucBuffer, | ||
uint32_t | ulBufferLength, | ||
AzureIoTGetCurrentTimeFunc_t | xGetTimeFunction, | ||
const AzureIoTTransportInterface_t * | pxTransportInterface | ||
) |
Initialize the Azure IoT Hub Client.
[out] | pxAzureIoTHubClient | The AzureIoTHubClient_t * to use for this call. |
[in] | pucHostname | The IoT Hub Hostname. |
[in] | ulHostnameLength | The length of the IoT Hub Hostname. |
[in] | pucDeviceID | The device ID. If the ID contains any of the following characters, they must be percent-encoded as follows:
|
[in] | ulDeviceIDLength | The length of the device ID. |
[in] | pxHubClientOptions | The AzureIoTHubClientOptions_t for the IoT Hub client instance. |
[in] | pucBuffer | The static buffer to use for middleware operations and MQTT messages until AzureIoTHubClient_Deinit is called. |
[in] | ulBufferLength | The length of the pucBuffer . |
[in] | xGetTimeFunction | A function pointer to a function which gives the current epoch time. |
[in] | pxTransportInterface | The AzureIoTTransportInterface_t to use for the MQTT library. |
AzureIoTResult_t AzureIoTHubClient_OptionsInit | ( | AzureIoTHubClientOptions_t * | pxHubClientOptions | ) |
Initialize the Azure IoT Hub Options with default values.
[out] | pxHubClientOptions | The AzureIoTHubClientOptions_t instance to set with default values. |
AzureIoTResult_t AzureIoTHubClient_ProcessLoop | ( | AzureIoTHubClient_t * | pxAzureIoTHubClient, |
uint32_t | ulTimeoutMilliseconds | ||
) |
Receive any incoming MQTT messages from and manage the MQTT connection to IoT Hub.
PING
messages.[in] | pxAzureIoTHubClient | The AzureIoTHubClient_t * to use for this call. |
[in] | ulTimeoutMilliseconds | Minimum time (in milliseconds) for the loop to run. If 0 is passed, it will only run once. |
AzureIoTResult_t AzureIoTHubClient_RequestPropertiesAsync | ( | AzureIoTHubClient_t * | pxAzureIoTHubClient | ) |
Request to get the device property document.
The response to the request will be returned via the AzureIoTHubClientPropertiesCallback_t which was passed in the AzureIoTHubClient_SubscribeProperties() call. The type of message will be eAzureIoTHubPropertiesRequestedMessage and the payload (on success) will be the property document.
[in] | pxAzureIoTHubClient | The AzureIoTHubClient_t * to use for this call. |
AzureIoTResult_t AzureIoTHubClient_SendCommandResponse | ( | AzureIoTHubClient_t * | pxAzureIoTHubClient, |
const AzureIoTHubClientCommandRequest_t * | pxMessage, | ||
uint32_t | ulStatus, | ||
const uint8_t * | pucCommandPayload, | ||
uint32_t | ulCommandPayloadLength | ||
) |
Send a response to a received command message.
[in] | pxAzureIoTHubClient | The AzureIoTHubClient_t * to use for this call. |
[in] | pxMessage | The pointer to the AzureIoTHubClientCommandRequest_t to which a response is being sent. |
[in] | ulStatus | A code that indicates the result of the command, as defined by the user. |
[in] | pucCommandPayload | [nullable] An optional command response payload. |
[in] | ulCommandPayloadLength | The length of the command response payload. |
AzureIoTResult_t AzureIoTHubClient_SendPropertiesReported | ( | AzureIoTHubClient_t * | pxAzureIoTHubClient, |
const uint8_t * | pucReportedPayload, | ||
uint32_t | ulReportedPayloadLength, | ||
uint32_t * | pulRequestID | ||
) |
Send reported device properties to Azure IoT Hub.
[in] | pxAzureIoTHubClient | The AzureIoTHubClient_t * to use for this call. |
[in] | pucReportedPayload | The payload of properly formatted, reported properties. |
[in] | ulReportedPayloadLength | The length of the reported property payload. |
[out] | pulRequestID | Pointer to request ID used to send the reported property. |
AzureIoTResult_t AzureIoTHubClient_SendTelemetry | ( | AzureIoTHubClient_t * | pxAzureIoTHubClient, |
const uint8_t * | pucTelemetryData, | ||
uint32_t | ulTelemetryDataLength, | ||
AzureIoTMessageProperties_t * | pxProperties, | ||
AzureIoTHubMessageQoS_t | xQOS, | ||
uint16_t * | pusTelemetryPacketID | ||
) |
Send telemetry data to IoT Hub.
[in] | pxAzureIoTHubClient | The AzureIoTHubClient_t * to use for this call. |
[in] | pucTelemetryData | The pointer to the buffer of telemetry data. |
[in] | ulTelemetryDataLength | The length of the buffer to send as telemetry. |
[in] | pxProperties | The property bag to send with the message. |
[in] | xQOS | The QOS to use for the telemetry. Only QOS 0 and 1 are supported. |
[out] | pusTelemetryPacketID | The packet id for the sent telemetry. Can be notified of PUBACK for QOS 1 using the AzureIoTHubClientOptions_t xTelemetryCallback option. If xQOS is eAzureIoTHubMessageQoS0 this value will not be sent on return. Can be NULL . |
AzureIoTResult_t AzureIoTHubClient_SetSymmetricKey | ( | AzureIoTHubClient_t * | pxAzureIoTHubClient, |
const uint8_t * | pucSymmetricKey, | ||
uint32_t | ulSymmetricKeyLength, | ||
AzureIoTGetHMACFunc_t | xHMACFunction | ||
) |
Set the symmetric key to use for authentication.
[in] | pxAzureIoTHubClient | The AzureIoTHubClient_t * to use for this call. |
[in] | pucSymmetricKey | The symmetric key to use for the connection. |
[in] | ulSymmetricKeyLength | The length of the pucSymmetricKey . |
[in] | xHMACFunction | The AzureIoTGetHMACFunc_t function pointer to a function which computes the HMAC256 over a set of bytes. |
AzureIoTResult_t AzureIoTHubClient_SubscribeCloudToDeviceMessage | ( | AzureIoTHubClient_t * | pxAzureIoTHubClient, |
AzureIoTHubClientCloudToDeviceMessageCallback_t | xCloudToDeviceMessageCallback, | ||
void * | prvCallbackContext, | ||
uint32_t | ulTimeoutMilliseconds | ||
) |
Subscribe to cloud to device messages.
[in] | pxAzureIoTHubClient | The AzureIoTHubClient_t * to use for this call. |
[in] | xCloudToDeviceMessageCallback | The AzureIoTHubClientCloudToDeviceMessageCallback_t to invoke when a CloudToDevice messages arrive. |
[in] | prvCallbackContext | A pointer to a context to pass to the callback. |
[in] | ulTimeoutMilliseconds | Timeout in milliseconds for subscribe operation to complete. |
AzureIoTResult_t AzureIoTHubClient_SubscribeCommand | ( | AzureIoTHubClient_t * | pxAzureIoTHubClient, |
AzureIoTHubClientCommandCallback_t | xCommandCallback, | ||
void * | prvCallbackContext, | ||
uint32_t | ulTimeoutMilliseconds | ||
) |
Subscribe to commands.
[in] | pxAzureIoTHubClient | The AzureIoTHubClient_t * to use for this call. |
[in] | xCommandCallback | The AzureIoTHubClientCommandCallback_t to invoke when command messages arrive. |
[in] | prvCallbackContext | A pointer to a context to pass to the callback. |
[in] | ulTimeoutMilliseconds | Timeout in milliseconds for Subscribe operation to complete. |
AzureIoTResult_t AzureIoTHubClient_SubscribeProperties | ( | AzureIoTHubClient_t * | pxAzureIoTHubClient, |
AzureIoTHubClientPropertiesCallback_t | xPropertiesCallback, | ||
void * | prvCallbackContext, | ||
uint32_t | ulTimeoutMilliseconds | ||
) |
Subscribe to device properties.
[in] | pxAzureIoTHubClient | The AzureIoTHubClient_t * to use for this call. |
[in] | xPropertiesCallback | The AzureIoTHubClientPropertiesCallback_t to invoke when device property messages arrive. |
[in] | prvCallbackContext | A pointer to a context to pass to the callback. |
[in] | ulTimeoutMilliseconds | Timeout in milliseconds for Subscribe operation to complete. |
AzureIoTResult_t AzureIoTHubClient_UnsubscribeCloudToDeviceMessage | ( | AzureIoTHubClient_t * | pxAzureIoTHubClient | ) |
Unsubscribe from cloud to device messages.
[in] | pxAzureIoTHubClient | The AzureIoTHubClient_t * to use for this call. |
AzureIoTResult_t AzureIoTHubClient_UnsubscribeCommand | ( | AzureIoTHubClient_t * | pxAzureIoTHubClient | ) |
Unsubscribe from commands.
[in] | pxAzureIoTHubClient | The AzureIoTHubClient_t * to use for this call. |
AzureIoTResult_t AzureIoTHubClient_UnsubscribeProperties | ( | AzureIoTHubClient_t * | pxAzureIoTHubClient | ) |
Unsubscribe from device properties.
[in] | pxAzureIoTHubClient | The AzureIoTHubClient_t * to use for this call. |