Azure IoT middleware for FreeRTOS
azure_iot_hub_client.h
Go to the documentation of this file.
1 /* Copyright (c) Microsoft Corporation.
2  * Licensed under the MIT License. */
3 
16 #ifndef AZURE_IOT_HUB_CLIENT_H
17 #define AZURE_IOT_HUB_CLIENT_H
18 
19 #include "azure_iot.h"
20 #include "azure_iot_message.h"
21 #include "azure_iot_result.h"
22 
23 #include "azure_iot_mqtt_port.h"
25 
26 /* Azure SDK for Embedded C includes */
27 #include "azure/az_core.h"
28 #include "azure/iot/az_iot_common.h"
29 #include "azure/iot/az_iot_hub_client.h"
30 #include "azure/core/_az_cfg_prefix.h"
31 
35 #define azureiothubSUBSCRIBE_FEATURE_COUNT ( 3 )
36 
40 #define azureiothubCREATE_COMPONENT( x ) ( AzureIoTHubClientComponent_t ) AZ_SPAN_LITERAL_FROM_STR( x )
41 
42 /* Forward declaration for Azure IoT Hub Client */
44 
50 
55 {
56  eAzureIoTHubMessageQoS0 = 0,
59 
64 {
71 
76 {
77  /* Default, unset value */
78  eAzureIoTStatusUnknown = 0,
79 
80  /* Service success codes */
81  eAzureIoTStatusOk = 200,
82  eAzureIoTStatusAccepted = 202,
83  eAzureIoTStatusNoContent = 204,
84 
85  /* Service error codes */
86  eAzureIoTStatusBadRequest = 400,
87  eAzureIoTStatusUnauthorized = 401,
88  eAzureIoTStatusForbidden = 403,
89  eAzureIoTStatusNotFound = 404,
90  eAzureIoTStatusNotAllowed = 405,
91  eAzureIoTStatusNotConflict = 409,
92  eAzureIoTStatusPreconditionFailed = 412,
93  eAzureIoTStatusRequestTooLarge = 413,
94  eAzureIoTStatusUnsupportedType = 415,
95  eAzureIoTStatusThrottled = 429,
96  eAzureIoTStatusClientClosed = 499,
97  eAzureIoTStatusServerError = 500,
98  eAzureIoTStatusBadGateway = 502,
99  eAzureIoTStatusServiceUnavailable = 503,
100  eAzureIoTStatusTimeout = 504,
102 
107 {
108  const void * pvMessagePayload;
109  uint32_t ulPayloadLength;
113 
118 {
119  const void * pvMessagePayload;
120  uint32_t ulPayloadLength;
122  const uint8_t * pucRequestID;
123  uint16_t usRequestIDLength;
125  const uint8_t * pucComponentName;
128  const uint8_t * pucCommandName;
131 
136 {
139  const void * pvMessagePayload;
140  uint32_t ulPayloadLength;
142  uint32_t ulRequestID;
146 
154  void * pvContext );
155 
164  void * pvContext );
165 
173  void * pvContext );
174 
181 {
182  struct
183  {
184  uint16_t usState;
185  uint16_t usMqttSubPacketID;
186  uint32_t ( * pxProcessFunction )( struct AzureIoTHubClientReceiveContext * pxContext,
187  AzureIoTHubClient_t * pxAzureIoTHubClient,
188  void * pvPublishInfo );
189 
190  void * pvCallbackContext;
191  union
192  {
193  AzureIoTHubClientCloudToDeviceMessageCallback_t xCloudToDeviceMessageCallback;
194  AzureIoTHubClientCommandCallback_t xCommandCallback;
195  AzureIoTHubClientPropertiesCallback_t xPropertiesCallback;
196  } callbacks;
199 
206 typedef void (* AzureIoTTelemetryAckCallback_t)( uint16_t ulTelemetryPacketID );
207 
212 {
213  const uint8_t * pucModuleID;
214  uint32_t ulModuleIDLength;
216  const uint8_t * pucModelID;
218  uint32_t ulModelIDLength;
223  const uint8_t * pucUserAgent;
224  uint32_t ulUserAgentLength;
229 
235 {
236  struct
237  {
238  AzureIoTMQTT_t xMQTTContext;
239 
240  uint8_t * pucWorkingBuffer;
241  uint32_t ulWorkingBufferLength;
242  az_iot_hub_client xAzureIoTHubClientCore;
243 
244  const uint8_t * pucHostname;
245  uint16_t ulHostnameLength;
246  const uint8_t * pucDeviceID;
247  uint16_t ulDeviceIDLength;
248  const uint8_t * pucSymmetricKey;
249  uint32_t ulSymmetricKeyLength;
250 
251  uint32_t ( * pxTokenRefresh )( AzureIoTHubClient_t * pxAzureIoTHubClient,
252  uint64_t ullExpiryTimeSecs,
253  const uint8_t * ucKey,
254  uint32_t ulKeyLen,
255  uint8_t * pucSASBuffer,
256  uint32_t ulSasBufferLen,
257  uint32_t * pulSaSLength );
258  AzureIoTGetHMACFunc_t xHMACFunction;
259  AzureIoTGetCurrentTimeFunc_t xTimeFunction;
260  AzureIoTTelemetryAckCallback_t xTelemetryCallback;
261 
262  uint32_t ulCurrentPropertyRequestID;
263 
265  }
267 };
268 
276 
298  const uint8_t * pucHostname,
299  uint16_t ulHostnameLength,
300  const uint8_t * pucDeviceID,
301  uint16_t ulDeviceIDLength,
302  AzureIoTHubClientOptions_t * pxHubClientOptions,
303  uint8_t * pucBuffer,
304  uint32_t ulBufferLength,
305  AzureIoTGetCurrentTimeFunc_t xGetTimeFunction,
306  const AzureIoTTransportInterface_t * pxTransportInterface );
307 
313 void AzureIoTHubClient_Deinit( AzureIoTHubClient_t * pxAzureIoTHubClient );
314 
327  const uint8_t * pucSymmetricKey,
328  uint32_t ulSymmetricKeyLength,
329  AzureIoTGetHMACFunc_t xHMACFunction );
330 
342  bool xCleanSession,
343  bool * pxOutSessionPresent,
344  uint32_t ulTimeoutMilliseconds );
345 
353 
369  const uint8_t * pucTelemetryData,
370  uint32_t ulTelemetryDataLength,
371  AzureIoTMessageProperties_t * pxProperties,
373  uint16_t * pusTelemetryPacketID );
374 
386  uint32_t ulTimeoutMilliseconds );
387 
398  AzureIoTHubClientCloudToDeviceMessageCallback_t xCloudToDeviceMessageCallback,
399  void * prvCallbackContext,
400  uint32_t ulTimeoutMilliseconds );
401 
409 
420  AzureIoTHubClientCommandCallback_t xCommandCallback,
421  void * prvCallbackContext,
422  uint32_t ulTimeoutMilliseconds );
423 
431 
443  const AzureIoTHubClientCommandRequest_t * pxMessage,
444  uint32_t ulStatus,
445  const uint8_t * pucCommandPayload,
446  uint32_t ulCommandPayloadLength );
447 
458  AzureIoTHubClientPropertiesCallback_t xPropertiesCallback,
459  void * prvCallbackContext,
460  uint32_t ulTimeoutMilliseconds );
461 
469 
482  const uint8_t * pucReportedPayload,
483  uint32_t ulReportedPayloadLength,
484  uint32_t * pulRequestID );
485 
499 
500 #include "azure/core/_az_cfg_suffix.h"
501 
502 #endif /* AZURE_IOT_HUB_CLIENT_H */
Azure IoT FreeRTOS middleware common APIs and structs.
uint32_t(* AzureIoTGetHMACFunc_t)(const uint8_t *pucKey, uint32_t ulKeyLength, const uint8_t *pucData, uint32_t ulDataLength, uint8_t *pucOutput, uint32_t ulOutputLength, uint32_t *pulBytesCopied)
The HMAC256 function used by the SDK to generate SAS keys.
Definition: azure_iot.h:62
uint64_t(* AzureIoTGetCurrentTimeFunc_t)(void)
The platform get time function to be used by the SDK for MQTT connections.
Definition: azure_iot.h:48
void(* AzureIoTHubClientCommandCallback_t)(AzureIoTHubClientCommandRequest_t *pxMessage, void *pvContext)
Command callback to be invoked when a command request is received in the call to AzureIoTHubClient_Pr...
Definition: azure_iot_hub_client.h:163
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.
struct AzureIoTHubClientCloudToDeviceMessageRequest AzureIoTHubClientCloudToDeviceMessageRequest_t
IoT Hub Cloud Message Request struct.
enum AzureIoTHubMessageStatus AzureIoTHubMessageStatus_t
Status codes for Azure IoT Hub responses.
az_span AzureIoTHubClientComponent_t
Type for Azure IoT Plug and Play component. The list of component names can be set as an option for t...
Definition: azure_iot_hub_client.h:49
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.
void(* AzureIoTHubClientCloudToDeviceMessageCallback_t)(AzureIoTHubClientCloudToDeviceMessageRequest_t *pxMessage, void *pvContext)
Cloud message callback to be invoked when a cloud message is received in the call to AzureIoTHubClien...
Definition: azure_iot_hub_client.h:153
AzureIoTResult_t AzureIoTHubClient_UnsubscribeProperties(AzureIoTHubClient_t *pxAzureIoTHubClient)
Unsubscribe from device properties.
AzureIoTResult_t AzureIoTHubClient_SubscribeProperties(AzureIoTHubClient_t *pxAzureIoTHubClient, AzureIoTHubClientPropertiesCallback_t xPropertiesCallback, void *prvCallbackContext, uint32_t ulTimeoutMilliseconds)
Subscribe to device properties.
void(* AzureIoTHubClientPropertiesCallback_t)(AzureIoTHubClientPropertiesResponse_t *pxMessage, void *pvContext)
Properties callback to be invoked when a property message is received in the call to AzureIoTHubClien...
Definition: azure_iot_hub_client.h:172
void AzureIoTHubClient_Deinit(AzureIoTHubClient_t *pxAzureIoTHubClient)
Deinitialize the Azure IoT Hub Client.
AzureIoTResult_t AzureIoTHubClient_Connect(AzureIoTHubClient_t *pxAzureIoTHubClient, bool xCleanSession, bool *pxOutSessionPresent, uint32_t ulTimeoutMilliseconds)
Connect via MQTT to the IoT Hub endpoint.
AzureIoTResult_t AzureIoTHubClient_OptionsInit(AzureIoTHubClientOptions_t *pxHubClientOptions)
Initialize the Azure IoT Hub Options with default values.
AzureIoTResult_t AzureIoTHubClient_UnsubscribeCommand(AzureIoTHubClient_t *pxAzureIoTHubClient)
Unsubscribe from commands.
AzureIoTResult_t AzureIoTHubClient_ProcessLoop(AzureIoTHubClient_t *pxAzureIoTHubClient, uint32_t ulTimeoutMilliseconds)
Receive any incoming MQTT messages from and manage the MQTT connection to IoT Hub.
AzureIoTHubMessageType
Enumeration to dictate Azure IoT message types.
Definition: azure_iot_hub_client.h:64
@ eAzureIoTHubPropertiesWritablePropertyMessage
Definition: azure_iot_hub_client.h:69
@ eAzureIoTHubCommandMessage
Definition: azure_iot_hub_client.h:66
@ eAzureIoTHubCloudToDeviceMessage
Definition: azure_iot_hub_client.h:65
@ eAzureIoTHubPropertiesReportedResponseMessage
Definition: azure_iot_hub_client.h:68
@ eAzureIoTHubPropertiesRequestedMessage
Definition: azure_iot_hub_client.h:67
AzureIoTResult_t AzureIoTHubClient_Disconnect(AzureIoTHubClient_t *pxAzureIoTHubClient)
Disconnect from the IoT Hub endpoint.
struct AzureIoTHubClientReceiveContext AzureIoTHubClientReceiveContext_t
Receive context to be used internally for the processing of messages.
struct AzureIoTHubClientOptions AzureIoTHubClientOptions_t
Options list for the hub client.
AzureIoTResult_t AzureIoTHubClient_SubscribeCommand(AzureIoTHubClient_t *pxAzureIoTHubClient, AzureIoTHubClientCommandCallback_t xCommandCallback, void *prvCallbackContext, uint32_t ulTimeoutMilliseconds)
Subscribe to commands.
enum AzureIoTHubMessageQoS AzureIoTHubMessageQoS_t
MQTT quality of service values used for messages.
AzureIoTResult_t AzureIoTHubClient_SubscribeCloudToDeviceMessage(AzureIoTHubClient_t *pxAzureIoTHubClient, AzureIoTHubClientCloudToDeviceMessageCallback_t xCloudToDeviceMessageCallback, void *prvCallbackContext, uint32_t ulTimeoutMilliseconds)
Subscribe to cloud to device messages.
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.
AzureIoTResult_t AzureIoTHubClient_UnsubscribeCloudToDeviceMessage(AzureIoTHubClient_t *pxAzureIoTHubClient)
Unsubscribe from cloud to device messages.
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.
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.
struct AzureIoTHubClientCommandRequest AzureIoTHubClientCommandRequest_t
IoT Hub Command Request struct.
enum AzureIoTHubMessageType AzureIoTHubMessageType_t
Enumeration to dictate Azure IoT message types.
AzureIoTHubMessageQoS
MQTT quality of service values used for messages.
Definition: azure_iot_hub_client.h:55
@ eAzureIoTHubMessageQoS1
Definition: azure_iot_hub_client.h:57
struct AzureIoTHubClientPropertiesResponse AzureIoTHubClientPropertiesResponse_t
IoT Hub Properties Response struct.
AzureIoTResult_t AzureIoTHubClient_RequestPropertiesAsync(AzureIoTHubClient_t *pxAzureIoTHubClient)
Request to get the device property document.
void(* AzureIoTTelemetryAckCallback_t)(uint16_t ulTelemetryPacketID)
Callback to send notification that puback was received for specific packet ID.
Definition: azure_iot_hub_client.h:206
AzureIoTHubMessageStatus
Status codes for Azure IoT Hub responses.
Definition: azure_iot_hub_client.h:76
#define azureiothubSUBSCRIBE_FEATURE_COUNT
Total number of features which could be subscribed to.
Definition: azure_iot_hub_client.h:35
Azure IoT FreeRTOS middleware message APIs and structs.
Azure IoT FreeRTOS middleware result values.
enum AzureIoTResult AzureIoTResult_t
The results used by the middleware.
Transport interface definition to send and receive data over the network.
Azure IoT Hub Client used to manage connections and features for Azure IoT Hub.
IoT Hub Cloud Message Request struct.
Definition: azure_iot_hub_client.h:107
uint32_t ulPayloadLength
Definition: azure_iot_hub_client.h:109
AzureIoTMessageProperties_t xProperties
Definition: azure_iot_hub_client.h:111
const void * pvMessagePayload
Definition: azure_iot_hub_client.h:108
IoT Hub Command Request struct.
Definition: azure_iot_hub_client.h:118
uint16_t usCommandNameLength
Definition: azure_iot_hub_client.h:129
uint16_t usComponentNameLength
Definition: azure_iot_hub_client.h:126
const void * pvMessagePayload
Definition: azure_iot_hub_client.h:119
uint16_t usRequestIDLength
Definition: azure_iot_hub_client.h:123
const uint8_t * pucComponentName
Definition: azure_iot_hub_client.h:125
const uint8_t * pucRequestID
Definition: azure_iot_hub_client.h:122
uint32_t ulPayloadLength
Definition: azure_iot_hub_client.h:120
const uint8_t * pucCommandName
Definition: azure_iot_hub_client.h:128
Definition: azure_iot_hub_client.h:235
struct AzureIoTHubClient::@4 _internal
Internal to the SDK.
Options list for the hub client.
Definition: azure_iot_hub_client.h:212
uint32_t ulUserAgentLength
Definition: azure_iot_hub_client.h:224
AzureIoTTelemetryAckCallback_t xTelemetryCallback
Definition: azure_iot_hub_client.h:226
const uint8_t * pucModuleID
Definition: azure_iot_hub_client.h:213
const uint8_t * pucModelID
Definition: azure_iot_hub_client.h:216
uint32_t ulModelIDLength
Definition: azure_iot_hub_client.h:218
uint32_t ulModuleIDLength
Definition: azure_iot_hub_client.h:214
AzureIoTHubClientComponent_t * pxComponentList
Definition: azure_iot_hub_client.h:220
uint32_t ulComponentListLength
Definition: azure_iot_hub_client.h:221
const uint8_t * pucUserAgent
Definition: azure_iot_hub_client.h:223
IoT Hub Properties Response struct.
Definition: azure_iot_hub_client.h:136
uint32_t ulRequestID
Definition: azure_iot_hub_client.h:142
uint32_t ulPayloadLength
Definition: azure_iot_hub_client.h:140
AzureIoTHubMessageStatus_t xMessageStatus
Definition: azure_iot_hub_client.h:144
const void * pvMessagePayload
Definition: azure_iot_hub_client.h:139
AzureIoTHubMessageType_t xMessageType
Definition: azure_iot_hub_client.h:137
Receive context to be used internally for the processing of messages.
Definition: azure_iot_hub_client.h:181
struct AzureIoTHubClientReceiveContext::@2 _internal
Internal to the SDK.
The bag of properties associated with a message.
Definition: azure_iot_message.h:31
The transport layer interface.
Definition: azure_iot_transport_interface.h:159